Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 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; |
Thomas Zimmermann | 59f5989 | 2019-05-08 10:26:18 +0200 | [diff] [blame] | 20 | struct drm_vram_mm; |
Noralf Trønnes | 29ad20b22 | 2017-10-30 16:39:38 +0100 | [diff] [blame] | 21 | struct drm_fb_helper; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 22 | |
| 23 | struct inode; |
| 24 | |
| 25 | struct pci_dev; |
| 26 | struct pci_controller; |
| 27 | |
Sam Ravnborg | 7af78f4 | 2019-01-08 20:29:29 +0100 | [diff] [blame] | 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 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 47 | /** |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 48 | * struct drm_device - DRM device structure |
| 49 | * |
| 50 | * This structure represent a complete card that |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 51 | * may contain multiple heads. |
| 52 | */ |
| 53 | struct drm_device { |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 54 | /** |
| 55 | * @legacy_dev_list: |
| 56 | * |
| 57 | * List of devices per driver for stealth attach cleanup |
| 58 | */ |
| 59 | struct list_head legacy_dev_list; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 60 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 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 | /** @driver: DRM driver managing the device */ |
| 71 | struct drm_driver *driver; |
| 72 | |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 73 | /** |
| 74 | * @dev_private: |
| 75 | * |
| 76 | * DRM driver private data. Instead of using this pointer it is |
| 77 | * recommended that drivers use drm_dev_init() and embed struct |
| 78 | * &drm_device in their larger per-device structure. |
| 79 | */ |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 80 | void *dev_private; |
| 81 | |
| 82 | /** @primary: Primary node */ |
| 83 | struct drm_minor *primary; |
| 84 | |
| 85 | /** @render: Render node */ |
| 86 | struct drm_minor *render; |
| 87 | |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 88 | /** |
| 89 | * @registered: |
| 90 | * |
| 91 | * Internally used by drm_dev_register() and drm_connector_register(). |
| 92 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 93 | bool registered; |
| 94 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 95 | /** |
| 96 | * @master: |
| 97 | * |
| 98 | * Currently active master for this device. |
| 99 | * Protected by &master_mutex |
| 100 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 101 | struct drm_master *master; |
| 102 | |
Noralf Trønnes | bee330f | 2018-03-28 10:38:35 +0300 | [diff] [blame] | 103 | /** |
Ville Syrjälä | 18ace11 | 2018-09-13 16:16:21 +0300 | [diff] [blame] | 104 | * @driver_features: per-device driver features |
| 105 | * |
| 106 | * Drivers can clear specific flags here to disallow |
| 107 | * certain features on a per-device basis while still |
| 108 | * sharing a single &struct drm_driver instance across |
| 109 | * all devices. |
| 110 | */ |
| 111 | u32 driver_features; |
| 112 | |
| 113 | /** |
Noralf Trønnes | bee330f | 2018-03-28 10:38:35 +0300 | [diff] [blame] | 114 | * @unplugged: |
| 115 | * |
| 116 | * Flag to tell if the device has been unplugged. |
| 117 | * See drm_dev_enter() and drm_dev_is_unplugged(). |
| 118 | */ |
| 119 | bool unplugged; |
| 120 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 121 | /** @anon_inode: inode for private address-space */ |
| 122 | struct inode *anon_inode; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 123 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 124 | /** @unique: Unique name of the device */ |
| 125 | char *unique; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 126 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 127 | /** |
| 128 | * @struct_mutex: |
| 129 | * |
| 130 | * Lock for others (not &drm_minor.master and &drm_file.is_master) |
| 131 | */ |
| 132 | struct mutex struct_mutex; |
| 133 | |
| 134 | /** |
| 135 | * @master_mutex: |
| 136 | * |
| 137 | * Lock for &drm_minor.master and &drm_file.is_master |
| 138 | */ |
| 139 | struct mutex master_mutex; |
| 140 | |
| 141 | /** |
| 142 | * @open_count: |
| 143 | * |
| 144 | * Usage counter for outstanding files open, |
| 145 | * protected by drm_global_mutex |
| 146 | */ |
| 147 | int open_count; |
| 148 | |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 149 | /** @filelist_mutex: Protects @filelist. */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 150 | struct mutex filelist_mutex; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 151 | /** |
| 152 | * @filelist: |
| 153 | * |
| 154 | * List of userspace clients, linked through &drm_file.lhead. |
| 155 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 156 | struct list_head filelist; |
| 157 | |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 158 | /** |
| 159 | * @filelist_internal: |
| 160 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 161 | * List of open DRM files for in-kernel clients. |
| 162 | * Protected by &filelist_mutex. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 163 | */ |
| 164 | struct list_head filelist_internal; |
| 165 | |
| 166 | /** |
| 167 | * @clientlist_mutex: |
| 168 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 169 | * Protects &clientlist access. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 170 | */ |
| 171 | struct mutex clientlist_mutex; |
| 172 | |
| 173 | /** |
| 174 | * @clientlist: |
| 175 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 176 | * List of in-kernel clients. Protected by &clientlist_mutex. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 177 | */ |
| 178 | struct list_head clientlist; |
| 179 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 180 | /** |
| 181 | * @irq_enabled: |
| 182 | * |
| 183 | * Indicates that interrupt handling is enabled, specifically vblank |
| 184 | * handling. Drivers which don't use drm_irq_install() need to set this |
| 185 | * to true manually. |
| 186 | */ |
| 187 | bool irq_enabled; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * @irq: Used by the drm_irq_install() and drm_irq_unistall() helpers. |
| 191 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 192 | int irq; |
| 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 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 219 | /** |
| 220 | * @vblank_time_lock: |
| 221 | * |
| 222 | * Protects vblank count and time updates during vblank enable/disable |
| 223 | */ |
| 224 | spinlock_t vblank_time_lock; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 225 | /** |
| 226 | * @vbl_lock: Top-level vblank references lock, wraps the low-level |
| 227 | * @vblank_time_lock. |
| 228 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 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 | * |
Ville Syrjälä | ed20151 | 2018-11-27 20:20:04 +0200 | [diff] [blame] | 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 | * |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 250 | * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set. |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 251 | */ |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 252 | u32 max_vblank_count; |
| 253 | |
| 254 | /** @vblank_event_list: List of vblank events */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 255 | struct list_head vblank_event_list; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 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 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 263 | spinlock_t event_lock; |
| 264 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 265 | /** @agp: AGP data */ |
| 266 | struct drm_agp_head *agp; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 267 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 268 | /** @pdev: PCI device structure */ |
| 269 | struct pci_dev *pdev; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 270 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 271 | #ifdef __alpha__ |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 272 | /** @hose: PCI hose, only used on ALPHA platforms. */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 273 | struct pci_controller *hose; |
| 274 | #endif |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 275 | /** @num_crtcs: Number of CRTCs on this device */ |
| 276 | unsigned int num_crtcs; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 277 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 278 | /** @mode_config: Current mode config */ |
| 279 | struct drm_mode_config mode_config; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 280 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 281 | /** @object_name_lock: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 282 | struct mutex object_name_lock; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 283 | |
| 284 | /** @object_name_idr: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 285 | struct idr object_name_idr; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 286 | |
| 287 | /** @vma_offset_manager: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 288 | struct drm_vma_offset_manager *vma_offset_manager; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 289 | |
Thomas Zimmermann | 59f5989 | 2019-05-08 10:26:18 +0200 | [diff] [blame] | 290 | /** @vram_mm: VRAM MM memory manager */ |
| 291 | struct drm_vram_mm *vram_mm; |
| 292 | |
Sam Ravnborg | 7af78f4 | 2019-01-08 20:29:29 +0100 | [diff] [blame] | 293 | /** |
| 294 | * @switch_power_state: |
| 295 | * |
| 296 | * Power state of the client. |
| 297 | * Used by drivers supporting the switcheroo driver. |
| 298 | * The state is maintained in the |
| 299 | * &vga_switcheroo_client_ops.set_gpu_state callback |
| 300 | */ |
| 301 | enum switch_power_state switch_power_state; |
Noralf Trønnes | 29ad20b22 | 2017-10-30 16:39:38 +0100 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * @fb_helper: |
| 305 | * |
| 306 | * Pointer to the fbdev emulation structure. |
| 307 | * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini(). |
| 308 | */ |
| 309 | struct drm_fb_helper *fb_helper; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 310 | |
| 311 | /* Everything below here is for legacy driver, never use! */ |
| 312 | /* private: */ |
Dave Airlie | 83c163f | 2019-04-23 09:56:01 +1000 | [diff] [blame] | 313 | #if IS_ENABLED(CONFIG_DRM_LEGACY) |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 314 | /* Context handle management - linked list of context handles */ |
| 315 | struct list_head ctxlist; |
| 316 | |
| 317 | /* Context handle management - mutex for &ctxlist */ |
| 318 | struct mutex ctxlist_mutex; |
| 319 | |
| 320 | /* Context handle management */ |
| 321 | struct idr ctx_idr; |
| 322 | |
| 323 | /* Memory management - linked list of regions */ |
| 324 | struct list_head maplist; |
| 325 | |
| 326 | /* Memory management - user token hash table for maps */ |
| 327 | struct drm_open_hash map_hash; |
| 328 | |
| 329 | /* Context handle management - list of vmas (for debugging) */ |
| 330 | struct list_head vmalist; |
| 331 | |
| 332 | /* Optional pointer for DMA support */ |
| 333 | struct drm_device_dma *dma; |
| 334 | |
| 335 | /* Context swapping flag */ |
| 336 | __volatile__ long context_flag; |
| 337 | |
| 338 | /* Last current context */ |
| 339 | int last_context; |
| 340 | |
| 341 | /* Lock for &buf_use and a few other things. */ |
| 342 | spinlock_t buf_lock; |
| 343 | |
| 344 | /* Usage counter for buffers in use -- cannot alloc */ |
| 345 | int buf_use; |
| 346 | |
| 347 | /* Buffer allocation in progress */ |
| 348 | atomic_t buf_alloc; |
| 349 | |
| 350 | struct { |
| 351 | int context; |
| 352 | struct drm_hw_lock *lock; |
| 353 | } sigdata; |
| 354 | |
| 355 | struct drm_local_map *agp_buffer_map; |
| 356 | unsigned int agp_buffer_token; |
| 357 | |
| 358 | /* Scatter gather memory */ |
| 359 | struct drm_sg_mem *sg; |
Dave Airlie | 83c163f | 2019-04-23 09:56:01 +1000 | [diff] [blame] | 360 | #endif |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | #endif |