| 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_mode_config.h> |
| 10 | |
| 11 | struct drm_driver; |
| 12 | struct drm_minor; |
| 13 | struct drm_master; |
| 14 | struct drm_vblank_crtc; |
| 15 | struct drm_vma_offset_manager; |
| 16 | struct drm_vram_mm; |
| 17 | struct drm_fb_helper; |
| 18 | |
| 19 | struct inode; |
| 20 | |
| 21 | struct pci_dev; |
| 22 | struct pci_controller; |
| 23 | |
| 24 | /* |
| 25 | * Recovery methods for wedged device in order of less to more side-effects. |
| 26 | * To be used with drm_dev_wedged_event() as recovery @method. Callers can |
| 27 | * use any one, multiple (or'd) or none depending on their needs. |
| 28 | */ |
| 29 | #define DRM_WEDGE_RECOVERY_NONE BIT(0) /* optional telemetry collection */ |
| 30 | #define DRM_WEDGE_RECOVERY_REBIND BIT(1) /* unbind + bind driver */ |
| 31 | #define DRM_WEDGE_RECOVERY_BUS_RESET BIT(2) /* unbind + reset bus device + bind */ |
| 32 | |
| 33 | /** |
| 34 | * enum switch_power_state - power state of drm device |
| 35 | */ |
| 36 | |
| 37 | enum switch_power_state { |
| 38 | /** @DRM_SWITCH_POWER_ON: Power state is ON */ |
| 39 | DRM_SWITCH_POWER_ON = 0, |
| 40 | |
| 41 | /** @DRM_SWITCH_POWER_OFF: Power state is OFF */ |
| 42 | DRM_SWITCH_POWER_OFF = 1, |
| 43 | |
| 44 | /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */ |
| 45 | DRM_SWITCH_POWER_CHANGING = 2, |
| 46 | |
| 47 | /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */ |
| 48 | DRM_SWITCH_POWER_DYNAMIC_OFF = 3, |
| 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * struct drm_device - DRM device structure |
| 53 | * |
| 54 | * This structure represent a complete card that |
| 55 | * may contain multiple heads. |
| 56 | */ |
| 57 | struct drm_device { |
| 58 | /** @if_version: Highest interface version set */ |
| 59 | int if_version; |
| 60 | |
| 61 | /** @ref: Object ref-count */ |
| 62 | struct kref ref; |
| 63 | |
| 64 | /** @dev: Device structure of bus-device */ |
| 65 | struct device *dev; |
| 66 | |
| 67 | /** |
| 68 | * @dma_dev: |
| 69 | * |
| 70 | * Device for DMA operations. Only required if the device @dev |
| 71 | * cannot perform DMA by itself. Should be NULL otherwise. Call |
| 72 | * drm_dev_dma_dev() to get the DMA device instead of using this |
| 73 | * field directly. Call drm_dev_set_dma_dev() to set this field. |
| 74 | * |
| 75 | * DRM devices are sometimes bound to virtual devices that cannot |
| 76 | * perform DMA by themselves. Drivers should set this field to the |
| 77 | * respective DMA controller. |
| 78 | * |
| 79 | * Devices on USB and other peripheral busses also cannot perform |
| 80 | * DMA by themselves. The @dma_dev field should point the bus |
| 81 | * controller that does DMA on behalve of such a device. Required |
| 82 | * for importing buffers via dma-buf. |
| 83 | * |
| 84 | * If set, the DRM core automatically releases the reference on the |
| 85 | * device. |
| 86 | */ |
| 87 | struct device *dma_dev; |
| 88 | |
| 89 | /** |
| 90 | * @managed: |
| 91 | * |
| 92 | * Managed resources linked to the lifetime of this &drm_device as |
| 93 | * tracked by @ref. |
| 94 | */ |
| 95 | struct { |
| 96 | /** @managed.resources: managed resources list */ |
| 97 | struct list_head resources; |
| 98 | /** @managed.final_kfree: pointer for final kfree() call */ |
| 99 | void *final_kfree; |
| 100 | /** @managed.lock: protects @managed.resources */ |
| 101 | spinlock_t lock; |
| 102 | } managed; |
| 103 | |
| 104 | /** @driver: DRM driver managing the device */ |
| 105 | const struct drm_driver *driver; |
| 106 | |
| 107 | /** |
| 108 | * @dev_private: |
| 109 | * |
| 110 | * DRM driver private data. This is deprecated and should be left set to |
| 111 | * NULL. |
| 112 | * |
| 113 | * Instead of using this pointer it is recommended that drivers use |
| 114 | * devm_drm_dev_alloc() and embed struct &drm_device in their larger |
| 115 | * per-device structure. |
| 116 | */ |
| 117 | void *dev_private; |
| 118 | |
| 119 | /** |
| 120 | * @primary: |
| 121 | * |
| 122 | * Primary node. Drivers should not interact with this |
| 123 | * directly. debugfs interfaces can be registered with |
| 124 | * drm_debugfs_add_file(), and sysfs should be directly added on the |
| 125 | * hardware (and not character device node) struct device @dev. |
| 126 | */ |
| 127 | struct drm_minor *primary; |
| 128 | |
| 129 | /** |
| 130 | * @render: |
| 131 | * |
| 132 | * Render node. Drivers should not interact with this directly ever. |
| 133 | * Drivers should not expose any additional interfaces in debugfs or |
| 134 | * sysfs on this node. |
| 135 | */ |
| 136 | struct drm_minor *render; |
| 137 | |
| 138 | /** @accel: Compute Acceleration node */ |
| 139 | struct drm_minor *accel; |
| 140 | |
| 141 | /** |
| 142 | * @registered: |
| 143 | * |
| 144 | * Internally used by drm_dev_register() and drm_connector_register(). |
| 145 | */ |
| 146 | bool registered; |
| 147 | |
| 148 | /** |
| 149 | * @master: |
| 150 | * |
| 151 | * Currently active master for this device. |
| 152 | * Protected by &master_mutex |
| 153 | */ |
| 154 | struct drm_master *master; |
| 155 | |
| 156 | /** |
| 157 | * @driver_features: per-device driver features |
| 158 | * |
| 159 | * Drivers can clear specific flags here to disallow |
| 160 | * certain features on a per-device basis while still |
| 161 | * sharing a single &struct drm_driver instance across |
| 162 | * all devices. |
| 163 | */ |
| 164 | u32 driver_features; |
| 165 | |
| 166 | /** |
| 167 | * @unplugged: |
| 168 | * |
| 169 | * Flag to tell if the device has been unplugged. |
| 170 | * See drm_dev_enter() and drm_dev_is_unplugged(). |
| 171 | */ |
| 172 | bool unplugged; |
| 173 | |
| 174 | /** @anon_inode: inode for private address-space */ |
| 175 | struct inode *anon_inode; |
| 176 | |
| 177 | /** @unique: Unique name of the device */ |
| 178 | char *unique; |
| 179 | |
| 180 | /** |
| 181 | * @struct_mutex: |
| 182 | * |
| 183 | * Lock for others (not &drm_minor.master and &drm_file.is_master) |
| 184 | * |
| 185 | * TODO: This lock used to be the BKL of the DRM subsystem. Move the |
| 186 | * lock into i915, which is the only remaining user. |
| 187 | */ |
| 188 | struct mutex struct_mutex; |
| 189 | |
| 190 | /** |
| 191 | * @master_mutex: |
| 192 | * |
| 193 | * Lock for &drm_minor.master and &drm_file.is_master |
| 194 | */ |
| 195 | struct mutex master_mutex; |
| 196 | |
| 197 | /** |
| 198 | * @open_count: |
| 199 | * |
| 200 | * Usage counter for outstanding files open, |
| 201 | * protected by drm_global_mutex |
| 202 | */ |
| 203 | atomic_t open_count; |
| 204 | |
| 205 | /** @filelist_mutex: Protects @filelist. */ |
| 206 | struct mutex filelist_mutex; |
| 207 | /** |
| 208 | * @filelist: |
| 209 | * |
| 210 | * List of userspace clients, linked through &drm_file.lhead. |
| 211 | */ |
| 212 | struct list_head filelist; |
| 213 | |
| 214 | /** |
| 215 | * @filelist_internal: |
| 216 | * |
| 217 | * List of open DRM files for in-kernel clients. |
| 218 | * Protected by &filelist_mutex. |
| 219 | */ |
| 220 | struct list_head filelist_internal; |
| 221 | |
| 222 | /** |
| 223 | * @clientlist_mutex: |
| 224 | * |
| 225 | * Protects &clientlist access. |
| 226 | */ |
| 227 | struct mutex clientlist_mutex; |
| 228 | |
| 229 | /** |
| 230 | * @clientlist: |
| 231 | * |
| 232 | * List of in-kernel clients. Protected by &clientlist_mutex. |
| 233 | */ |
| 234 | struct list_head clientlist; |
| 235 | |
| 236 | /** |
| 237 | * @vblank_disable_immediate: |
| 238 | * |
| 239 | * If true, vblank interrupt will be disabled immediately when the |
| 240 | * refcount drops to zero, as opposed to via the vblank disable |
| 241 | * timer. |
| 242 | * |
| 243 | * This can be set to true it the hardware has a working vblank counter |
| 244 | * with high-precision timestamping (otherwise there are races) and the |
| 245 | * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off() |
| 246 | * appropriately. Also, see @max_vblank_count, |
| 247 | * &drm_crtc_funcs.get_vblank_counter and |
| 248 | * &drm_vblank_crtc_config.disable_immediate. |
| 249 | */ |
| 250 | bool vblank_disable_immediate; |
| 251 | |
| 252 | /** |
| 253 | * @vblank: |
| 254 | * |
| 255 | * Array of vblank tracking structures, one per &struct drm_crtc. For |
| 256 | * historical reasons (vblank support predates kernel modesetting) this |
| 257 | * is free-standing and not part of &struct drm_crtc itself. It must be |
| 258 | * initialized explicitly by calling drm_vblank_init(). |
| 259 | */ |
| 260 | struct drm_vblank_crtc *vblank; |
| 261 | |
| 262 | /** |
| 263 | * @vblank_time_lock: |
| 264 | * |
| 265 | * Protects vblank count and time updates during vblank enable/disable |
| 266 | */ |
| 267 | spinlock_t vblank_time_lock; |
| 268 | /** |
| 269 | * @vbl_lock: Top-level vblank references lock, wraps the low-level |
| 270 | * @vblank_time_lock. |
| 271 | */ |
| 272 | spinlock_t vbl_lock; |
| 273 | |
| 274 | /** |
| 275 | * @max_vblank_count: |
| 276 | * |
| 277 | * Maximum value of the vblank registers. This value +1 will result in a |
| 278 | * wrap-around of the vblank register. It is used by the vblank core to |
| 279 | * handle wrap-arounds. |
| 280 | * |
| 281 | * If set to zero the vblank core will try to guess the elapsed vblanks |
| 282 | * between times when the vblank interrupt is disabled through |
| 283 | * high-precision timestamps. That approach is suffering from small |
| 284 | * races and imprecision over longer time periods, hence exposing a |
| 285 | * hardware vblank counter is always recommended. |
| 286 | * |
| 287 | * This is the statically configured device wide maximum. The driver |
| 288 | * can instead choose to use a runtime configurable per-crtc value |
| 289 | * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count |
| 290 | * must be left at zero. See drm_crtc_set_max_vblank_count() on how |
| 291 | * to use the per-crtc value. |
| 292 | * |
| 293 | * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set. |
| 294 | */ |
| 295 | u32 max_vblank_count; |
| 296 | |
| 297 | /** @vblank_event_list: List of vblank events */ |
| 298 | struct list_head vblank_event_list; |
| 299 | |
| 300 | /** |
| 301 | * @event_lock: |
| 302 | * |
| 303 | * Protects @vblank_event_list and event delivery in |
| 304 | * general. See drm_send_event() and drm_send_event_locked(). |
| 305 | */ |
| 306 | spinlock_t event_lock; |
| 307 | |
| 308 | /** @num_crtcs: Number of CRTCs on this device */ |
| 309 | unsigned int num_crtcs; |
| 310 | |
| 311 | /** @mode_config: Current mode config */ |
| 312 | struct drm_mode_config mode_config; |
| 313 | |
| 314 | /** @object_name_lock: GEM information */ |
| 315 | struct mutex object_name_lock; |
| 316 | |
| 317 | /** @object_name_idr: GEM information */ |
| 318 | struct idr object_name_idr; |
| 319 | |
| 320 | /** @vma_offset_manager: GEM information */ |
| 321 | struct drm_vma_offset_manager *vma_offset_manager; |
| 322 | |
| 323 | /** @vram_mm: VRAM MM memory manager */ |
| 324 | struct drm_vram_mm *vram_mm; |
| 325 | |
| 326 | /** |
| 327 | * @switch_power_state: |
| 328 | * |
| 329 | * Power state of the client. |
| 330 | * Used by drivers supporting the switcheroo driver. |
| 331 | * The state is maintained in the |
| 332 | * &vga_switcheroo_client_ops.set_gpu_state callback |
| 333 | */ |
| 334 | enum switch_power_state switch_power_state; |
| 335 | |
| 336 | /** |
| 337 | * @fb_helper: |
| 338 | * |
| 339 | * Pointer to the fbdev emulation structure. |
| 340 | * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini(). |
| 341 | */ |
| 342 | struct drm_fb_helper *fb_helper; |
| 343 | |
| 344 | /** |
| 345 | * @debugfs_root: |
| 346 | * |
| 347 | * Root directory for debugfs files. |
| 348 | */ |
| 349 | struct dentry *debugfs_root; |
| 350 | }; |
| 351 | |
| 352 | void drm_dev_set_dma_dev(struct drm_device *dev, struct device *dma_dev); |
| 353 | |
| 354 | /** |
| 355 | * drm_dev_dma_dev - returns the DMA device for a DRM device |
| 356 | * @dev: DRM device |
| 357 | * |
| 358 | * Returns the DMA device of the given DRM device. By default, this |
| 359 | * the DRM device's parent. See drm_dev_set_dma_dev(). |
| 360 | * |
| 361 | * Returns: |
| 362 | * A DMA-capable device for the DRM device. |
| 363 | */ |
| 364 | static inline struct device *drm_dev_dma_dev(struct drm_device *dev) |
| 365 | { |
| 366 | if (dev->dma_dev) |
| 367 | return dev->dma_dev; |
| 368 | return dev->dev; |
| 369 | } |
| 370 | |
| 371 | #endif |
| 372 | |