xref: /linux/include/drm/drm_device.h (revision de848da12f752170c2ebe114804a985314fd5a6a)
1e4672e55SDaniel Vetter #ifndef _DRM_DEVICE_H_
2e4672e55SDaniel Vetter #define _DRM_DEVICE_H_
3e4672e55SDaniel Vetter 
4e4672e55SDaniel Vetter #include <linux/list.h>
5e4672e55SDaniel Vetter #include <linux/kref.h>
6e4672e55SDaniel Vetter #include <linux/mutex.h>
7e4672e55SDaniel Vetter #include <linux/idr.h>
8e4672e55SDaniel Vetter 
9e4672e55SDaniel Vetter #include <drm/drm_mode_config.h>
10e4672e55SDaniel Vetter 
11e4672e55SDaniel Vetter struct drm_driver;
12e4672e55SDaniel Vetter struct drm_minor;
13e4672e55SDaniel Vetter struct drm_master;
14e4672e55SDaniel Vetter struct drm_vblank_crtc;
15e4672e55SDaniel Vetter struct drm_vma_offset_manager;
1659f5989aSThomas Zimmermann struct drm_vram_mm;
1729ad20b2SNoralf Trønnes struct drm_fb_helper;
18e4672e55SDaniel Vetter 
19e4672e55SDaniel Vetter struct inode;
20e4672e55SDaniel Vetter 
21e4672e55SDaniel Vetter struct pci_dev;
22e4672e55SDaniel Vetter struct pci_controller;
23e4672e55SDaniel Vetter 
247af78f40SSam Ravnborg 
257af78f40SSam Ravnborg /**
26e9d2871fSMauro Carvalho Chehab  * enum switch_power_state - power state of drm device
277af78f40SSam Ravnborg  */
287af78f40SSam Ravnborg 
297af78f40SSam Ravnborg enum switch_power_state {
307af78f40SSam Ravnborg 	/** @DRM_SWITCH_POWER_ON: Power state is ON */
317af78f40SSam Ravnborg 	DRM_SWITCH_POWER_ON = 0,
327af78f40SSam Ravnborg 
337af78f40SSam Ravnborg 	/** @DRM_SWITCH_POWER_OFF: Power state is OFF */
347af78f40SSam Ravnborg 	DRM_SWITCH_POWER_OFF = 1,
357af78f40SSam Ravnborg 
367af78f40SSam Ravnborg 	/** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
377af78f40SSam Ravnborg 	DRM_SWITCH_POWER_CHANGING = 2,
387af78f40SSam Ravnborg 
397af78f40SSam Ravnborg 	/** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
407af78f40SSam Ravnborg 	DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
417af78f40SSam Ravnborg };
427af78f40SSam Ravnborg 
43e4672e55SDaniel Vetter /**
44ac4f24c2SSam Ravnborg  * struct drm_device - DRM device structure
45ac4f24c2SSam Ravnborg  *
46ac4f24c2SSam Ravnborg  * This structure represent a complete card that
47e4672e55SDaniel Vetter  * may contain multiple heads.
48e4672e55SDaniel Vetter  */
49e4672e55SDaniel Vetter struct drm_device {
50ac4f24c2SSam Ravnborg 	/** @if_version: Highest interface version set */
51ac4f24c2SSam Ravnborg 	int if_version;
52ac4f24c2SSam Ravnborg 
53ac4f24c2SSam Ravnborg 	/** @ref: Object ref-count */
54ac4f24c2SSam Ravnborg 	struct kref ref;
55ac4f24c2SSam Ravnborg 
56ac4f24c2SSam Ravnborg 	/** @dev: Device structure of bus-device */
57ac4f24c2SSam Ravnborg 	struct device *dev;
58ac4f24c2SSam Ravnborg 
59c6603c74SDaniel Vetter 	/**
60c6603c74SDaniel Vetter 	 * @managed:
61c6603c74SDaniel Vetter 	 *
62c6603c74SDaniel Vetter 	 * Managed resources linked to the lifetime of this &drm_device as
63c6603c74SDaniel Vetter 	 * tracked by @ref.
64c6603c74SDaniel Vetter 	 */
65c6603c74SDaniel Vetter 	struct {
66c6603c74SDaniel Vetter 		/** @managed.resources: managed resources list */
67c6603c74SDaniel Vetter 		struct list_head resources;
68c6603c74SDaniel Vetter 		/** @managed.final_kfree: pointer for final kfree() call */
69c6603c74SDaniel Vetter 		void *final_kfree;
70c6603c74SDaniel Vetter 		/** @managed.lock: protects @managed.resources */
71c6603c74SDaniel Vetter 		spinlock_t lock;
72c6603c74SDaniel Vetter 	} managed;
73c6603c74SDaniel Vetter 
74ac4f24c2SSam Ravnborg 	/** @driver: DRM driver managing the device */
758f5c7aa0SDaniel Vetter 	const struct drm_driver *driver;
76ac4f24c2SSam Ravnborg 
773214a166SDaniel Vetter 	/**
783214a166SDaniel Vetter 	 * @dev_private:
793214a166SDaniel Vetter 	 *
8074aae1c4SDaniel Vetter 	 * DRM driver private data. This is deprecated and should be left set to
8174aae1c4SDaniel Vetter 	 * NULL.
8274aae1c4SDaniel Vetter 	 *
8374aae1c4SDaniel Vetter 	 * Instead of using this pointer it is recommended that drivers use
844c8e84b8SDaniel Vetter 	 * devm_drm_dev_alloc() and embed struct &drm_device in their larger
8574aae1c4SDaniel Vetter 	 * per-device structure.
863214a166SDaniel Vetter 	 */
87ac4f24c2SSam Ravnborg 	void *dev_private;
88ac4f24c2SSam Ravnborg 
8999845faaSDaniel Vetter 	/**
9099845faaSDaniel Vetter 	 * @primary:
9199845faaSDaniel Vetter 	 *
9299845faaSDaniel Vetter 	 * Primary node. Drivers should not interact with this
9399845faaSDaniel Vetter 	 * directly. debugfs interfaces can be registered with
9499845faaSDaniel Vetter 	 * drm_debugfs_add_file(), and sysfs should be directly added on the
9599845faaSDaniel Vetter 	 * hardware (and not character device node) struct device @dev.
9699845faaSDaniel Vetter 	 */
97ac4f24c2SSam Ravnborg 	struct drm_minor *primary;
98ac4f24c2SSam Ravnborg 
9999845faaSDaniel Vetter 	/**
10099845faaSDaniel Vetter 	 * @render:
10199845faaSDaniel Vetter 	 *
10299845faaSDaniel Vetter 	 * Render node. Drivers should not interact with this directly ever.
10399845faaSDaniel Vetter 	 * Drivers should not expose any additional interfaces in debugfs or
10499845faaSDaniel Vetter 	 * sysfs on this node.
10599845faaSDaniel Vetter 	 */
106ac4f24c2SSam Ravnborg 	struct drm_minor *render;
107ac4f24c2SSam Ravnborg 
1082c204f3dSOded Gabbay 	/** @accel: Compute Acceleration node */
1092c204f3dSOded Gabbay 	struct drm_minor *accel;
1102c204f3dSOded Gabbay 
1113214a166SDaniel Vetter 	/**
1123214a166SDaniel Vetter 	 * @registered:
1133214a166SDaniel Vetter 	 *
1143214a166SDaniel Vetter 	 * Internally used by drm_dev_register() and drm_connector_register().
1153214a166SDaniel Vetter 	 */
116e4672e55SDaniel Vetter 	bool registered;
117e4672e55SDaniel Vetter 
118ac4f24c2SSam Ravnborg 	/**
119ac4f24c2SSam Ravnborg 	 * @master:
120ac4f24c2SSam Ravnborg 	 *
121ac4f24c2SSam Ravnborg 	 * Currently active master for this device.
122ac4f24c2SSam Ravnborg 	 * Protected by &master_mutex
123ac4f24c2SSam Ravnborg 	 */
124e4672e55SDaniel Vetter 	struct drm_master *master;
125e4672e55SDaniel Vetter 
126bee330f3SNoralf Trønnes 	/**
12718ace11fSVille Syrjälä 	 * @driver_features: per-device driver features
12818ace11fSVille Syrjälä 	 *
12918ace11fSVille Syrjälä 	 * Drivers can clear specific flags here to disallow
13018ace11fSVille Syrjälä 	 * certain features on a per-device basis while still
13118ace11fSVille Syrjälä 	 * sharing a single &struct drm_driver instance across
13218ace11fSVille Syrjälä 	 * all devices.
13318ace11fSVille Syrjälä 	 */
13418ace11fSVille Syrjälä 	u32 driver_features;
13518ace11fSVille Syrjälä 
13618ace11fSVille Syrjälä 	/**
137bee330f3SNoralf Trønnes 	 * @unplugged:
138bee330f3SNoralf Trønnes 	 *
139bee330f3SNoralf Trønnes 	 * Flag to tell if the device has been unplugged.
140bee330f3SNoralf Trønnes 	 * See drm_dev_enter() and drm_dev_is_unplugged().
141bee330f3SNoralf Trønnes 	 */
142bee330f3SNoralf Trønnes 	bool unplugged;
143bee330f3SNoralf Trønnes 
144ac4f24c2SSam Ravnborg 	/** @anon_inode: inode for private address-space */
145ac4f24c2SSam Ravnborg 	struct inode *anon_inode;
146e4672e55SDaniel Vetter 
147ac4f24c2SSam Ravnborg 	/** @unique: Unique name of the device */
148ac4f24c2SSam Ravnborg 	char *unique;
149e4672e55SDaniel Vetter 
150ac4f24c2SSam Ravnborg 	/**
151ac4f24c2SSam Ravnborg 	 * @struct_mutex:
152ac4f24c2SSam Ravnborg 	 *
153ac4f24c2SSam Ravnborg 	 * Lock for others (not &drm_minor.master and &drm_file.is_master)
154e33f4234SEmil Velikov 	 *
1552504c7ecSThomas Zimmermann 	 * TODO: This lock used to be the BKL of the DRM subsystem. Move the
1562504c7ecSThomas Zimmermann 	 *       lock into i915, which is the only remaining user.
157ac4f24c2SSam Ravnborg 	 */
158ac4f24c2SSam Ravnborg 	struct mutex struct_mutex;
159ac4f24c2SSam Ravnborg 
160ac4f24c2SSam Ravnborg 	/**
161ac4f24c2SSam Ravnborg 	 * @master_mutex:
162ac4f24c2SSam Ravnborg 	 *
163ac4f24c2SSam Ravnborg 	 * Lock for &drm_minor.master and &drm_file.is_master
164ac4f24c2SSam Ravnborg 	 */
165ac4f24c2SSam Ravnborg 	struct mutex master_mutex;
166ac4f24c2SSam Ravnborg 
167ac4f24c2SSam Ravnborg 	/**
168ac4f24c2SSam Ravnborg 	 * @open_count:
169ac4f24c2SSam Ravnborg 	 *
170ac4f24c2SSam Ravnborg 	 * Usage counter for outstanding files open,
171ac4f24c2SSam Ravnborg 	 * protected by drm_global_mutex
172ac4f24c2SSam Ravnborg 	 */
1737e13ad89SChris Wilson 	atomic_t open_count;
174ac4f24c2SSam Ravnborg 
1753214a166SDaniel Vetter 	/** @filelist_mutex: Protects @filelist. */
176e4672e55SDaniel Vetter 	struct mutex filelist_mutex;
1773214a166SDaniel Vetter 	/**
1783214a166SDaniel Vetter 	 * @filelist:
1793214a166SDaniel Vetter 	 *
1803214a166SDaniel Vetter 	 * List of userspace clients, linked through &drm_file.lhead.
1813214a166SDaniel Vetter 	 */
182e4672e55SDaniel Vetter 	struct list_head filelist;
183e4672e55SDaniel Vetter 
184c76f0f7cSNoralf Trønnes 	/**
185c76f0f7cSNoralf Trønnes 	 * @filelist_internal:
186c76f0f7cSNoralf Trønnes 	 *
187ac4f24c2SSam Ravnborg 	 * List of open DRM files for in-kernel clients.
188ac4f24c2SSam Ravnborg 	 * Protected by &filelist_mutex.
189c76f0f7cSNoralf Trønnes 	 */
190c76f0f7cSNoralf Trønnes 	struct list_head filelist_internal;
191c76f0f7cSNoralf Trønnes 
192c76f0f7cSNoralf Trønnes 	/**
193c76f0f7cSNoralf Trønnes 	 * @clientlist_mutex:
194c76f0f7cSNoralf Trønnes 	 *
195ac4f24c2SSam Ravnborg 	 * Protects &clientlist access.
196c76f0f7cSNoralf Trønnes 	 */
197c76f0f7cSNoralf Trønnes 	struct mutex clientlist_mutex;
198c76f0f7cSNoralf Trønnes 
199c76f0f7cSNoralf Trønnes 	/**
200c76f0f7cSNoralf Trønnes 	 * @clientlist:
201c76f0f7cSNoralf Trønnes 	 *
202ac4f24c2SSam Ravnborg 	 * List of in-kernel clients. Protected by &clientlist_mutex.
203c76f0f7cSNoralf Trønnes 	 */
204c76f0f7cSNoralf Trønnes 	struct list_head clientlist;
205c76f0f7cSNoralf Trønnes 
206e4672e55SDaniel Vetter 	/**
207e4672e55SDaniel Vetter 	 * @vblank_disable_immediate:
208e4672e55SDaniel Vetter 	 *
209e4672e55SDaniel Vetter 	 * If true, vblank interrupt will be disabled immediately when the
210e4672e55SDaniel Vetter 	 * refcount drops to zero, as opposed to via the vblank disable
211e4672e55SDaniel Vetter 	 * timer.
212e4672e55SDaniel Vetter 	 *
213e4672e55SDaniel Vetter 	 * This can be set to true it the hardware has a working vblank counter
214e4672e55SDaniel Vetter 	 * with high-precision timestamping (otherwise there are races) and the
215e4672e55SDaniel Vetter 	 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
216*0d5040e4SHamza Mahfooz 	 * appropriately. Also, see @max_vblank_count,
217*0d5040e4SHamza Mahfooz 	 * &drm_crtc_funcs.get_vblank_counter and
218*0d5040e4SHamza Mahfooz 	 * &drm_vblank_crtc_config.disable_immediate.
219e4672e55SDaniel Vetter 	 */
220e4672e55SDaniel Vetter 	bool vblank_disable_immediate;
221e4672e55SDaniel Vetter 
222e4672e55SDaniel Vetter 	/**
223e4672e55SDaniel Vetter 	 * @vblank:
224e4672e55SDaniel Vetter 	 *
225e4672e55SDaniel Vetter 	 * Array of vblank tracking structures, one per &struct drm_crtc. For
226e4672e55SDaniel Vetter 	 * historical reasons (vblank support predates kernel modesetting) this
227e4672e55SDaniel Vetter 	 * is free-standing and not part of &struct drm_crtc itself. It must be
228e4672e55SDaniel Vetter 	 * initialized explicitly by calling drm_vblank_init().
229e4672e55SDaniel Vetter 	 */
230e4672e55SDaniel Vetter 	struct drm_vblank_crtc *vblank;
231e4672e55SDaniel Vetter 
232ac4f24c2SSam Ravnborg 	/**
233ac4f24c2SSam Ravnborg 	 * @vblank_time_lock:
234ac4f24c2SSam Ravnborg 	 *
235ac4f24c2SSam Ravnborg 	 *  Protects vblank count and time updates during vblank enable/disable
236ac4f24c2SSam Ravnborg 	 */
237ac4f24c2SSam Ravnborg 	spinlock_t vblank_time_lock;
2383214a166SDaniel Vetter 	/**
2393214a166SDaniel Vetter 	 * @vbl_lock: Top-level vblank references lock, wraps the low-level
2403214a166SDaniel Vetter 	 * @vblank_time_lock.
2413214a166SDaniel Vetter 	 */
242e4672e55SDaniel Vetter 	spinlock_t vbl_lock;
243e4672e55SDaniel Vetter 
244e4672e55SDaniel Vetter 	/**
245e4672e55SDaniel Vetter 	 * @max_vblank_count:
246e4672e55SDaniel Vetter 	 *
247e4672e55SDaniel Vetter 	 * Maximum value of the vblank registers. This value +1 will result in a
248e4672e55SDaniel Vetter 	 * wrap-around of the vblank register. It is used by the vblank core to
249e4672e55SDaniel Vetter 	 * handle wrap-arounds.
250e4672e55SDaniel Vetter 	 *
251e4672e55SDaniel Vetter 	 * If set to zero the vblank core will try to guess the elapsed vblanks
252e4672e55SDaniel Vetter 	 * between times when the vblank interrupt is disabled through
253e4672e55SDaniel Vetter 	 * high-precision timestamps. That approach is suffering from small
254e4672e55SDaniel Vetter 	 * races and imprecision over longer time periods, hence exposing a
255e4672e55SDaniel Vetter 	 * hardware vblank counter is always recommended.
256e4672e55SDaniel Vetter 	 *
257ed20151aSVille Syrjälä 	 * This is the statically configured device wide maximum. The driver
258ed20151aSVille Syrjälä 	 * can instead choose to use a runtime configurable per-crtc value
259ed20151aSVille Syrjälä 	 * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
260ed20151aSVille Syrjälä 	 * must be left at zero. See drm_crtc_set_max_vblank_count() on how
261ed20151aSVille Syrjälä 	 * to use the per-crtc value.
262ed20151aSVille Syrjälä 	 *
2633214a166SDaniel Vetter 	 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
264e4672e55SDaniel Vetter 	 */
265ac4f24c2SSam Ravnborg 	u32 max_vblank_count;
266ac4f24c2SSam Ravnborg 
267ac4f24c2SSam Ravnborg 	/** @vblank_event_list: List of vblank events */
268e4672e55SDaniel Vetter 	struct list_head vblank_event_list;
2693214a166SDaniel Vetter 
2703214a166SDaniel Vetter 	/**
2713214a166SDaniel Vetter 	 * @event_lock:
2723214a166SDaniel Vetter 	 *
2733214a166SDaniel Vetter 	 * Protects @vblank_event_list and event delivery in
2743214a166SDaniel Vetter 	 * general. See drm_send_event() and drm_send_event_locked().
2753214a166SDaniel Vetter 	 */
276e4672e55SDaniel Vetter 	spinlock_t event_lock;
277e4672e55SDaniel Vetter 
278ac4f24c2SSam Ravnborg 	/** @num_crtcs: Number of CRTCs on this device */
279ac4f24c2SSam Ravnborg 	unsigned int num_crtcs;
280e4672e55SDaniel Vetter 
281ac4f24c2SSam Ravnborg 	/** @mode_config: Current mode config */
282ac4f24c2SSam Ravnborg 	struct drm_mode_config mode_config;
283e4672e55SDaniel Vetter 
284ac4f24c2SSam Ravnborg 	/** @object_name_lock: GEM information */
285e4672e55SDaniel Vetter 	struct mutex object_name_lock;
286ac4f24c2SSam Ravnborg 
287ac4f24c2SSam Ravnborg 	/** @object_name_idr: GEM information */
288e4672e55SDaniel Vetter 	struct idr object_name_idr;
289ac4f24c2SSam Ravnborg 
290ac4f24c2SSam Ravnborg 	/** @vma_offset_manager: GEM information */
291e4672e55SDaniel Vetter 	struct drm_vma_offset_manager *vma_offset_manager;
292ac4f24c2SSam Ravnborg 
29359f5989aSThomas Zimmermann 	/** @vram_mm: VRAM MM memory manager */
29459f5989aSThomas Zimmermann 	struct drm_vram_mm *vram_mm;
29559f5989aSThomas Zimmermann 
2967af78f40SSam Ravnborg 	/**
2977af78f40SSam Ravnborg 	 * @switch_power_state:
2987af78f40SSam Ravnborg 	 *
2997af78f40SSam Ravnborg 	 * Power state of the client.
3007af78f40SSam Ravnborg 	 * Used by drivers supporting the switcheroo driver.
3017af78f40SSam Ravnborg 	 * The state is maintained in the
3027af78f40SSam Ravnborg 	 * &vga_switcheroo_client_ops.set_gpu_state callback
3037af78f40SSam Ravnborg 	 */
3047af78f40SSam Ravnborg 	enum switch_power_state switch_power_state;
30529ad20b2SNoralf Trønnes 
30629ad20b2SNoralf Trønnes 	/**
30729ad20b2SNoralf Trønnes 	 * @fb_helper:
30829ad20b2SNoralf Trønnes 	 *
30929ad20b2SNoralf Trønnes 	 * Pointer to the fbdev emulation structure.
31029ad20b2SNoralf Trønnes 	 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
31129ad20b2SNoralf Trønnes 	 */
31229ad20b2SNoralf Trønnes 	struct drm_fb_helper *fb_helper;
3133214a166SDaniel Vetter 
3141c9cacbeSMaíra Canal 	/**
3150b30d57aSChristian König 	 * @debugfs_root:
3160b30d57aSChristian König 	 *
3170b30d57aSChristian König 	 * Root directory for debugfs files.
3180b30d57aSChristian König 	 */
3190b30d57aSChristian König 	struct dentry *debugfs_root;
320e4672e55SDaniel Vetter };
321e4672e55SDaniel Vetter 
322e4672e55SDaniel Vetter #endif
323