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 * @managed: 69 * 70 * Managed resources linked to the lifetime of this &drm_device as 71 * tracked by @ref. 72 */ 73 struct { 74 /** @managed.resources: managed resources list */ 75 struct list_head resources; 76 /** @managed.final_kfree: pointer for final kfree() call */ 77 void *final_kfree; 78 /** @managed.lock: protects @managed.resources */ 79 spinlock_t lock; 80 } managed; 81 82 /** @driver: DRM driver managing the device */ 83 const struct drm_driver *driver; 84 85 /** 86 * @dev_private: 87 * 88 * DRM driver private data. This is deprecated and should be left set to 89 * NULL. 90 * 91 * Instead of using this pointer it is recommended that drivers use 92 * devm_drm_dev_alloc() and embed struct &drm_device in their larger 93 * per-device structure. 94 */ 95 void *dev_private; 96 97 /** 98 * @primary: 99 * 100 * Primary node. Drivers should not interact with this 101 * directly. debugfs interfaces can be registered with 102 * drm_debugfs_add_file(), and sysfs should be directly added on the 103 * hardware (and not character device node) struct device @dev. 104 */ 105 struct drm_minor *primary; 106 107 /** 108 * @render: 109 * 110 * Render node. Drivers should not interact with this directly ever. 111 * Drivers should not expose any additional interfaces in debugfs or 112 * sysfs on this node. 113 */ 114 struct drm_minor *render; 115 116 /** @accel: Compute Acceleration node */ 117 struct drm_minor *accel; 118 119 /** 120 * @registered: 121 * 122 * Internally used by drm_dev_register() and drm_connector_register(). 123 */ 124 bool registered; 125 126 /** 127 * @master: 128 * 129 * Currently active master for this device. 130 * Protected by &master_mutex 131 */ 132 struct drm_master *master; 133 134 /** 135 * @driver_features: per-device driver features 136 * 137 * Drivers can clear specific flags here to disallow 138 * certain features on a per-device basis while still 139 * sharing a single &struct drm_driver instance across 140 * all devices. 141 */ 142 u32 driver_features; 143 144 /** 145 * @unplugged: 146 * 147 * Flag to tell if the device has been unplugged. 148 * See drm_dev_enter() and drm_dev_is_unplugged(). 149 */ 150 bool unplugged; 151 152 /** @anon_inode: inode for private address-space */ 153 struct inode *anon_inode; 154 155 /** @unique: Unique name of the device */ 156 char *unique; 157 158 /** 159 * @struct_mutex: 160 * 161 * Lock for others (not &drm_minor.master and &drm_file.is_master) 162 * 163 * TODO: This lock used to be the BKL of the DRM subsystem. Move the 164 * lock into i915, which is the only remaining user. 165 */ 166 struct mutex struct_mutex; 167 168 /** 169 * @master_mutex: 170 * 171 * Lock for &drm_minor.master and &drm_file.is_master 172 */ 173 struct mutex master_mutex; 174 175 /** 176 * @open_count: 177 * 178 * Usage counter for outstanding files open, 179 * protected by drm_global_mutex 180 */ 181 atomic_t open_count; 182 183 /** @filelist_mutex: Protects @filelist. */ 184 struct mutex filelist_mutex; 185 /** 186 * @filelist: 187 * 188 * List of userspace clients, linked through &drm_file.lhead. 189 */ 190 struct list_head filelist; 191 192 /** 193 * @filelist_internal: 194 * 195 * List of open DRM files for in-kernel clients. 196 * Protected by &filelist_mutex. 197 */ 198 struct list_head filelist_internal; 199 200 /** 201 * @clientlist_mutex: 202 * 203 * Protects &clientlist access. 204 */ 205 struct mutex clientlist_mutex; 206 207 /** 208 * @clientlist: 209 * 210 * List of in-kernel clients. Protected by &clientlist_mutex. 211 */ 212 struct list_head clientlist; 213 214 /** 215 * @vblank_disable_immediate: 216 * 217 * If true, vblank interrupt will be disabled immediately when the 218 * refcount drops to zero, as opposed to via the vblank disable 219 * timer. 220 * 221 * This can be set to true it the hardware has a working vblank counter 222 * with high-precision timestamping (otherwise there are races) and the 223 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off() 224 * appropriately. Also, see @max_vblank_count, 225 * &drm_crtc_funcs.get_vblank_counter and 226 * &drm_vblank_crtc_config.disable_immediate. 227 */ 228 bool vblank_disable_immediate; 229 230 /** 231 * @vblank: 232 * 233 * Array of vblank tracking structures, one per &struct drm_crtc. For 234 * historical reasons (vblank support predates kernel modesetting) this 235 * is free-standing and not part of &struct drm_crtc itself. It must be 236 * initialized explicitly by calling drm_vblank_init(). 237 */ 238 struct drm_vblank_crtc *vblank; 239 240 /** 241 * @vblank_time_lock: 242 * 243 * Protects vblank count and time updates during vblank enable/disable 244 */ 245 spinlock_t vblank_time_lock; 246 /** 247 * @vbl_lock: Top-level vblank references lock, wraps the low-level 248 * @vblank_time_lock. 249 */ 250 spinlock_t vbl_lock; 251 252 /** 253 * @max_vblank_count: 254 * 255 * Maximum value of the vblank registers. This value +1 will result in a 256 * wrap-around of the vblank register. It is used by the vblank core to 257 * handle wrap-arounds. 258 * 259 * If set to zero the vblank core will try to guess the elapsed vblanks 260 * between times when the vblank interrupt is disabled through 261 * high-precision timestamps. That approach is suffering from small 262 * races and imprecision over longer time periods, hence exposing a 263 * hardware vblank counter is always recommended. 264 * 265 * This is the statically configured device wide maximum. The driver 266 * can instead choose to use a runtime configurable per-crtc value 267 * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count 268 * must be left at zero. See drm_crtc_set_max_vblank_count() on how 269 * to use the per-crtc value. 270 * 271 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set. 272 */ 273 u32 max_vblank_count; 274 275 /** @vblank_event_list: List of vblank events */ 276 struct list_head vblank_event_list; 277 278 /** 279 * @event_lock: 280 * 281 * Protects @vblank_event_list and event delivery in 282 * general. See drm_send_event() and drm_send_event_locked(). 283 */ 284 spinlock_t event_lock; 285 286 /** @num_crtcs: Number of CRTCs on this device */ 287 unsigned int num_crtcs; 288 289 /** @mode_config: Current mode config */ 290 struct drm_mode_config mode_config; 291 292 /** @object_name_lock: GEM information */ 293 struct mutex object_name_lock; 294 295 /** @object_name_idr: GEM information */ 296 struct idr object_name_idr; 297 298 /** @vma_offset_manager: GEM information */ 299 struct drm_vma_offset_manager *vma_offset_manager; 300 301 /** @vram_mm: VRAM MM memory manager */ 302 struct drm_vram_mm *vram_mm; 303 304 /** 305 * @switch_power_state: 306 * 307 * Power state of the client. 308 * Used by drivers supporting the switcheroo driver. 309 * The state is maintained in the 310 * &vga_switcheroo_client_ops.set_gpu_state callback 311 */ 312 enum switch_power_state switch_power_state; 313 314 /** 315 * @fb_helper: 316 * 317 * Pointer to the fbdev emulation structure. 318 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini(). 319 */ 320 struct drm_fb_helper *fb_helper; 321 322 /** 323 * @debugfs_root: 324 * 325 * Root directory for debugfs files. 326 */ 327 struct dentry *debugfs_root; 328 }; 329 330 #endif 331