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