#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* Refer to "Device Wedging" chapter in Documentation/gpu/drm-uapi.rst for more30* details.31*/32#define DRM_WEDGE_RECOVERY_NONE BIT(0) /* optional telemetry collection */33#define DRM_WEDGE_RECOVERY_REBIND BIT(1) /* unbind + bind driver */34#define DRM_WEDGE_RECOVERY_BUS_RESET BIT(2) /* unbind + reset bus device + bind */35#define DRM_WEDGE_RECOVERY_VENDOR BIT(3) /* vendor specific recovery method */3637/**38* struct drm_wedge_task_info - information about the guilty task of a wedge dev39*/40struct drm_wedge_task_info {41/** @pid: pid of the task */42pid_t pid;43/** @comm: command name of the task */44char comm[TASK_COMM_LEN];45};4647/**48* enum switch_power_state - power state of drm device49*/5051enum switch_power_state {52/** @DRM_SWITCH_POWER_ON: Power state is ON */53DRM_SWITCH_POWER_ON = 0,5455/** @DRM_SWITCH_POWER_OFF: Power state is OFF */56DRM_SWITCH_POWER_OFF = 1,5758/** @DRM_SWITCH_POWER_CHANGING: Power state is changing */59DRM_SWITCH_POWER_CHANGING = 2,6061/** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */62DRM_SWITCH_POWER_DYNAMIC_OFF = 3,63};6465/**66* struct drm_device - DRM device structure67*68* This structure represent a complete card that69* may contain multiple heads.70*/71struct drm_device {72/** @if_version: Highest interface version set */73int if_version;7475/** @ref: Object ref-count */76struct kref ref;7778/** @dev: Device structure of bus-device */79struct device *dev;8081/**82* @dma_dev:83*84* Device for DMA operations. Only required if the device @dev85* cannot perform DMA by itself. Should be NULL otherwise. Call86* drm_dev_dma_dev() to get the DMA device instead of using this87* field directly. Call drm_dev_set_dma_dev() to set this field.88*89* DRM devices are sometimes bound to virtual devices that cannot90* perform DMA by themselves. Drivers should set this field to the91* respective DMA controller.92*93* Devices on USB and other peripheral busses also cannot perform94* DMA by themselves. The @dma_dev field should point the bus95* controller that does DMA on behalve of such a device. Required96* for importing buffers via dma-buf.97*98* If set, the DRM core automatically releases the reference on the99* device.100*/101struct device *dma_dev;102103/**104* @managed:105*106* Managed resources linked to the lifetime of this &drm_device as107* tracked by @ref.108*/109struct {110/** @managed.resources: managed resources list */111struct list_head resources;112/** @managed.final_kfree: pointer for final kfree() call */113void *final_kfree;114/** @managed.lock: protects @managed.resources */115spinlock_t lock;116} managed;117118/** @driver: DRM driver managing the device */119const struct drm_driver *driver;120121/**122* @dev_private:123*124* DRM driver private data. This is deprecated and should be left set to125* NULL.126*127* Instead of using this pointer it is recommended that drivers use128* devm_drm_dev_alloc() and embed struct &drm_device in their larger129* per-device structure.130*/131void *dev_private;132133/**134* @primary:135*136* Primary node. Drivers should not interact with this137* directly. debugfs interfaces can be registered with138* drm_debugfs_add_file(), and sysfs should be directly added on the139* hardware (and not character device node) struct device @dev.140*/141struct drm_minor *primary;142143/**144* @render:145*146* Render node. Drivers should not interact with this directly ever.147* Drivers should not expose any additional interfaces in debugfs or148* sysfs on this node.149*/150struct drm_minor *render;151152/** @accel: Compute Acceleration node */153struct drm_minor *accel;154155/**156* @registered:157*158* Internally used by drm_dev_register() and drm_connector_register().159*/160bool registered;161162/**163* @master:164*165* Currently active master for this device.166* Protected by &master_mutex167*/168struct drm_master *master;169170/**171* @driver_features: per-device driver features172*173* Drivers can clear specific flags here to disallow174* certain features on a per-device basis while still175* sharing a single &struct drm_driver instance across176* all devices.177*/178u32 driver_features;179180/**181* @unplugged:182*183* Flag to tell if the device has been unplugged.184* See drm_dev_enter() and drm_dev_is_unplugged().185*/186bool unplugged;187188/** @anon_inode: inode for private address-space */189struct inode *anon_inode;190191/** @unique: Unique name of the device */192char *unique;193194/**195* @master_mutex:196*197* Lock for &drm_minor.master and &drm_file.is_master198*/199struct mutex master_mutex;200201/**202* @open_count:203*204* Usage counter for outstanding files open,205* protected by drm_global_mutex206*/207atomic_t open_count;208209/** @filelist_mutex: Protects @filelist. */210struct mutex filelist_mutex;211/**212* @filelist:213*214* List of userspace clients, linked through &drm_file.lhead.215*/216struct list_head filelist;217218/**219* @filelist_internal:220*221* List of open DRM files for in-kernel clients.222* Protected by &filelist_mutex.223*/224struct list_head filelist_internal;225226/**227* @clientlist_mutex:228*229* Protects &clientlist access.230*/231struct mutex clientlist_mutex;232233/**234* @clientlist:235*236* List of in-kernel clients. Protected by &clientlist_mutex.237*/238struct list_head clientlist;239240/**241* @vblank_disable_immediate:242*243* If true, vblank interrupt will be disabled immediately when the244* refcount drops to zero, as opposed to via the vblank disable245* timer.246*247* This can be set to true it the hardware has a working vblank counter248* with high-precision timestamping (otherwise there are races) and the249* driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()250* appropriately. Also, see @max_vblank_count,251* &drm_crtc_funcs.get_vblank_counter and252* &drm_vblank_crtc_config.disable_immediate.253*/254bool vblank_disable_immediate;255256/**257* @vblank:258*259* Array of vblank tracking structures, one per &struct drm_crtc. For260* historical reasons (vblank support predates kernel modesetting) this261* is free-standing and not part of &struct drm_crtc itself. It must be262* initialized explicitly by calling drm_vblank_init().263*/264struct drm_vblank_crtc *vblank;265266/**267* @vblank_time_lock:268*269* Protects vblank count and time updates during vblank enable/disable270*/271spinlock_t vblank_time_lock;272/**273* @vbl_lock: Top-level vblank references lock, wraps the low-level274* @vblank_time_lock.275*/276spinlock_t vbl_lock;277278/**279* @max_vblank_count:280*281* Maximum value of the vblank registers. This value +1 will result in a282* wrap-around of the vblank register. It is used by the vblank core to283* handle wrap-arounds.284*285* If set to zero the vblank core will try to guess the elapsed vblanks286* between times when the vblank interrupt is disabled through287* high-precision timestamps. That approach is suffering from small288* races and imprecision over longer time periods, hence exposing a289* hardware vblank counter is always recommended.290*291* This is the statically configured device wide maximum. The driver292* can instead choose to use a runtime configurable per-crtc value293* &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count294* must be left at zero. See drm_crtc_set_max_vblank_count() on how295* to use the per-crtc value.296*297* If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.298*/299u32 max_vblank_count;300301/** @vblank_event_list: List of vblank events */302struct list_head vblank_event_list;303304/**305* @event_lock:306*307* Protects @vblank_event_list and event delivery in308* general. See drm_send_event() and drm_send_event_locked().309*/310spinlock_t event_lock;311312/** @num_crtcs: Number of CRTCs on this device */313unsigned int num_crtcs;314315/** @mode_config: Current mode config */316struct drm_mode_config mode_config;317318/** @object_name_lock: GEM information */319struct mutex object_name_lock;320321/** @object_name_idr: GEM information */322struct idr object_name_idr;323324/** @vma_offset_manager: GEM information */325struct drm_vma_offset_manager *vma_offset_manager;326327/** @vram_mm: VRAM MM memory manager */328struct drm_vram_mm *vram_mm;329330/**331* @switch_power_state:332*333* Power state of the client.334* Used by drivers supporting the switcheroo driver.335* The state is maintained in the336* &vga_switcheroo_client_ops.set_gpu_state callback337*/338enum switch_power_state switch_power_state;339340/**341* @fb_helper:342*343* Pointer to the fbdev emulation structure.344* Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().345*/346struct drm_fb_helper *fb_helper;347348/**349* @debugfs_root:350*351* Root directory for debugfs files.352*/353struct dentry *debugfs_root;354};355356void drm_dev_set_dma_dev(struct drm_device *dev, struct device *dma_dev);357358/**359* drm_dev_dma_dev - returns the DMA device for a DRM device360* @dev: DRM device361*362* Returns the DMA device of the given DRM device. By default, this363* the DRM device's parent. See drm_dev_set_dma_dev().364*365* Returns:366* A DMA-capable device for the DRM device.367*/368static inline struct device *drm_dev_dma_dev(struct drm_device *dev)369{370if (dev->dma_dev)371return dev->dma_dev;372return dev->dev;373}374375#endif376377378