#ifndef _DRM_DEVICE_H_1#define _DRM_DEVICE_H_23#include <linux/list.h>4#include <linux/kref.h>5#include <linux/mutex.h>6#include <linux/idr.h>7#include <linux/sched.h>89#include <drm/drm_mode_config.h>1011struct drm_driver;12struct drm_minor;13struct drm_master;14struct drm_vblank_crtc;15struct drm_vma_offset_manager;16struct drm_vram_mm;17struct drm_fb_helper;1819struct inode;2021struct pci_dev;22struct pci_controller;2324/*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 can27* 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 */3233/**34* struct drm_wedge_task_info - information about the guilty task of a wedge dev35*/36struct drm_wedge_task_info {37/** @pid: pid of the task */38pid_t pid;39/** @comm: command name of the task */40char comm[TASK_COMM_LEN];41};4243/**44* enum switch_power_state - power state of drm device45*/4647enum switch_power_state {48/** @DRM_SWITCH_POWER_ON: Power state is ON */49DRM_SWITCH_POWER_ON = 0,5051/** @DRM_SWITCH_POWER_OFF: Power state is OFF */52DRM_SWITCH_POWER_OFF = 1,5354/** @DRM_SWITCH_POWER_CHANGING: Power state is changing */55DRM_SWITCH_POWER_CHANGING = 2,5657/** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */58DRM_SWITCH_POWER_DYNAMIC_OFF = 3,59};6061/**62* struct drm_device - DRM device structure63*64* This structure represent a complete card that65* may contain multiple heads.66*/67struct drm_device {68/** @if_version: Highest interface version set */69int if_version;7071/** @ref: Object ref-count */72struct kref ref;7374/** @dev: Device structure of bus-device */75struct device *dev;7677/**78* @dma_dev:79*80* Device for DMA operations. Only required if the device @dev81* cannot perform DMA by itself. Should be NULL otherwise. Call82* drm_dev_dma_dev() to get the DMA device instead of using this83* field directly. Call drm_dev_set_dma_dev() to set this field.84*85* DRM devices are sometimes bound to virtual devices that cannot86* perform DMA by themselves. Drivers should set this field to the87* respective DMA controller.88*89* Devices on USB and other peripheral busses also cannot perform90* DMA by themselves. The @dma_dev field should point the bus91* controller that does DMA on behalve of such a device. Required92* for importing buffers via dma-buf.93*94* If set, the DRM core automatically releases the reference on the95* device.96*/97struct device *dma_dev;9899/**100* @managed:101*102* Managed resources linked to the lifetime of this &drm_device as103* tracked by @ref.104*/105struct {106/** @managed.resources: managed resources list */107struct list_head resources;108/** @managed.final_kfree: pointer for final kfree() call */109void *final_kfree;110/** @managed.lock: protects @managed.resources */111spinlock_t lock;112} managed;113114/** @driver: DRM driver managing the device */115const struct drm_driver *driver;116117/**118* @dev_private:119*120* DRM driver private data. This is deprecated and should be left set to121* NULL.122*123* Instead of using this pointer it is recommended that drivers use124* devm_drm_dev_alloc() and embed struct &drm_device in their larger125* per-device structure.126*/127void *dev_private;128129/**130* @primary:131*132* Primary node. Drivers should not interact with this133* directly. debugfs interfaces can be registered with134* drm_debugfs_add_file(), and sysfs should be directly added on the135* hardware (and not character device node) struct device @dev.136*/137struct drm_minor *primary;138139/**140* @render:141*142* Render node. Drivers should not interact with this directly ever.143* Drivers should not expose any additional interfaces in debugfs or144* sysfs on this node.145*/146struct drm_minor *render;147148/** @accel: Compute Acceleration node */149struct drm_minor *accel;150151/**152* @registered:153*154* Internally used by drm_dev_register() and drm_connector_register().155*/156bool registered;157158/**159* @master:160*161* Currently active master for this device.162* Protected by &master_mutex163*/164struct drm_master *master;165166/**167* @driver_features: per-device driver features168*169* Drivers can clear specific flags here to disallow170* certain features on a per-device basis while still171* sharing a single &struct drm_driver instance across172* all devices.173*/174u32 driver_features;175176/**177* @unplugged:178*179* Flag to tell if the device has been unplugged.180* See drm_dev_enter() and drm_dev_is_unplugged().181*/182bool unplugged;183184/** @anon_inode: inode for private address-space */185struct inode *anon_inode;186187/** @unique: Unique name of the device */188char *unique;189190/**191* @struct_mutex:192*193* Lock for others (not &drm_minor.master and &drm_file.is_master)194*195* TODO: This lock used to be the BKL of the DRM subsystem. Move the196* lock into i915, which is the only remaining user.197*/198struct mutex struct_mutex;199200/**201* @master_mutex:202*203* Lock for &drm_minor.master and &drm_file.is_master204*/205struct mutex master_mutex;206207/**208* @open_count:209*210* Usage counter for outstanding files open,211* protected by drm_global_mutex212*/213atomic_t open_count;214215/** @filelist_mutex: Protects @filelist. */216struct mutex filelist_mutex;217/**218* @filelist:219*220* List of userspace clients, linked through &drm_file.lhead.221*/222struct list_head filelist;223224/**225* @filelist_internal:226*227* List of open DRM files for in-kernel clients.228* Protected by &filelist_mutex.229*/230struct list_head filelist_internal;231232/**233* @clientlist_mutex:234*235* Protects &clientlist access.236*/237struct mutex clientlist_mutex;238239/**240* @clientlist:241*242* List of in-kernel clients. Protected by &clientlist_mutex.243*/244struct list_head clientlist;245246/**247* @vblank_disable_immediate:248*249* If true, vblank interrupt will be disabled immediately when the250* refcount drops to zero, as opposed to via the vblank disable251* timer.252*253* This can be set to true it the hardware has a working vblank counter254* with high-precision timestamping (otherwise there are races) and the255* driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()256* appropriately. Also, see @max_vblank_count,257* &drm_crtc_funcs.get_vblank_counter and258* &drm_vblank_crtc_config.disable_immediate.259*/260bool vblank_disable_immediate;261262/**263* @vblank:264*265* Array of vblank tracking structures, one per &struct drm_crtc. For266* historical reasons (vblank support predates kernel modesetting) this267* is free-standing and not part of &struct drm_crtc itself. It must be268* initialized explicitly by calling drm_vblank_init().269*/270struct drm_vblank_crtc *vblank;271272/**273* @vblank_time_lock:274*275* Protects vblank count and time updates during vblank enable/disable276*/277spinlock_t vblank_time_lock;278/**279* @vbl_lock: Top-level vblank references lock, wraps the low-level280* @vblank_time_lock.281*/282spinlock_t vbl_lock;283284/**285* @max_vblank_count:286*287* Maximum value of the vblank registers. This value +1 will result in a288* wrap-around of the vblank register. It is used by the vblank core to289* handle wrap-arounds.290*291* If set to zero the vblank core will try to guess the elapsed vblanks292* between times when the vblank interrupt is disabled through293* high-precision timestamps. That approach is suffering from small294* races and imprecision over longer time periods, hence exposing a295* hardware vblank counter is always recommended.296*297* This is the statically configured device wide maximum. The driver298* can instead choose to use a runtime configurable per-crtc value299* &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count300* must be left at zero. See drm_crtc_set_max_vblank_count() on how301* to use the per-crtc value.302*303* If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.304*/305u32 max_vblank_count;306307/** @vblank_event_list: List of vblank events */308struct list_head vblank_event_list;309310/**311* @event_lock:312*313* Protects @vblank_event_list and event delivery in314* general. See drm_send_event() and drm_send_event_locked().315*/316spinlock_t event_lock;317318/** @num_crtcs: Number of CRTCs on this device */319unsigned int num_crtcs;320321/** @mode_config: Current mode config */322struct drm_mode_config mode_config;323324/** @object_name_lock: GEM information */325struct mutex object_name_lock;326327/** @object_name_idr: GEM information */328struct idr object_name_idr;329330/** @vma_offset_manager: GEM information */331struct drm_vma_offset_manager *vma_offset_manager;332333/** @vram_mm: VRAM MM memory manager */334struct drm_vram_mm *vram_mm;335336/**337* @switch_power_state:338*339* Power state of the client.340* Used by drivers supporting the switcheroo driver.341* The state is maintained in the342* &vga_switcheroo_client_ops.set_gpu_state callback343*/344enum switch_power_state switch_power_state;345346/**347* @fb_helper:348*349* Pointer to the fbdev emulation structure.350* Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().351*/352struct drm_fb_helper *fb_helper;353354/**355* @debugfs_root:356*357* Root directory for debugfs files.358*/359struct dentry *debugfs_root;360};361362void drm_dev_set_dma_dev(struct drm_device *dev, struct device *dma_dev);363364/**365* drm_dev_dma_dev - returns the DMA device for a DRM device366* @dev: DRM device367*368* Returns the DMA device of the given DRM device. By default, this369* the DRM device's parent. See drm_dev_set_dma_dev().370*371* Returns:372* A DMA-capable device for the DRM device.373*/374static inline struct device *drm_dev_dma_dev(struct drm_device *dev)375{376if (dev->dma_dev)377return dev->dma_dev;378return dev->dev;379}380381#endif382383384