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