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