Back to home page

OSCL-LXR

 
 

    


0001 #ifndef _DRM_DEVICE_H_
0002 #define _DRM_DEVICE_H_
0003 
0004 #include <linux/list.h>
0005 #include <linux/kref.h>
0006 #include <linux/mutex.h>
0007 #include <linux/idr.h>
0008 
0009 #include <drm/drm_legacy.h>
0010 #include <drm/drm_mode_config.h>
0011 
0012 struct drm_driver;
0013 struct drm_minor;
0014 struct drm_master;
0015 struct drm_vblank_crtc;
0016 struct drm_vma_offset_manager;
0017 struct drm_vram_mm;
0018 struct drm_fb_helper;
0019 
0020 struct inode;
0021 
0022 struct pci_dev;
0023 struct pci_controller;
0024 
0025 
0026 /**
0027  * enum switch_power_state - power state of drm device
0028  */
0029 
0030 enum switch_power_state {
0031     /** @DRM_SWITCH_POWER_ON: Power state is ON */
0032     DRM_SWITCH_POWER_ON = 0,
0033 
0034     /** @DRM_SWITCH_POWER_OFF: Power state is OFF */
0035     DRM_SWITCH_POWER_OFF = 1,
0036 
0037     /** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
0038     DRM_SWITCH_POWER_CHANGING = 2,
0039 
0040     /** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
0041     DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
0042 };
0043 
0044 /**
0045  * struct drm_device - DRM device structure
0046  *
0047  * This structure represent a complete card that
0048  * may contain multiple heads.
0049  */
0050 struct drm_device {
0051     /** @if_version: Highest interface version set */
0052     int if_version;
0053 
0054     /** @ref: Object ref-count */
0055     struct kref ref;
0056 
0057     /** @dev: Device structure of bus-device */
0058     struct device *dev;
0059 
0060     /**
0061      * @managed:
0062      *
0063      * Managed resources linked to the lifetime of this &drm_device as
0064      * tracked by @ref.
0065      */
0066     struct {
0067         /** @managed.resources: managed resources list */
0068         struct list_head resources;
0069         /** @managed.final_kfree: pointer for final kfree() call */
0070         void *final_kfree;
0071         /** @managed.lock: protects @managed.resources */
0072         spinlock_t lock;
0073     } managed;
0074 
0075     /** @driver: DRM driver managing the device */
0076     const struct drm_driver *driver;
0077 
0078     /**
0079      * @dev_private:
0080      *
0081      * DRM driver private data. This is deprecated and should be left set to
0082      * NULL.
0083      *
0084      * Instead of using this pointer it is recommended that drivers use
0085      * devm_drm_dev_alloc() and embed struct &drm_device in their larger
0086      * per-device structure.
0087      */
0088     void *dev_private;
0089 
0090     /** @primary: Primary node */
0091     struct drm_minor *primary;
0092 
0093     /** @render: Render node */
0094     struct drm_minor *render;
0095 
0096     /**
0097      * @registered:
0098      *
0099      * Internally used by drm_dev_register() and drm_connector_register().
0100      */
0101     bool registered;
0102 
0103     /**
0104      * @master:
0105      *
0106      * Currently active master for this device.
0107      * Protected by &master_mutex
0108      */
0109     struct drm_master *master;
0110 
0111     /**
0112      * @driver_features: per-device driver features
0113      *
0114      * Drivers can clear specific flags here to disallow
0115      * certain features on a per-device basis while still
0116      * sharing a single &struct drm_driver instance across
0117      * all devices.
0118      */
0119     u32 driver_features;
0120 
0121     /**
0122      * @unplugged:
0123      *
0124      * Flag to tell if the device has been unplugged.
0125      * See drm_dev_enter() and drm_dev_is_unplugged().
0126      */
0127     bool unplugged;
0128 
0129     /** @anon_inode: inode for private address-space */
0130     struct inode *anon_inode;
0131 
0132     /** @unique: Unique name of the device */
0133     char *unique;
0134 
0135     /**
0136      * @struct_mutex:
0137      *
0138      * Lock for others (not &drm_minor.master and &drm_file.is_master)
0139      *
0140      * WARNING:
0141      * Only drivers annotated with DRIVER_LEGACY should be using this.
0142      */
0143     struct mutex struct_mutex;
0144 
0145     /**
0146      * @master_mutex:
0147      *
0148      * Lock for &drm_minor.master and &drm_file.is_master
0149      */
0150     struct mutex master_mutex;
0151 
0152     /**
0153      * @open_count:
0154      *
0155      * Usage counter for outstanding files open,
0156      * protected by drm_global_mutex
0157      */
0158     atomic_t open_count;
0159 
0160     /** @filelist_mutex: Protects @filelist. */
0161     struct mutex filelist_mutex;
0162     /**
0163      * @filelist:
0164      *
0165      * List of userspace clients, linked through &drm_file.lhead.
0166      */
0167     struct list_head filelist;
0168 
0169     /**
0170      * @filelist_internal:
0171      *
0172      * List of open DRM files for in-kernel clients.
0173      * Protected by &filelist_mutex.
0174      */
0175     struct list_head filelist_internal;
0176 
0177     /**
0178      * @clientlist_mutex:
0179      *
0180      * Protects &clientlist access.
0181      */
0182     struct mutex clientlist_mutex;
0183 
0184     /**
0185      * @clientlist:
0186      *
0187      * List of in-kernel clients. Protected by &clientlist_mutex.
0188      */
0189     struct list_head clientlist;
0190 
0191     /**
0192      * @vblank_disable_immediate:
0193      *
0194      * If true, vblank interrupt will be disabled immediately when the
0195      * refcount drops to zero, as opposed to via the vblank disable
0196      * timer.
0197      *
0198      * This can be set to true it the hardware has a working vblank counter
0199      * with high-precision timestamping (otherwise there are races) and the
0200      * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
0201      * appropriately. See also @max_vblank_count and
0202      * &drm_crtc_funcs.get_vblank_counter.
0203      */
0204     bool vblank_disable_immediate;
0205 
0206     /**
0207      * @vblank:
0208      *
0209      * Array of vblank tracking structures, one per &struct drm_crtc. For
0210      * historical reasons (vblank support predates kernel modesetting) this
0211      * is free-standing and not part of &struct drm_crtc itself. It must be
0212      * initialized explicitly by calling drm_vblank_init().
0213      */
0214     struct drm_vblank_crtc *vblank;
0215 
0216     /**
0217      * @vblank_time_lock:
0218      *
0219      *  Protects vblank count and time updates during vblank enable/disable
0220      */
0221     spinlock_t vblank_time_lock;
0222     /**
0223      * @vbl_lock: Top-level vblank references lock, wraps the low-level
0224      * @vblank_time_lock.
0225      */
0226     spinlock_t vbl_lock;
0227 
0228     /**
0229      * @max_vblank_count:
0230      *
0231      * Maximum value of the vblank registers. This value +1 will result in a
0232      * wrap-around of the vblank register. It is used by the vblank core to
0233      * handle wrap-arounds.
0234      *
0235      * If set to zero the vblank core will try to guess the elapsed vblanks
0236      * between times when the vblank interrupt is disabled through
0237      * high-precision timestamps. That approach is suffering from small
0238      * races and imprecision over longer time periods, hence exposing a
0239      * hardware vblank counter is always recommended.
0240      *
0241      * This is the statically configured device wide maximum. The driver
0242      * can instead choose to use a runtime configurable per-crtc value
0243      * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
0244      * must be left at zero. See drm_crtc_set_max_vblank_count() on how
0245      * to use the per-crtc value.
0246      *
0247      * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
0248      */
0249     u32 max_vblank_count;
0250 
0251     /** @vblank_event_list: List of vblank events */
0252     struct list_head vblank_event_list;
0253 
0254     /**
0255      * @event_lock:
0256      *
0257      * Protects @vblank_event_list and event delivery in
0258      * general. See drm_send_event() and drm_send_event_locked().
0259      */
0260     spinlock_t event_lock;
0261 
0262     /** @num_crtcs: Number of CRTCs on this device */
0263     unsigned int num_crtcs;
0264 
0265     /** @mode_config: Current mode config */
0266     struct drm_mode_config mode_config;
0267 
0268     /** @object_name_lock: GEM information */
0269     struct mutex object_name_lock;
0270 
0271     /** @object_name_idr: GEM information */
0272     struct idr object_name_idr;
0273 
0274     /** @vma_offset_manager: GEM information */
0275     struct drm_vma_offset_manager *vma_offset_manager;
0276 
0277     /** @vram_mm: VRAM MM memory manager */
0278     struct drm_vram_mm *vram_mm;
0279 
0280     /**
0281      * @switch_power_state:
0282      *
0283      * Power state of the client.
0284      * Used by drivers supporting the switcheroo driver.
0285      * The state is maintained in the
0286      * &vga_switcheroo_client_ops.set_gpu_state callback
0287      */
0288     enum switch_power_state switch_power_state;
0289 
0290     /**
0291      * @fb_helper:
0292      *
0293      * Pointer to the fbdev emulation structure.
0294      * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
0295      */
0296     struct drm_fb_helper *fb_helper;
0297 
0298     /* Everything below here is for legacy driver, never use! */
0299     /* private: */
0300 #if IS_ENABLED(CONFIG_DRM_LEGACY)
0301     /* List of devices per driver for stealth attach cleanup */
0302     struct list_head legacy_dev_list;
0303 
0304 #ifdef __alpha__
0305     /** @hose: PCI hose, only used on ALPHA platforms. */
0306     struct pci_controller *hose;
0307 #endif
0308 
0309     /* AGP data */
0310     struct drm_agp_head *agp;
0311 
0312     /* Context handle management - linked list of context handles */
0313     struct list_head ctxlist;
0314 
0315     /* Context handle management - mutex for &ctxlist */
0316     struct mutex ctxlist_mutex;
0317 
0318     /* Context handle management */
0319     struct idr ctx_idr;
0320 
0321     /* Memory management - linked list of regions */
0322     struct list_head maplist;
0323 
0324     /* Memory management - user token hash table for maps */
0325     struct drm_open_hash map_hash;
0326 
0327     /* Context handle management - list of vmas (for debugging) */
0328     struct list_head vmalist;
0329 
0330     /* Optional pointer for DMA support */
0331     struct drm_device_dma *dma;
0332 
0333     /* Context swapping flag */
0334     __volatile__ long context_flag;
0335 
0336     /* Last current context */
0337     int last_context;
0338 
0339     /* Lock for &buf_use and a few other things. */
0340     spinlock_t buf_lock;
0341 
0342     /* Usage counter for buffers in use -- cannot alloc */
0343     int buf_use;
0344 
0345     /* Buffer allocation in progress */
0346     atomic_t buf_alloc;
0347 
0348     struct {
0349         int context;
0350         struct drm_hw_lock *lock;
0351     } sigdata;
0352 
0353     struct drm_local_map *agp_buffer_map;
0354     unsigned int agp_buffer_token;
0355 
0356     /* Scatter gather memory */
0357     struct drm_sg_mem *sg;
0358 
0359     /* IRQs */
0360     bool irq_enabled;
0361     int irq;
0362 #endif
0363 };
0364 
0365 #endif