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; |
Noralf Trønnes | 29ad20b22 | 2017-10-30 16:39:38 +0100 | [diff] [blame] | 20 | struct drm_fb_helper; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 21 | |
| 22 | struct inode; |
| 23 | |
| 24 | struct pci_dev; |
| 25 | struct pci_controller; |
| 26 | |
Sam Ravnborg | 7af78f4 | 2019-01-08 20:29:29 +0100 | [diff] [blame^] | 27 | |
| 28 | /** |
| 29 | * enum drm_switch_power - power state of drm device |
| 30 | */ |
| 31 | |
| 32 | enum switch_power_state { |
| 33 | /** @DRM_SWITCH_POWER_ON: Power state is ON */ |
| 34 | DRM_SWITCH_POWER_ON = 0, |
| 35 | |
| 36 | /** @DRM_SWITCH_POWER_OFF: Power state is OFF */ |
| 37 | DRM_SWITCH_POWER_OFF = 1, |
| 38 | |
| 39 | /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */ |
| 40 | DRM_SWITCH_POWER_CHANGING = 2, |
| 41 | |
| 42 | /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */ |
| 43 | DRM_SWITCH_POWER_DYNAMIC_OFF = 3, |
| 44 | }; |
| 45 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 46 | /** |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 47 | * struct drm_device - DRM device structure |
| 48 | * |
| 49 | * This structure represent a complete card that |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 50 | * may contain multiple heads. |
| 51 | */ |
| 52 | struct drm_device { |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 53 | /** |
| 54 | * @legacy_dev_list: |
| 55 | * |
| 56 | * List of devices per driver for stealth attach cleanup |
| 57 | */ |
| 58 | struct list_head legacy_dev_list; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 59 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 60 | /** @if_version: Highest interface version set */ |
| 61 | int if_version; |
| 62 | |
| 63 | /** @ref: Object ref-count */ |
| 64 | struct kref ref; |
| 65 | |
| 66 | /** @dev: Device structure of bus-device */ |
| 67 | struct device *dev; |
| 68 | |
| 69 | /** @driver: DRM driver managing the device */ |
| 70 | struct drm_driver *driver; |
| 71 | |
| 72 | /** @dev_private: DRM driver private data */ |
| 73 | void *dev_private; |
| 74 | |
| 75 | /** @primary: Primary node */ |
| 76 | struct drm_minor *primary; |
| 77 | |
| 78 | /** @render: Render node */ |
| 79 | struct drm_minor *render; |
| 80 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 81 | bool registered; |
| 82 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 83 | /** |
| 84 | * @master: |
| 85 | * |
| 86 | * Currently active master for this device. |
| 87 | * Protected by &master_mutex |
| 88 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 89 | struct drm_master *master; |
| 90 | |
Noralf Trønnes | bee330f | 2018-03-28 10:38:35 +0300 | [diff] [blame] | 91 | /** |
Ville Syrjälä | 18ace11 | 2018-09-13 16:16:21 +0300 | [diff] [blame] | 92 | * @driver_features: per-device driver features |
| 93 | * |
| 94 | * Drivers can clear specific flags here to disallow |
| 95 | * certain features on a per-device basis while still |
| 96 | * sharing a single &struct drm_driver instance across |
| 97 | * all devices. |
| 98 | */ |
| 99 | u32 driver_features; |
| 100 | |
| 101 | /** |
Noralf Trønnes | bee330f | 2018-03-28 10:38:35 +0300 | [diff] [blame] | 102 | * @unplugged: |
| 103 | * |
| 104 | * Flag to tell if the device has been unplugged. |
| 105 | * See drm_dev_enter() and drm_dev_is_unplugged(). |
| 106 | */ |
| 107 | bool unplugged; |
| 108 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 109 | /** @anon_inode: inode for private address-space */ |
| 110 | struct inode *anon_inode; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 111 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 112 | /** @unique: Unique name of the device */ |
| 113 | char *unique; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 114 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 115 | /** |
| 116 | * @struct_mutex: |
| 117 | * |
| 118 | * Lock for others (not &drm_minor.master and &drm_file.is_master) |
| 119 | */ |
| 120 | struct mutex struct_mutex; |
| 121 | |
| 122 | /** |
| 123 | * @master_mutex: |
| 124 | * |
| 125 | * Lock for &drm_minor.master and &drm_file.is_master |
| 126 | */ |
| 127 | struct mutex master_mutex; |
| 128 | |
| 129 | /** |
| 130 | * @open_count: |
| 131 | * |
| 132 | * Usage counter for outstanding files open, |
| 133 | * protected by drm_global_mutex |
| 134 | */ |
| 135 | int open_count; |
| 136 | |
| 137 | /** @buf_lock: Lock for &buf_use and a few other things. */ |
| 138 | spinlock_t buf_lock; |
| 139 | |
| 140 | /** @buf_use: Usage counter for buffers in use -- cannot alloc */ |
| 141 | int buf_use; |
| 142 | |
| 143 | /** @buf_alloc: Buffer allocation in progress */ |
| 144 | atomic_t buf_alloc; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 145 | |
| 146 | struct mutex filelist_mutex; |
| 147 | struct list_head filelist; |
| 148 | |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 149 | /** |
| 150 | * @filelist_internal: |
| 151 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 152 | * List of open DRM files for in-kernel clients. |
| 153 | * Protected by &filelist_mutex. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 154 | */ |
| 155 | struct list_head filelist_internal; |
| 156 | |
| 157 | /** |
| 158 | * @clientlist_mutex: |
| 159 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 160 | * Protects &clientlist access. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 161 | */ |
| 162 | struct mutex clientlist_mutex; |
| 163 | |
| 164 | /** |
| 165 | * @clientlist: |
| 166 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 167 | * List of in-kernel clients. Protected by &clientlist_mutex. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 168 | */ |
| 169 | struct list_head clientlist; |
| 170 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 171 | /** @maplist: Memory management - linked list of regions */ |
| 172 | struct list_head maplist; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 173 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 174 | /** @map_hash: Memory management - user token hash table for maps */ |
| 175 | struct drm_open_hash map_hash; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 176 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 177 | /** |
| 178 | * @ctxlist: |
| 179 | * Context handle management - linked list of context handles |
| 180 | */ |
| 181 | struct list_head ctxlist; |
| 182 | |
| 183 | /** |
| 184 | * @ctxlist_mutex: |
| 185 | * |
| 186 | * Context handle management - mutex for &ctxlist |
| 187 | */ |
| 188 | struct mutex ctxlist_mutex; |
| 189 | |
| 190 | /** |
| 191 | * @ctx_idr: |
| 192 | * Context handle management |
| 193 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 194 | struct idr ctx_idr; |
| 195 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 196 | /** |
| 197 | * @vmalist: |
| 198 | * Context handle management - list of vmas (for debugging) |
| 199 | */ |
| 200 | struct list_head vmalist; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 201 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 202 | /** @dma: Optional pointer for DMA support */ |
| 203 | struct drm_device_dma *dma; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 204 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 205 | /** @context_flag: Context swapping flag */ |
| 206 | __volatile__ long context_flag; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 207 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 208 | /** @last_context: Last current context */ |
| 209 | int last_context; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * @irq_enabled: |
| 213 | * |
| 214 | * Indicates that interrupt handling is enabled, specifically vblank |
| 215 | * handling. Drivers which don't use drm_irq_install() need to set this |
| 216 | * to true manually. |
| 217 | */ |
| 218 | bool irq_enabled; |
| 219 | int irq; |
| 220 | |
| 221 | /** |
| 222 | * @vblank_disable_immediate: |
| 223 | * |
| 224 | * If true, vblank interrupt will be disabled immediately when the |
| 225 | * refcount drops to zero, as opposed to via the vblank disable |
| 226 | * timer. |
| 227 | * |
| 228 | * This can be set to true it the hardware has a working vblank counter |
| 229 | * with high-precision timestamping (otherwise there are races) and the |
| 230 | * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off() |
| 231 | * appropriately. See also @max_vblank_count and |
| 232 | * &drm_crtc_funcs.get_vblank_counter. |
| 233 | */ |
| 234 | bool vblank_disable_immediate; |
| 235 | |
| 236 | /** |
| 237 | * @vblank: |
| 238 | * |
| 239 | * Array of vblank tracking structures, one per &struct drm_crtc. For |
| 240 | * historical reasons (vblank support predates kernel modesetting) this |
| 241 | * is free-standing and not part of &struct drm_crtc itself. It must be |
| 242 | * initialized explicitly by calling drm_vblank_init(). |
| 243 | */ |
| 244 | struct drm_vblank_crtc *vblank; |
| 245 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 246 | /** |
| 247 | * @vblank_time_lock: |
| 248 | * |
| 249 | * Protects vblank count and time updates during vblank enable/disable |
| 250 | */ |
| 251 | spinlock_t vblank_time_lock; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 252 | spinlock_t vbl_lock; |
| 253 | |
| 254 | /** |
| 255 | * @max_vblank_count: |
| 256 | * |
| 257 | * Maximum value of the vblank registers. This value +1 will result in a |
| 258 | * wrap-around of the vblank register. It is used by the vblank core to |
| 259 | * handle wrap-arounds. |
| 260 | * |
| 261 | * If set to zero the vblank core will try to guess the elapsed vblanks |
| 262 | * between times when the vblank interrupt is disabled through |
| 263 | * high-precision timestamps. That approach is suffering from small |
| 264 | * races and imprecision over longer time periods, hence exposing a |
| 265 | * hardware vblank counter is always recommended. |
| 266 | * |
| 267 | * If non-zeor, &drm_crtc_funcs.get_vblank_counter must be set. |
| 268 | */ |
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 | /** @max_vblank_count: Size of vblank counter register */ |
| 271 | u32 max_vblank_count; |
| 272 | |
| 273 | /** @vblank_event_list: List of vblank events */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 274 | struct list_head vblank_event_list; |
| 275 | spinlock_t event_lock; |
| 276 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 277 | /** @agp: AGP data */ |
| 278 | struct drm_agp_head *agp; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 279 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 280 | /** @pdev: PCI device structure */ |
| 281 | struct pci_dev *pdev; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 282 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 283 | #ifdef __alpha__ |
| 284 | struct pci_controller *hose; |
| 285 | #endif |
| 286 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 287 | /** @sg: Scatter gather memory */ |
| 288 | struct drm_sg_mem *sg; |
| 289 | |
| 290 | /** @num_crtcs: Number of CRTCs on this device */ |
| 291 | unsigned int num_crtcs; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 292 | |
| 293 | struct { |
| 294 | int context; |
| 295 | struct drm_hw_lock *lock; |
| 296 | } sigdata; |
| 297 | |
| 298 | struct drm_local_map *agp_buffer_map; |
| 299 | unsigned int agp_buffer_token; |
| 300 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 301 | /** @mode_config: Current mode config */ |
| 302 | struct drm_mode_config mode_config; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 303 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 304 | /** @object_name_lock: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 305 | struct mutex object_name_lock; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 306 | |
| 307 | /** @object_name_idr: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 308 | struct idr object_name_idr; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 309 | |
| 310 | /** @vma_offset_manager: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 311 | struct drm_vma_offset_manager *vma_offset_manager; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 312 | |
Sam Ravnborg | 7af78f4 | 2019-01-08 20:29:29 +0100 | [diff] [blame^] | 313 | /** |
| 314 | * @switch_power_state: |
| 315 | * |
| 316 | * Power state of the client. |
| 317 | * Used by drivers supporting the switcheroo driver. |
| 318 | * The state is maintained in the |
| 319 | * &vga_switcheroo_client_ops.set_gpu_state callback |
| 320 | */ |
| 321 | enum switch_power_state switch_power_state; |
Noralf Trønnes | 29ad20b22 | 2017-10-30 16:39:38 +0100 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * @fb_helper: |
| 325 | * |
| 326 | * Pointer to the fbdev emulation structure. |
| 327 | * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini(). |
| 328 | */ |
| 329 | struct drm_fb_helper *fb_helper; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 330 | }; |
| 331 | |
| 332 | #endif |