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 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 9 | #include <drm/drm_mode_config.h> |
| 10 | |
| 11 | struct drm_driver; |
| 12 | struct drm_minor; |
| 13 | struct drm_master; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 14 | struct drm_vblank_crtc; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 15 | struct drm_vma_offset_manager; |
Thomas Zimmermann | 59f5989 | 2019-05-08 10:26:18 +0200 | [diff] [blame] | 16 | struct drm_vram_mm; |
Noralf Trønnes | 29ad20b22 | 2017-10-30 16:39:38 +0100 | [diff] [blame] | 17 | struct drm_fb_helper; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 18 | |
| 19 | struct inode; |
| 20 | |
| 21 | struct pci_dev; |
| 22 | struct pci_controller; |
| 23 | |
Sam Ravnborg | 7af78f4 | 2019-01-08 20:29:29 +0100 | [diff] [blame] | 24 | |
| 25 | /** |
Mauro Carvalho Chehab | e9d2871 | 2020-11-16 11:18:01 +0100 | [diff] [blame] | 26 | * enum switch_power_state - power state of drm device |
Sam Ravnborg | 7af78f4 | 2019-01-08 20:29:29 +0100 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | enum switch_power_state { |
| 30 | /** @DRM_SWITCH_POWER_ON: Power state is ON */ |
| 31 | DRM_SWITCH_POWER_ON = 0, |
| 32 | |
| 33 | /** @DRM_SWITCH_POWER_OFF: Power state is OFF */ |
| 34 | DRM_SWITCH_POWER_OFF = 1, |
| 35 | |
| 36 | /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */ |
| 37 | DRM_SWITCH_POWER_CHANGING = 2, |
| 38 | |
| 39 | /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */ |
| 40 | DRM_SWITCH_POWER_DYNAMIC_OFF = 3, |
| 41 | }; |
| 42 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 43 | /** |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 44 | * struct drm_device - DRM device structure |
| 45 | * |
| 46 | * This structure represent a complete card that |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 47 | * may contain multiple heads. |
| 48 | */ |
| 49 | struct drm_device { |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 50 | /** @if_version: Highest interface version set */ |
| 51 | int if_version; |
| 52 | |
| 53 | /** @ref: Object ref-count */ |
| 54 | struct kref ref; |
| 55 | |
| 56 | /** @dev: Device structure of bus-device */ |
| 57 | struct device *dev; |
| 58 | |
Daniel Vetter | c6603c7 | 2020-03-24 13:45:40 +0100 | [diff] [blame] | 59 | /** |
| 60 | * @managed: |
| 61 | * |
| 62 | * Managed resources linked to the lifetime of this &drm_device as |
| 63 | * tracked by @ref. |
| 64 | */ |
| 65 | struct { |
| 66 | /** @managed.resources: managed resources list */ |
| 67 | struct list_head resources; |
| 68 | /** @managed.final_kfree: pointer for final kfree() call */ |
| 69 | void *final_kfree; |
| 70 | /** @managed.lock: protects @managed.resources */ |
| 71 | spinlock_t lock; |
| 72 | } managed; |
| 73 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 74 | /** @driver: DRM driver managing the device */ |
Daniel Vetter | 8f5c7aa | 2020-11-04 11:04:23 +0100 | [diff] [blame] | 75 | const struct drm_driver *driver; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 76 | |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 77 | /** |
| 78 | * @dev_private: |
| 79 | * |
Daniel Vetter | 74aae1c | 2020-04-03 15:57:47 +0200 | [diff] [blame] | 80 | * DRM driver private data. This is deprecated and should be left set to |
| 81 | * NULL. |
| 82 | * |
| 83 | * Instead of using this pointer it is recommended that drivers use |
Daniel Vetter | 4c8e84b8 | 2020-09-02 09:26:27 +0200 | [diff] [blame] | 84 | * devm_drm_dev_alloc() and embed struct &drm_device in their larger |
Daniel Vetter | 74aae1c | 2020-04-03 15:57:47 +0200 | [diff] [blame] | 85 | * per-device structure. |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 86 | */ |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 87 | void *dev_private; |
| 88 | |
Daniel Vetter | 99845fa | 2023-01-09 17:46:04 +0100 | [diff] [blame] | 89 | /** |
| 90 | * @primary: |
| 91 | * |
| 92 | * Primary node. Drivers should not interact with this |
| 93 | * directly. debugfs interfaces can be registered with |
| 94 | * drm_debugfs_add_file(), and sysfs should be directly added on the |
| 95 | * hardware (and not character device node) struct device @dev. |
| 96 | */ |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 97 | struct drm_minor *primary; |
| 98 | |
Daniel Vetter | 99845fa | 2023-01-09 17:46:04 +0100 | [diff] [blame] | 99 | /** |
| 100 | * @render: |
| 101 | * |
| 102 | * Render node. Drivers should not interact with this directly ever. |
| 103 | * Drivers should not expose any additional interfaces in debugfs or |
| 104 | * sysfs on this node. |
| 105 | */ |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 106 | struct drm_minor *render; |
| 107 | |
Oded Gabbay | 2c204f3 | 2022-10-31 15:33:06 +0200 | [diff] [blame] | 108 | /** @accel: Compute Acceleration node */ |
| 109 | struct drm_minor *accel; |
| 110 | |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 111 | /** |
| 112 | * @registered: |
| 113 | * |
| 114 | * Internally used by drm_dev_register() and drm_connector_register(). |
| 115 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 116 | bool registered; |
| 117 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 118 | /** |
| 119 | * @master: |
| 120 | * |
| 121 | * Currently active master for this device. |
| 122 | * Protected by &master_mutex |
| 123 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 124 | struct drm_master *master; |
| 125 | |
Noralf Trønnes | bee330f | 2018-03-28 10:38:35 +0300 | [diff] [blame] | 126 | /** |
Ville Syrjälä | 18ace11 | 2018-09-13 16:16:21 +0300 | [diff] [blame] | 127 | * @driver_features: per-device driver features |
| 128 | * |
| 129 | * Drivers can clear specific flags here to disallow |
| 130 | * certain features on a per-device basis while still |
| 131 | * sharing a single &struct drm_driver instance across |
| 132 | * all devices. |
| 133 | */ |
| 134 | u32 driver_features; |
| 135 | |
| 136 | /** |
Noralf Trønnes | bee330f | 2018-03-28 10:38:35 +0300 | [diff] [blame] | 137 | * @unplugged: |
| 138 | * |
| 139 | * Flag to tell if the device has been unplugged. |
| 140 | * See drm_dev_enter() and drm_dev_is_unplugged(). |
| 141 | */ |
| 142 | bool unplugged; |
| 143 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 144 | /** @anon_inode: inode for private address-space */ |
| 145 | struct inode *anon_inode; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 146 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 147 | /** @unique: Unique name of the device */ |
| 148 | char *unique; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 149 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 150 | /** |
| 151 | * @struct_mutex: |
| 152 | * |
| 153 | * Lock for others (not &drm_minor.master and &drm_file.is_master) |
Emil Velikov | e33f423 | 2020-05-15 10:50:45 +0100 | [diff] [blame] | 154 | * |
Thomas Zimmermann | 2504c7e | 2023-11-22 13:09:41 +0100 | [diff] [blame] | 155 | * TODO: This lock used to be the BKL of the DRM subsystem. Move the |
| 156 | * lock into i915, which is the only remaining user. |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 157 | */ |
| 158 | struct mutex struct_mutex; |
| 159 | |
| 160 | /** |
| 161 | * @master_mutex: |
| 162 | * |
| 163 | * Lock for &drm_minor.master and &drm_file.is_master |
| 164 | */ |
| 165 | struct mutex master_mutex; |
| 166 | |
| 167 | /** |
| 168 | * @open_count: |
| 169 | * |
| 170 | * Usage counter for outstanding files open, |
| 171 | * protected by drm_global_mutex |
| 172 | */ |
Chris Wilson | 7e13ad8 | 2020-01-24 13:01:07 +0000 | [diff] [blame] | 173 | atomic_t open_count; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 174 | |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 175 | /** @filelist_mutex: Protects @filelist. */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 176 | struct mutex filelist_mutex; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 177 | /** |
| 178 | * @filelist: |
| 179 | * |
| 180 | * List of userspace clients, linked through &drm_file.lhead. |
| 181 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 182 | struct list_head filelist; |
| 183 | |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 184 | /** |
| 185 | * @filelist_internal: |
| 186 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 187 | * List of open DRM files for in-kernel clients. |
| 188 | * Protected by &filelist_mutex. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 189 | */ |
| 190 | struct list_head filelist_internal; |
| 191 | |
| 192 | /** |
| 193 | * @clientlist_mutex: |
| 194 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 195 | * Protects &clientlist access. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 196 | */ |
| 197 | struct mutex clientlist_mutex; |
| 198 | |
| 199 | /** |
| 200 | * @clientlist: |
| 201 | * |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 202 | * List of in-kernel clients. Protected by &clientlist_mutex. |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 203 | */ |
| 204 | struct list_head clientlist; |
| 205 | |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 206 | /** |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 207 | * @vblank_disable_immediate: |
| 208 | * |
| 209 | * If true, vblank interrupt will be disabled immediately when the |
| 210 | * refcount drops to zero, as opposed to via the vblank disable |
| 211 | * timer. |
| 212 | * |
| 213 | * This can be set to true it the hardware has a working vblank counter |
| 214 | * with high-precision timestamping (otherwise there are races) and the |
| 215 | * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off() |
| 216 | * appropriately. See also @max_vblank_count and |
| 217 | * &drm_crtc_funcs.get_vblank_counter. |
| 218 | */ |
| 219 | bool vblank_disable_immediate; |
| 220 | |
| 221 | /** |
| 222 | * @vblank: |
| 223 | * |
| 224 | * Array of vblank tracking structures, one per &struct drm_crtc. For |
| 225 | * historical reasons (vblank support predates kernel modesetting) this |
| 226 | * is free-standing and not part of &struct drm_crtc itself. It must be |
| 227 | * initialized explicitly by calling drm_vblank_init(). |
| 228 | */ |
| 229 | struct drm_vblank_crtc *vblank; |
| 230 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 231 | /** |
| 232 | * @vblank_time_lock: |
| 233 | * |
| 234 | * Protects vblank count and time updates during vblank enable/disable |
| 235 | */ |
| 236 | spinlock_t vblank_time_lock; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 237 | /** |
| 238 | * @vbl_lock: Top-level vblank references lock, wraps the low-level |
| 239 | * @vblank_time_lock. |
| 240 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 241 | spinlock_t vbl_lock; |
| 242 | |
| 243 | /** |
| 244 | * @max_vblank_count: |
| 245 | * |
| 246 | * Maximum value of the vblank registers. This value +1 will result in a |
| 247 | * wrap-around of the vblank register. It is used by the vblank core to |
| 248 | * handle wrap-arounds. |
| 249 | * |
| 250 | * If set to zero the vblank core will try to guess the elapsed vblanks |
| 251 | * between times when the vblank interrupt is disabled through |
| 252 | * high-precision timestamps. That approach is suffering from small |
| 253 | * races and imprecision over longer time periods, hence exposing a |
| 254 | * hardware vblank counter is always recommended. |
| 255 | * |
Ville Syrjälä | ed20151 | 2018-11-27 20:20:04 +0200 | [diff] [blame] | 256 | * This is the statically configured device wide maximum. The driver |
| 257 | * can instead choose to use a runtime configurable per-crtc value |
| 258 | * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count |
| 259 | * must be left at zero. See drm_crtc_set_max_vblank_count() on how |
| 260 | * to use the per-crtc value. |
| 261 | * |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 262 | * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set. |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 263 | */ |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 264 | u32 max_vblank_count; |
| 265 | |
| 266 | /** @vblank_event_list: List of vblank events */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 267 | struct list_head vblank_event_list; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 268 | |
| 269 | /** |
| 270 | * @event_lock: |
| 271 | * |
| 272 | * Protects @vblank_event_list and event delivery in |
| 273 | * general. See drm_send_event() and drm_send_event_locked(). |
| 274 | */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 275 | spinlock_t event_lock; |
| 276 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 277 | /** @num_crtcs: Number of CRTCs on this device */ |
| 278 | unsigned int num_crtcs; |
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 | /** @mode_config: Current mode config */ |
| 281 | struct drm_mode_config mode_config; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 282 | |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 283 | /** @object_name_lock: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 284 | struct mutex object_name_lock; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 285 | |
| 286 | /** @object_name_idr: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 287 | struct idr object_name_idr; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 288 | |
| 289 | /** @vma_offset_manager: GEM information */ |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 290 | struct drm_vma_offset_manager *vma_offset_manager; |
Sam Ravnborg | ac4f24c | 2019-01-08 20:29:28 +0100 | [diff] [blame] | 291 | |
Thomas Zimmermann | 59f5989 | 2019-05-08 10:26:18 +0200 | [diff] [blame] | 292 | /** @vram_mm: VRAM MM memory manager */ |
| 293 | struct drm_vram_mm *vram_mm; |
| 294 | |
Sam Ravnborg | 7af78f4 | 2019-01-08 20:29:29 +0100 | [diff] [blame] | 295 | /** |
| 296 | * @switch_power_state: |
| 297 | * |
| 298 | * Power state of the client. |
| 299 | * Used by drivers supporting the switcheroo driver. |
| 300 | * The state is maintained in the |
| 301 | * &vga_switcheroo_client_ops.set_gpu_state callback |
| 302 | */ |
| 303 | enum switch_power_state switch_power_state; |
Noralf Trønnes | 29ad20b22 | 2017-10-30 16:39:38 +0100 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * @fb_helper: |
| 307 | * |
| 308 | * Pointer to the fbdev emulation structure. |
| 309 | * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini(). |
| 310 | */ |
| 311 | struct drm_fb_helper *fb_helper; |
Daniel Vetter | 3214a16 | 2019-01-11 17:40:48 +0100 | [diff] [blame] | 312 | |
Maíra Canal | 1c9cacb | 2022-12-19 09:06:15 -0300 | [diff] [blame] | 313 | /** |
Christian König | 0b30d57 | 2023-08-29 13:01:13 +0200 | [diff] [blame] | 314 | * @debugfs_root: |
| 315 | * |
| 316 | * Root directory for debugfs files. |
| 317 | */ |
| 318 | struct dentry *debugfs_root; |
Daniel Vetter | e4672e5 | 2017-08-02 13:56:01 +0200 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | #endif |