Home | History | Annotate | Line # | Download | only in drm
      1  1.11  riastrad /*	$NetBSD: drm_device.h,v 1.11 2022/10/15 15:19:28 riastradh Exp $	*/
      2   1.1  riastrad 
      3   1.1  riastrad #ifndef _DRM_DEVICE_H_
      4   1.1  riastrad #define _DRM_DEVICE_H_
      5   1.1  riastrad 
      6   1.1  riastrad #include <linux/list.h>
      7   1.1  riastrad #include <linux/kref.h>
      8   1.1  riastrad #include <linux/mutex.h>
      9   1.1  riastrad #include <linux/idr.h>
     10   1.1  riastrad 
     11   1.1  riastrad #include <drm/drm_hashtab.h>
     12   1.1  riastrad #include <drm/drm_mode_config.h>
     13   1.1  riastrad 
     14   1.2  riastrad #ifdef __NetBSD__
     15  1.11  riastrad #include <drm/drm_wait_netbsd.h>
     16   1.2  riastrad #include <dev/sysmon/sysmonvar.h>
     17   1.2  riastrad #endif
     18   1.2  riastrad 
     19   1.1  riastrad struct drm_driver;
     20   1.1  riastrad struct drm_minor;
     21   1.1  riastrad struct drm_master;
     22   1.1  riastrad struct drm_device_dma;
     23   1.1  riastrad struct drm_vblank_crtc;
     24   1.1  riastrad struct drm_sg_mem;
     25   1.1  riastrad struct drm_local_map;
     26   1.1  riastrad struct drm_vma_offset_manager;
     27   1.1  riastrad struct drm_vram_mm;
     28   1.1  riastrad struct drm_fb_helper;
     29   1.1  riastrad 
     30   1.1  riastrad struct pci_dev;
     31   1.1  riastrad struct pci_controller;
     32   1.1  riastrad 
     33   1.1  riastrad /**
     34   1.1  riastrad  * enum drm_switch_power - power state of drm device
     35   1.1  riastrad  */
     36   1.1  riastrad 
     37   1.1  riastrad enum switch_power_state {
     38   1.1  riastrad 	/** @DRM_SWITCH_POWER_ON: Power state is ON */
     39   1.1  riastrad 	DRM_SWITCH_POWER_ON = 0,
     40   1.1  riastrad 
     41   1.1  riastrad 	/** @DRM_SWITCH_POWER_OFF: Power state is OFF */
     42   1.1  riastrad 	DRM_SWITCH_POWER_OFF = 1,
     43   1.1  riastrad 
     44   1.1  riastrad 	/** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
     45   1.1  riastrad 	DRM_SWITCH_POWER_CHANGING = 2,
     46   1.1  riastrad 
     47   1.1  riastrad 	/** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
     48   1.1  riastrad 	DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
     49   1.1  riastrad };
     50   1.1  riastrad 
     51   1.1  riastrad /**
     52   1.1  riastrad  * struct drm_device - DRM device structure
     53   1.1  riastrad  *
     54   1.1  riastrad  * This structure represent a complete card that
     55   1.1  riastrad  * may contain multiple heads.
     56   1.1  riastrad  */
     57   1.1  riastrad struct drm_device {
     58   1.1  riastrad 	/**
     59   1.1  riastrad 	 * @legacy_dev_list:
     60   1.1  riastrad 	 *
     61   1.1  riastrad 	 * List of devices per driver for stealth attach cleanup
     62   1.1  riastrad 	 */
     63   1.1  riastrad 	struct list_head legacy_dev_list;
     64   1.1  riastrad 
     65   1.1  riastrad 	/** @if_version: Highest interface version set */
     66   1.1  riastrad 	int if_version;
     67   1.1  riastrad 
     68   1.1  riastrad 	/** @ref: Object ref-count */
     69   1.1  riastrad 	struct kref ref;
     70   1.1  riastrad 
     71   1.1  riastrad 	/** @dev: Device structure of bus-device */
     72   1.1  riastrad 	struct device *dev;
     73   1.1  riastrad 
     74   1.1  riastrad 	/** @driver: DRM driver managing the device */
     75   1.1  riastrad 	struct drm_driver *driver;
     76   1.1  riastrad 
     77   1.1  riastrad 	/**
     78   1.1  riastrad 	 * @dev_private:
     79   1.1  riastrad 	 *
     80   1.1  riastrad 	 * DRM driver private data. Instead of using this pointer it is
     81   1.1  riastrad 	 * recommended that drivers use drm_dev_init() and embed struct
     82   1.1  riastrad 	 * &drm_device in their larger per-device structure.
     83   1.1  riastrad 	 */
     84   1.1  riastrad 	void *dev_private;
     85   1.1  riastrad 
     86   1.1  riastrad 	/** @primary: Primary node */
     87   1.1  riastrad 	struct drm_minor *primary;
     88   1.1  riastrad 
     89   1.1  riastrad 	/** @render: Render node */
     90   1.1  riastrad 	struct drm_minor *render;
     91   1.1  riastrad 
     92   1.1  riastrad 	/**
     93   1.1  riastrad 	 * @registered:
     94   1.1  riastrad 	 *
     95   1.1  riastrad 	 * Internally used by drm_dev_register() and drm_connector_register().
     96   1.1  riastrad 	 */
     97   1.1  riastrad 	bool registered;
     98   1.1  riastrad 
     99   1.1  riastrad 	/**
    100   1.1  riastrad 	 * @master:
    101   1.1  riastrad 	 *
    102   1.1  riastrad 	 * Currently active master for this device.
    103   1.1  riastrad 	 * Protected by &master_mutex
    104   1.1  riastrad 	 */
    105   1.1  riastrad 	struct drm_master *master;
    106   1.1  riastrad 
    107   1.1  riastrad 	/**
    108   1.1  riastrad 	 * @driver_features: per-device driver features
    109   1.1  riastrad 	 *
    110   1.1  riastrad 	 * Drivers can clear specific flags here to disallow
    111   1.1  riastrad 	 * certain features on a per-device basis while still
    112   1.1  riastrad 	 * sharing a single &struct drm_driver instance across
    113   1.1  riastrad 	 * all devices.
    114   1.1  riastrad 	 */
    115   1.1  riastrad 	u32 driver_features;
    116   1.1  riastrad 
    117   1.1  riastrad 	/**
    118   1.1  riastrad 	 * @unplugged:
    119   1.1  riastrad 	 *
    120   1.1  riastrad 	 * Flag to tell if the device has been unplugged.
    121   1.1  riastrad 	 * See drm_dev_enter() and drm_dev_is_unplugged().
    122   1.1  riastrad 	 */
    123   1.1  riastrad 	bool unplugged;
    124   1.1  riastrad 
    125   1.1  riastrad 	/** @anon_inode: inode for private address-space */
    126   1.2  riastrad 	void *anon_inode;
    127   1.1  riastrad 
    128   1.1  riastrad 	/** @unique: Unique name of the device */
    129   1.1  riastrad 	char *unique;
    130   1.1  riastrad 
    131   1.1  riastrad 	/**
    132   1.1  riastrad 	 * @struct_mutex:
    133   1.1  riastrad 	 *
    134   1.1  riastrad 	 * Lock for others (not &drm_minor.master and &drm_file.is_master)
    135   1.1  riastrad 	 */
    136   1.1  riastrad 	struct mutex struct_mutex;
    137   1.1  riastrad 
    138   1.1  riastrad 	/**
    139   1.1  riastrad 	 * @master_mutex:
    140   1.1  riastrad 	 *
    141   1.1  riastrad 	 * Lock for &drm_minor.master and &drm_file.is_master
    142   1.1  riastrad 	 */
    143   1.1  riastrad 	struct mutex master_mutex;
    144   1.1  riastrad 
    145   1.1  riastrad 	/**
    146   1.1  riastrad 	 * @open_count:
    147   1.1  riastrad 	 *
    148   1.1  riastrad 	 * Usage counter for outstanding files open,
    149   1.1  riastrad 	 * protected by drm_global_mutex
    150   1.1  riastrad 	 */
    151   1.1  riastrad 	int open_count;
    152   1.1  riastrad 
    153   1.1  riastrad 	/** @filelist_mutex: Protects @filelist. */
    154   1.1  riastrad 	struct mutex filelist_mutex;
    155   1.1  riastrad 	/**
    156   1.1  riastrad 	 * @filelist:
    157   1.1  riastrad 	 *
    158   1.1  riastrad 	 * List of userspace clients, linked through &drm_file.lhead.
    159   1.1  riastrad 	 */
    160   1.1  riastrad 	struct list_head filelist;
    161   1.1  riastrad 
    162   1.1  riastrad 	/**
    163   1.1  riastrad 	 * @filelist_internal:
    164   1.1  riastrad 	 *
    165   1.1  riastrad 	 * List of open DRM files for in-kernel clients.
    166   1.1  riastrad 	 * Protected by &filelist_mutex.
    167   1.1  riastrad 	 */
    168   1.1  riastrad 	struct list_head filelist_internal;
    169   1.1  riastrad 
    170   1.1  riastrad 	/**
    171   1.1  riastrad 	 * @clientlist_mutex:
    172   1.1  riastrad 	 *
    173   1.1  riastrad 	 * Protects &clientlist access.
    174   1.1  riastrad 	 */
    175   1.1  riastrad 	struct mutex clientlist_mutex;
    176   1.1  riastrad 
    177   1.1  riastrad 	/**
    178   1.1  riastrad 	 * @clientlist:
    179   1.1  riastrad 	 *
    180   1.1  riastrad 	 * List of in-kernel clients. Protected by &clientlist_mutex.
    181   1.1  riastrad 	 */
    182   1.1  riastrad 	struct list_head clientlist;
    183   1.1  riastrad 
    184   1.1  riastrad 	/**
    185   1.1  riastrad 	 * @irq_enabled:
    186   1.1  riastrad 	 *
    187   1.1  riastrad 	 * Indicates that interrupt handling is enabled, specifically vblank
    188   1.1  riastrad 	 * handling. Drivers which don't use drm_irq_install() need to set this
    189   1.1  riastrad 	 * to true manually.
    190   1.1  riastrad 	 */
    191   1.1  riastrad 	bool irq_enabled;
    192   1.1  riastrad 
    193   1.1  riastrad 	/**
    194   1.1  riastrad 	 * @irq: Used by the drm_irq_install() and drm_irq_unistall() helpers.
    195   1.1  riastrad 	 */
    196   1.1  riastrad 	int irq;
    197   1.3  riastrad #ifdef __NetBSD__
    198   1.3  riastrad 	struct drm_bus_irq_cookie *irq_cookie;
    199   1.3  riastrad #endif
    200   1.1  riastrad 
    201   1.1  riastrad 	/**
    202   1.1  riastrad 	 * @vblank_disable_immediate:
    203   1.1  riastrad 	 *
    204   1.1  riastrad 	 * If true, vblank interrupt will be disabled immediately when the
    205   1.1  riastrad 	 * refcount drops to zero, as opposed to via the vblank disable
    206   1.1  riastrad 	 * timer.
    207   1.1  riastrad 	 *
    208   1.1  riastrad 	 * This can be set to true it the hardware has a working vblank counter
    209   1.1  riastrad 	 * with high-precision timestamping (otherwise there are races) and the
    210   1.1  riastrad 	 * driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
    211   1.1  riastrad 	 * appropriately. See also @max_vblank_count and
    212   1.1  riastrad 	 * &drm_crtc_funcs.get_vblank_counter.
    213   1.1  riastrad 	 */
    214   1.1  riastrad 	bool vblank_disable_immediate;
    215   1.1  riastrad 
    216   1.1  riastrad 	/**
    217   1.1  riastrad 	 * @vblank:
    218   1.1  riastrad 	 *
    219   1.1  riastrad 	 * Array of vblank tracking structures, one per &struct drm_crtc. For
    220   1.1  riastrad 	 * historical reasons (vblank support predates kernel modesetting) this
    221   1.1  riastrad 	 * is free-standing and not part of &struct drm_crtc itself. It must be
    222   1.1  riastrad 	 * initialized explicitly by calling drm_vblank_init().
    223   1.1  riastrad 	 */
    224   1.1  riastrad 	struct drm_vblank_crtc *vblank;
    225   1.1  riastrad 
    226   1.1  riastrad 	/**
    227   1.1  riastrad 	 * @vblank_time_lock:
    228   1.1  riastrad 	 *
    229   1.1  riastrad 	 *  Protects vblank count and time updates during vblank enable/disable
    230   1.1  riastrad 	 */
    231   1.1  riastrad 	spinlock_t vblank_time_lock;
    232   1.8  riastrad #ifndef __NetBSD__		/* merged into event_lock */
    233   1.1  riastrad 	/**
    234   1.1  riastrad 	 * @vbl_lock: Top-level vblank references lock, wraps the low-level
    235   1.1  riastrad 	 * @vblank_time_lock.
    236   1.1  riastrad 	 */
    237   1.1  riastrad 	spinlock_t vbl_lock;
    238   1.8  riastrad #endif
    239   1.1  riastrad 
    240   1.1  riastrad 	/**
    241   1.1  riastrad 	 * @max_vblank_count:
    242   1.1  riastrad 	 *
    243   1.1  riastrad 	 * Maximum value of the vblank registers. This value +1 will result in a
    244   1.1  riastrad 	 * wrap-around of the vblank register. It is used by the vblank core to
    245   1.1  riastrad 	 * handle wrap-arounds.
    246   1.1  riastrad 	 *
    247   1.1  riastrad 	 * If set to zero the vblank core will try to guess the elapsed vblanks
    248   1.1  riastrad 	 * between times when the vblank interrupt is disabled through
    249   1.1  riastrad 	 * high-precision timestamps. That approach is suffering from small
    250   1.1  riastrad 	 * races and imprecision over longer time periods, hence exposing a
    251   1.1  riastrad 	 * hardware vblank counter is always recommended.
    252   1.1  riastrad 	 *
    253   1.1  riastrad 	 * This is the statically configured device wide maximum. The driver
    254   1.1  riastrad 	 * can instead choose to use a runtime configurable per-crtc value
    255   1.1  riastrad 	 * &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
    256   1.1  riastrad 	 * must be left at zero. See drm_crtc_set_max_vblank_count() on how
    257   1.1  riastrad 	 * to use the per-crtc value.
    258   1.1  riastrad 	 *
    259   1.1  riastrad 	 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
    260   1.1  riastrad 	 */
    261   1.1  riastrad 	u32 max_vblank_count;
    262   1.1  riastrad 
    263   1.1  riastrad 	/** @vblank_event_list: List of vblank events */
    264   1.1  riastrad 	struct list_head vblank_event_list;
    265   1.1  riastrad 
    266   1.1  riastrad 	/**
    267   1.1  riastrad 	 * @event_lock:
    268   1.1  riastrad 	 *
    269   1.1  riastrad 	 * Protects @vblank_event_list and event delivery in
    270   1.1  riastrad 	 * general. See drm_send_event() and drm_send_event_locked().
    271   1.1  riastrad 	 */
    272   1.1  riastrad 	spinlock_t event_lock;
    273   1.1  riastrad 
    274   1.1  riastrad 	/** @agp: AGP data */
    275   1.1  riastrad 	struct drm_agp_head *agp;
    276   1.1  riastrad 
    277   1.1  riastrad 	/** @pdev: PCI device structure */
    278   1.1  riastrad 	struct pci_dev *pdev;
    279   1.1  riastrad 
    280   1.1  riastrad #ifdef __alpha__
    281   1.1  riastrad 	/** @hose: PCI hose, only used on ALPHA platforms. */
    282   1.1  riastrad 	struct pci_controller *hose;
    283   1.1  riastrad #endif
    284   1.3  riastrad 
    285   1.3  riastrad #ifdef __NetBSD__
    286   1.3  riastrad 	bus_space_tag_t bst;
    287   1.3  riastrad 	struct drm_bus_map *bus_maps;
    288   1.3  riastrad 	unsigned bus_nmaps;
    289   1.3  riastrad 	bus_dma_tag_t bus_dmat;	/* bus's full DMA tag, for internal use */
    290   1.3  riastrad 	bus_dma_tag_t bus_dmat32;	/* bus's 32-bit DMA tag */
    291   1.3  riastrad 	bus_dma_tag_t dmat;	/* DMA tag for driver, may be subregion */
    292   1.3  riastrad 	bool dmat_subregion_p;
    293   1.3  riastrad 	bus_addr_t dmat_subregion_min;
    294   1.3  riastrad 	bus_addr_t dmat_subregion_max;
    295  1.10  riastrad 	struct vmem *cma_pool;
    296   1.3  riastrad #endif
    297   1.3  riastrad 
    298   1.1  riastrad 	/** @num_crtcs: Number of CRTCs on this device */
    299   1.1  riastrad 	unsigned int num_crtcs;
    300   1.1  riastrad 
    301   1.1  riastrad 	/** @mode_config: Current mode config */
    302   1.1  riastrad 	struct drm_mode_config mode_config;
    303   1.1  riastrad 
    304   1.1  riastrad 	/** @object_name_lock: GEM information */
    305   1.1  riastrad 	struct mutex object_name_lock;
    306   1.1  riastrad 
    307   1.1  riastrad 	/** @object_name_idr: GEM information */
    308   1.1  riastrad 	struct idr object_name_idr;
    309   1.1  riastrad 
    310   1.1  riastrad 	/** @vma_offset_manager: GEM information */
    311   1.1  riastrad 	struct drm_vma_offset_manager *vma_offset_manager;
    312   1.1  riastrad 
    313   1.1  riastrad 	/** @vram_mm: VRAM MM memory manager */
    314   1.1  riastrad 	struct drm_vram_mm *vram_mm;
    315   1.1  riastrad 
    316   1.1  riastrad 	/**
    317   1.1  riastrad 	 * @switch_power_state:
    318   1.1  riastrad 	 *
    319   1.1  riastrad 	 * Power state of the client.
    320   1.1  riastrad 	 * Used by drivers supporting the switcheroo driver.
    321   1.1  riastrad 	 * The state is maintained in the
    322   1.1  riastrad 	 * &vga_switcheroo_client_ops.set_gpu_state callback
    323   1.1  riastrad 	 */
    324   1.1  riastrad 	enum switch_power_state switch_power_state;
    325   1.1  riastrad 
    326   1.1  riastrad 	/**
    327   1.1  riastrad 	 * @fb_helper:
    328   1.1  riastrad 	 *
    329   1.1  riastrad 	 * Pointer to the fbdev emulation structure.
    330   1.1  riastrad 	 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
    331   1.1  riastrad 	 */
    332   1.1  riastrad 	struct drm_fb_helper *fb_helper;
    333   1.1  riastrad 
    334   1.2  riastrad #ifdef __NetBSD__
    335   1.2  riastrad 	struct sysmon_pswitch sc_monitor_hotplug;
    336  1.11  riastrad 	struct mutex suspend_lock;
    337  1.11  riastrad 	drm_waitqueue_t suspend_cv;
    338  1.11  riastrad 	uint64_t active_ioctls;
    339  1.11  riastrad 	struct lwp *suspender;
    340   1.2  riastrad #endif
    341   1.2  riastrad 
    342   1.1  riastrad 	/* Everything below here is for legacy driver, never use! */
    343   1.1  riastrad 	/* private: */
    344   1.5  riastrad #if IS_ENABLED(CONFIG_DRM_LEGACY) || \
    345   1.5  riastrad     defined(__NetBSD__) /* XXX drm_vm.c / drm_cdevsw.c use this */
    346   1.1  riastrad 	/* Context handle management - linked list of context handles */
    347   1.1  riastrad 	struct list_head ctxlist;
    348   1.1  riastrad 
    349   1.1  riastrad 	/* Context handle management - mutex for &ctxlist */
    350   1.1  riastrad 	struct mutex ctxlist_mutex;
    351   1.1  riastrad 
    352   1.1  riastrad 	/* Context handle management */
    353   1.1  riastrad 	struct idr ctx_idr;
    354   1.1  riastrad 
    355   1.1  riastrad 	/* Memory management - linked list of regions */
    356   1.1  riastrad 	struct list_head maplist;
    357   1.1  riastrad 
    358   1.1  riastrad 	/* Memory management - user token hash table for maps */
    359   1.1  riastrad 	struct drm_open_hash map_hash;
    360   1.1  riastrad 
    361   1.1  riastrad 	/* Context handle management - list of vmas (for debugging) */
    362   1.1  riastrad 	struct list_head vmalist;
    363   1.1  riastrad 
    364   1.1  riastrad 	/* Optional pointer for DMA support */
    365   1.1  riastrad 	struct drm_device_dma *dma;
    366   1.1  riastrad 
    367   1.1  riastrad 	/* Context swapping flag */
    368   1.1  riastrad 	__volatile__ long context_flag;
    369   1.1  riastrad 
    370   1.1  riastrad 	/* Last current context */
    371   1.1  riastrad 	int last_context;
    372   1.1  riastrad 
    373   1.1  riastrad 	/* Lock for &buf_use and a few other things. */
    374   1.1  riastrad 	spinlock_t buf_lock;
    375   1.1  riastrad 
    376   1.1  riastrad 	/* Usage counter for buffers in use -- cannot alloc */
    377   1.1  riastrad 	int buf_use;
    378   1.1  riastrad 
    379   1.1  riastrad 	/* Buffer allocation in progress */
    380   1.1  riastrad 	atomic_t buf_alloc;
    381   1.1  riastrad 
    382   1.1  riastrad 	struct {
    383   1.1  riastrad 		int context;
    384   1.1  riastrad 		struct drm_hw_lock *lock;
    385   1.1  riastrad 	} sigdata;
    386   1.1  riastrad 
    387   1.1  riastrad 	struct drm_local_map *agp_buffer_map;
    388   1.1  riastrad 	unsigned int agp_buffer_token;
    389   1.1  riastrad 
    390   1.1  riastrad 	/* Scatter gather memory */
    391   1.1  riastrad 	struct drm_sg_mem *sg;
    392   1.1  riastrad #endif
    393   1.1  riastrad };
    394   1.1  riastrad 
    395   1.4  riastrad #ifdef __NetBSD__
    396   1.4  riastrad extern const struct cdevsw drm_cdevsw;
    397   1.6  riastrad int drm_limit_dma_space(struct drm_device *, resource_size_t, resource_size_t);
    398   1.6  riastrad int drm_guarantee_initialized(void);
    399   1.4  riastrad #endif
    400   1.4  riastrad 
    401   1.1  riastrad #endif
    402