xref: /openbmc/linux/include/drm/drm_device.h (revision 0c874100)
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  * DRM device structure. This structure represent a complete card that
29  * may contain multiple heads.
30  */
31 struct drm_device {
32 	struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
33 	int if_version;			/**< Highest interface version set */
34 
35 	/** \name Lifetime Management */
36 	/*@{ */
37 	struct kref ref;		/**< Object ref-count */
38 	struct device *dev;		/**< Device structure of bus-device */
39 	struct drm_driver *driver;	/**< DRM driver managing the device */
40 	void *dev_private;		/**< DRM driver private data */
41 	struct drm_minor *primary;		/**< Primary node */
42 	struct drm_minor *render;		/**< Render node */
43 	bool registered;
44 
45 	/* currently active master for this device. Protected by master_mutex */
46 	struct drm_master *master;
47 
48 	/**
49 	 * @driver_features: per-device driver features
50 	 *
51 	 * Drivers can clear specific flags here to disallow
52 	 * certain features on a per-device basis while still
53 	 * sharing a single &struct drm_driver instance across
54 	 * all devices.
55 	 */
56 	u32 driver_features;
57 
58 	/**
59 	 * @unplugged:
60 	 *
61 	 * Flag to tell if the device has been unplugged.
62 	 * See drm_dev_enter() and drm_dev_is_unplugged().
63 	 */
64 	bool unplugged;
65 
66 	struct inode *anon_inode;		/**< inode for private address-space */
67 	char *unique;				/**< unique name of the device */
68 	/*@} */
69 
70 	/** \name Locks */
71 	/*@{ */
72 	struct mutex struct_mutex;	/**< For others */
73 	struct mutex master_mutex;      /**< For drm_minor::master and drm_file::is_master */
74 	/*@} */
75 
76 	/** \name Usage Counters */
77 	/*@{ */
78 	int open_count;			/**< Outstanding files open, protected by drm_global_mutex. */
79 	spinlock_t buf_lock;		/**< For drm_device::buf_use and a few other things. */
80 	int buf_use;			/**< Buffers in use -- cannot alloc */
81 	atomic_t buf_alloc;		/**< Buffer allocation in progress */
82 	/*@} */
83 
84 	struct mutex filelist_mutex;
85 	struct list_head filelist;
86 
87 	/**
88 	 * @filelist_internal:
89 	 *
90 	 * List of open DRM files for in-kernel clients. Protected by @filelist_mutex.
91 	 */
92 	struct list_head filelist_internal;
93 
94 	/**
95 	 * @clientlist_mutex:
96 	 *
97 	 * Protects @clientlist access.
98 	 */
99 	struct mutex clientlist_mutex;
100 
101 	/**
102 	 * @clientlist:
103 	 *
104 	 * List of in-kernel clients. Protected by @clientlist_mutex.
105 	 */
106 	struct list_head clientlist;
107 
108 	/** \name Memory management */
109 	/*@{ */
110 	struct list_head maplist;	/**< Linked list of regions */
111 	struct drm_open_hash map_hash;	/**< User token hash table for maps */
112 
113 	/** \name Context handle management */
114 	/*@{ */
115 	struct list_head ctxlist;	/**< Linked list of context handles */
116 	struct mutex ctxlist_mutex;	/**< For ctxlist */
117 
118 	struct idr ctx_idr;
119 
120 	struct list_head vmalist;	/**< List of vmas (for debugging) */
121 
122 	/*@} */
123 
124 	/** \name DMA support */
125 	/*@{ */
126 	struct drm_device_dma *dma;		/**< Optional pointer for DMA support */
127 	/*@} */
128 
129 	/** \name Context support */
130 	/*@{ */
131 
132 	__volatile__ long context_flag;	/**< Context swapping flag */
133 	int last_context;		/**< Last current context */
134 	/*@} */
135 
136 	/**
137 	 * @irq_enabled:
138 	 *
139 	 * Indicates that interrupt handling is enabled, specifically vblank
140 	 * handling. Drivers which don't use drm_irq_install() need to set this
141 	 * to true manually.
142 	 */
143 	bool irq_enabled;
144 	int irq;
145 
146 	/**
147 	 * @vblank_disable_immediate:
148 	 *
149 	 * If true, vblank interrupt will be disabled immediately when the
150 	 * refcount drops to zero, as opposed to via the vblank disable
151 	 * timer.
152 	 *
153 	 * This can be set to true it the hardware has a working vblank counter
154 	 * with high-precision timestamping (otherwise there are races) and the
155 	 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
156 	 * appropriately. See also @max_vblank_count and
157 	 * &drm_crtc_funcs.get_vblank_counter.
158 	 */
159 	bool vblank_disable_immediate;
160 
161 	/**
162 	 * @vblank:
163 	 *
164 	 * Array of vblank tracking structures, one per &struct drm_crtc. For
165 	 * historical reasons (vblank support predates kernel modesetting) this
166 	 * is free-standing and not part of &struct drm_crtc itself. It must be
167 	 * initialized explicitly by calling drm_vblank_init().
168 	 */
169 	struct drm_vblank_crtc *vblank;
170 
171 	spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
172 	spinlock_t vbl_lock;
173 
174 	/**
175 	 * @max_vblank_count:
176 	 *
177 	 * Maximum value of the vblank registers. This value +1 will result in a
178 	 * wrap-around of the vblank register. It is used by the vblank core to
179 	 * handle wrap-arounds.
180 	 *
181 	 * If set to zero the vblank core will try to guess the elapsed vblanks
182 	 * between times when the vblank interrupt is disabled through
183 	 * high-precision timestamps. That approach is suffering from small
184 	 * races and imprecision over longer time periods, hence exposing a
185 	 * hardware vblank counter is always recommended.
186 	 *
187 	 * If non-zeor, &drm_crtc_funcs.get_vblank_counter must be set.
188 	 */
189 	u32 max_vblank_count;           /**< size of vblank counter register */
190 
191 	/**
192 	 * List of events
193 	 */
194 	struct list_head vblank_event_list;
195 	spinlock_t event_lock;
196 
197 	/*@} */
198 
199 	struct drm_agp_head *agp;	/**< AGP data */
200 
201 	struct pci_dev *pdev;		/**< PCI device structure */
202 #ifdef __alpha__
203 	struct pci_controller *hose;
204 #endif
205 
206 	struct drm_sg_mem *sg;	/**< Scatter gather memory */
207 	unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
208 
209 	struct {
210 		int context;
211 		struct drm_hw_lock *lock;
212 	} sigdata;
213 
214 	struct drm_local_map *agp_buffer_map;
215 	unsigned int agp_buffer_token;
216 
217 	struct drm_mode_config mode_config;	/**< Current mode config */
218 
219 	/** \name GEM information */
220 	/*@{ */
221 	struct mutex object_name_lock;
222 	struct idr object_name_idr;
223 	struct drm_vma_offset_manager *vma_offset_manager;
224 	/*@} */
225 	int switch_power_state;
226 
227 	/**
228 	 * @fb_helper:
229 	 *
230 	 * Pointer to the fbdev emulation structure.
231 	 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
232 	 */
233 	struct drm_fb_helper *fb_helper;
234 };
235 
236 #endif
237