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