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