2017-08-02 19:56:01 +08:00
|
|
|
#ifndef _DRM_DEVICE_H_
|
|
|
|
#define _DRM_DEVICE_H_
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/kref.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
|
|
|
|
#include <drm/drm_hashtab.h>
|
|
|
|
#include <drm/drm_mode_config.h>
|
|
|
|
|
|
|
|
struct drm_driver;
|
|
|
|
struct drm_minor;
|
|
|
|
struct drm_master;
|
|
|
|
struct drm_device_dma;
|
|
|
|
struct drm_vblank_crtc;
|
|
|
|
struct drm_sg_mem;
|
|
|
|
struct drm_local_map;
|
|
|
|
struct drm_vma_offset_manager;
|
2019-05-08 16:26:18 +08:00
|
|
|
struct drm_vram_mm;
|
2017-10-30 23:39:38 +08:00
|
|
|
struct drm_fb_helper;
|
2017-08-02 19:56:01 +08:00
|
|
|
|
|
|
|
struct inode;
|
|
|
|
|
|
|
|
struct pci_dev;
|
|
|
|
struct pci_controller;
|
|
|
|
|
2019-01-09 03:29:29 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* enum drm_switch_power - power state of drm device
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum switch_power_state {
|
|
|
|
/** @DRM_SWITCH_POWER_ON: Power state is ON */
|
|
|
|
DRM_SWITCH_POWER_ON = 0,
|
|
|
|
|
|
|
|
/** @DRM_SWITCH_POWER_OFF: Power state is OFF */
|
|
|
|
DRM_SWITCH_POWER_OFF = 1,
|
|
|
|
|
|
|
|
/** @DRM_SWITCH_POWER_CHANGING: Power state is changing */
|
|
|
|
DRM_SWITCH_POWER_CHANGING = 2,
|
|
|
|
|
|
|
|
/** @DRM_SWITCH_POWER_DYNAMIC_OFF: Suspended */
|
|
|
|
DRM_SWITCH_POWER_DYNAMIC_OFF = 3,
|
|
|
|
};
|
|
|
|
|
2017-08-02 19:56:01 +08:00
|
|
|
/**
|
2019-01-09 03:29:28 +08:00
|
|
|
* struct drm_device - DRM device structure
|
|
|
|
*
|
|
|
|
* This structure represent a complete card that
|
2017-08-02 19:56:01 +08:00
|
|
|
* may contain multiple heads.
|
|
|
|
*/
|
|
|
|
struct drm_device {
|
2019-01-09 03:29:28 +08:00
|
|
|
/**
|
|
|
|
* @legacy_dev_list:
|
|
|
|
*
|
|
|
|
* List of devices per driver for stealth attach cleanup
|
|
|
|
*/
|
|
|
|
struct list_head legacy_dev_list;
|
|
|
|
|
|
|
|
/** @if_version: Highest interface version set */
|
|
|
|
int if_version;
|
|
|
|
|
|
|
|
/** @ref: Object ref-count */
|
|
|
|
struct kref ref;
|
|
|
|
|
|
|
|
/** @dev: Device structure of bus-device */
|
|
|
|
struct device *dev;
|
|
|
|
|
drm: add managed resources tied to drm_device
We have lots of these. And the cleanup code tends to be of dubious
quality. The biggest wrong pattern is that developers use devm_, which
ties the release action to the underlying struct device, whereas
all the userspace visible stuff attached to a drm_device can long
outlive that one (e.g. after a hotunplug while userspace has open
files and mmap'ed buffers). Give people what they want, but with more
correctness.
Mostly copied from devres.c, with types adjusted to fit drm_device and
a few simplifications - I didn't (yet) copy over everything. Since
the types don't match code sharing looked like a hopeless endeavour.
For now it's only super simplified, no groups, you can't remove
actions (but kfree exists, we'll need that soon). Plus all specific to
drm_device ofc, including the logging. Which I didn't bother to make
compile-time optional, since none of the other drm logging is compile
time optional either.
One tricky bit here is the chicken&egg between allocating your
drm_device structure and initiliazing it with drm_dev_init. For
perfect onion unwinding we'd need to have the action to kfree the
allocation registered before drm_dev_init registers any of its own
release handlers. But drm_dev_init doesn't know where exactly the
drm_device is emebedded into the overall structure, and by the time it
returns it'll all be too late. And forcing drivers to be able clean up
everything except the one kzalloc is silly.
Work around this by having a very special final_kfree pointer. This
also avoids troubles with the list head possibly disappearing from
underneath us when we release all resources attached to the
drm_device.
v2: Do all the kerneldoc at the end, to avoid lots of fairly pointless
shuffling while getting everything into shape.
v3: Add static to add/del_dr (Neil)
Move typo fix to the right patch (Neil)
v4: Enforce contract for drmm_add_final_kfree:
Use ksize() to check that the drm_device is indeed contained somewhere
in the final kfree(). Because we need that or the entire managed
release logic blows up in a pile of use-after-frees. Motivated by a
discussion with Laurent.
v5: Review from Laurent:
- %zu instead of casting size_t
- header guards
- sorting of includes
- guarding of data assignment if we didn't allocate it for a NULL
pointer
- delete spurious newline
- cast void* data parameter correctly in ->release call, no idea how
this even worked before
v6: Review from Sam
- Add the kerneldoc for the managed sub-struct back in, even if it
doesn't show up in the generated html somehow.
- Explain why __always_inline.
- Fix bisectability around the final kfree() in drm_dev_relase(). This
is just interim code which will disappear again.
- Some whitespace polish.
- Add debug output when drmm_add_action or drmm_kmalloc fail.
v7: My bisectability fix wasn't up to par as noticed by smatch.
v8: Remove unecessary {} around if else
v9: Use kstrdup_const, which requires kfree_const and introducing a free_dr()
helper (Thomas).
v10: kfree_const goes boom on the plain "kmalloc" assignment, somehow
we need to wrap that in kstrdup_const() too!! Also renumber revision
log, I somehow reset it midway thruh.
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Neil Armstrong <narmstrong@baylibre.com
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200324124540.3227396-1-daniel.vetter@ffwll.ch
2020-03-24 20:45:40 +08:00
|
|
|
/**
|
|
|
|
* @managed:
|
|
|
|
*
|
|
|
|
* Managed resources linked to the lifetime of this &drm_device as
|
|
|
|
* tracked by @ref.
|
|
|
|
*/
|
|
|
|
struct {
|
|
|
|
/** @managed.resources: managed resources list */
|
|
|
|
struct list_head resources;
|
|
|
|
/** @managed.final_kfree: pointer for final kfree() call */
|
|
|
|
void *final_kfree;
|
|
|
|
/** @managed.lock: protects @managed.resources */
|
|
|
|
spinlock_t lock;
|
|
|
|
} managed;
|
|
|
|
|
2019-01-09 03:29:28 +08:00
|
|
|
/** @driver: DRM driver managing the device */
|
|
|
|
struct drm_driver *driver;
|
|
|
|
|
2019-01-12 00:40:48 +08:00
|
|
|
/**
|
|
|
|
* @dev_private:
|
|
|
|
*
|
2020-04-03 21:57:47 +08:00
|
|
|
* DRM driver private data. This is deprecated and should be left set to
|
|
|
|
* NULL.
|
|
|
|
*
|
|
|
|
* Instead of using this pointer it is recommended that drivers use
|
2020-09-02 15:26:27 +08:00
|
|
|
* devm_drm_dev_alloc() and embed struct &drm_device in their larger
|
2020-04-03 21:57:47 +08:00
|
|
|
* per-device structure.
|
2019-01-12 00:40:48 +08:00
|
|
|
*/
|
2019-01-09 03:29:28 +08:00
|
|
|
void *dev_private;
|
|
|
|
|
|
|
|
/** @primary: Primary node */
|
|
|
|
struct drm_minor *primary;
|
|
|
|
|
|
|
|
/** @render: Render node */
|
|
|
|
struct drm_minor *render;
|
|
|
|
|
2019-01-12 00:40:48 +08:00
|
|
|
/**
|
|
|
|
* @registered:
|
|
|
|
*
|
|
|
|
* Internally used by drm_dev_register() and drm_connector_register().
|
|
|
|
*/
|
2017-08-02 19:56:01 +08:00
|
|
|
bool registered;
|
|
|
|
|
2019-01-09 03:29:28 +08:00
|
|
|
/**
|
|
|
|
* @master:
|
|
|
|
*
|
|
|
|
* Currently active master for this device.
|
|
|
|
* Protected by &master_mutex
|
|
|
|
*/
|
2017-08-02 19:56:01 +08:00
|
|
|
struct drm_master *master;
|
|
|
|
|
2018-09-13 21:16:21 +08:00
|
|
|
/**
|
|
|
|
* @driver_features: per-device driver features
|
|
|
|
*
|
|
|
|
* Drivers can clear specific flags here to disallow
|
|
|
|
* certain features on a per-device basis while still
|
|
|
|
* sharing a single &struct drm_driver instance across
|
|
|
|
* all devices.
|
|
|
|
*/
|
|
|
|
u32 driver_features;
|
|
|
|
|
2018-03-28 15:38:35 +08:00
|
|
|
/**
|
|
|
|
* @unplugged:
|
|
|
|
*
|
|
|
|
* Flag to tell if the device has been unplugged.
|
|
|
|
* See drm_dev_enter() and drm_dev_is_unplugged().
|
|
|
|
*/
|
|
|
|
bool unplugged;
|
|
|
|
|
2019-01-09 03:29:28 +08:00
|
|
|
/** @anon_inode: inode for private address-space */
|
|
|
|
struct inode *anon_inode;
|
|
|
|
|
|
|
|
/** @unique: Unique name of the device */
|
|
|
|
char *unique;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @struct_mutex:
|
|
|
|
*
|
|
|
|
* Lock for others (not &drm_minor.master and &drm_file.is_master)
|
2020-05-15 17:50:45 +08:00
|
|
|
*
|
|
|
|
* WARNING:
|
|
|
|
* Only drivers annotated with DRIVER_LEGACY should be using this.
|
2019-01-09 03:29:28 +08:00
|
|
|
*/
|
|
|
|
struct mutex struct_mutex;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @master_mutex:
|
|
|
|
*
|
|
|
|
* Lock for &drm_minor.master and &drm_file.is_master
|
|
|
|
*/
|
|
|
|
struct mutex master_mutex;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @open_count:
|
|
|
|
*
|
|
|
|
* Usage counter for outstanding files open,
|
|
|
|
* protected by drm_global_mutex
|
|
|
|
*/
|
2020-01-24 21:01:07 +08:00
|
|
|
atomic_t open_count;
|
2019-01-09 03:29:28 +08:00
|
|
|
|
2019-01-12 00:40:48 +08:00
|
|
|
/** @filelist_mutex: Protects @filelist. */
|
2017-08-02 19:56:01 +08:00
|
|
|
struct mutex filelist_mutex;
|
2019-01-12 00:40:48 +08:00
|
|
|
/**
|
|
|
|
* @filelist:
|
|
|
|
*
|
|
|
|
* List of userspace clients, linked through &drm_file.lhead.
|
|
|
|
*/
|
2017-08-02 19:56:01 +08:00
|
|
|
struct list_head filelist;
|
|
|
|
|
2018-07-04 00:03:47 +08:00
|
|
|
/**
|
|
|
|
* @filelist_internal:
|
|
|
|
*
|
2019-01-09 03:29:28 +08:00
|
|
|
* List of open DRM files for in-kernel clients.
|
|
|
|
* Protected by &filelist_mutex.
|
2018-07-04 00:03:47 +08:00
|
|
|
*/
|
|
|
|
struct list_head filelist_internal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @clientlist_mutex:
|
|
|
|
*
|
2019-01-09 03:29:28 +08:00
|
|
|
* Protects &clientlist access.
|
2018-07-04 00:03:47 +08:00
|
|
|
*/
|
|
|
|
struct mutex clientlist_mutex;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @clientlist:
|
|
|
|
*
|
2019-01-09 03:29:28 +08:00
|
|
|
* List of in-kernel clients. Protected by &clientlist_mutex.
|
2018-07-04 00:03:47 +08:00
|
|
|
*/
|
|
|
|
struct list_head clientlist;
|
|
|
|
|
2017-08-02 19:56:01 +08:00
|
|
|
/**
|
|
|
|
* @irq_enabled:
|
|
|
|
*
|
|
|
|
* Indicates that interrupt handling is enabled, specifically vblank
|
|
|
|
* handling. Drivers which don't use drm_irq_install() need to set this
|
|
|
|
* to true manually.
|
|
|
|
*/
|
|
|
|
bool irq_enabled;
|
2019-01-12 00:40:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @irq: Used by the drm_irq_install() and drm_irq_unistall() helpers.
|
|
|
|
*/
|
2017-08-02 19:56:01 +08:00
|
|
|
int irq;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @vblank_disable_immediate:
|
|
|
|
*
|
|
|
|
* If true, vblank interrupt will be disabled immediately when the
|
|
|
|
* refcount drops to zero, as opposed to via the vblank disable
|
|
|
|
* timer.
|
|
|
|
*
|
|
|
|
* This can be set to true it the hardware has a working vblank counter
|
|
|
|
* with high-precision timestamping (otherwise there are races) and the
|
|
|
|
* driver uses drm_crtc_vblank_on() and drm_crtc_vblank_off()
|
|
|
|
* appropriately. See also @max_vblank_count and
|
|
|
|
* &drm_crtc_funcs.get_vblank_counter.
|
|
|
|
*/
|
|
|
|
bool vblank_disable_immediate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @vblank:
|
|
|
|
*
|
|
|
|
* Array of vblank tracking structures, one per &struct drm_crtc. For
|
|
|
|
* historical reasons (vblank support predates kernel modesetting) this
|
|
|
|
* is free-standing and not part of &struct drm_crtc itself. It must be
|
|
|
|
* initialized explicitly by calling drm_vblank_init().
|
|
|
|
*/
|
|
|
|
struct drm_vblank_crtc *vblank;
|
|
|
|
|
2019-01-09 03:29:28 +08:00
|
|
|
/**
|
|
|
|
* @vblank_time_lock:
|
|
|
|
*
|
|
|
|
* Protects vblank count and time updates during vblank enable/disable
|
|
|
|
*/
|
|
|
|
spinlock_t vblank_time_lock;
|
2019-01-12 00:40:48 +08:00
|
|
|
/**
|
|
|
|
* @vbl_lock: Top-level vblank references lock, wraps the low-level
|
|
|
|
* @vblank_time_lock.
|
|
|
|
*/
|
2017-08-02 19:56:01 +08:00
|
|
|
spinlock_t vbl_lock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @max_vblank_count:
|
|
|
|
*
|
|
|
|
* Maximum value of the vblank registers. This value +1 will result in a
|
|
|
|
* wrap-around of the vblank register. It is used by the vblank core to
|
|
|
|
* handle wrap-arounds.
|
|
|
|
*
|
|
|
|
* If set to zero the vblank core will try to guess the elapsed vblanks
|
|
|
|
* between times when the vblank interrupt is disabled through
|
|
|
|
* high-precision timestamps. That approach is suffering from small
|
|
|
|
* races and imprecision over longer time periods, hence exposing a
|
|
|
|
* hardware vblank counter is always recommended.
|
|
|
|
*
|
2018-11-28 02:20:04 +08:00
|
|
|
* This is the statically configured device wide maximum. The driver
|
|
|
|
* can instead choose to use a runtime configurable per-crtc value
|
|
|
|
* &drm_vblank_crtc.max_vblank_count, in which case @max_vblank_count
|
|
|
|
* must be left at zero. See drm_crtc_set_max_vblank_count() on how
|
|
|
|
* to use the per-crtc value.
|
|
|
|
*
|
2019-01-12 00:40:48 +08:00
|
|
|
* If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
|
2017-08-02 19:56:01 +08:00
|
|
|
*/
|
2019-01-09 03:29:28 +08:00
|
|
|
u32 max_vblank_count;
|
|
|
|
|
|
|
|
/** @vblank_event_list: List of vblank events */
|
2017-08-02 19:56:01 +08:00
|
|
|
struct list_head vblank_event_list;
|
2019-01-12 00:40:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @event_lock:
|
|
|
|
*
|
|
|
|
* Protects @vblank_event_list and event delivery in
|
|
|
|
* general. See drm_send_event() and drm_send_event_locked().
|
|
|
|
*/
|
2017-08-02 19:56:01 +08:00
|
|
|
spinlock_t event_lock;
|
|
|
|
|
2019-01-09 03:29:28 +08:00
|
|
|
/** @agp: AGP data */
|
|
|
|
struct drm_agp_head *agp;
|
2017-08-02 19:56:01 +08:00
|
|
|
|
2019-01-09 03:29:28 +08:00
|
|
|
/** @pdev: PCI device structure */
|
|
|
|
struct pci_dev *pdev;
|
2017-08-02 19:56:01 +08:00
|
|
|
|
|
|
|
#ifdef __alpha__
|
2019-01-12 00:40:48 +08:00
|
|
|
/** @hose: PCI hose, only used on ALPHA platforms. */
|
2017-08-02 19:56:01 +08:00
|
|
|
struct pci_controller *hose;
|
|
|
|
#endif
|
2019-01-09 03:29:28 +08:00
|
|
|
/** @num_crtcs: Number of CRTCs on this device */
|
|
|
|
unsigned int num_crtcs;
|
2017-08-02 19:56:01 +08:00
|
|
|
|
2019-01-09 03:29:28 +08:00
|
|
|
/** @mode_config: Current mode config */
|
|
|
|
struct drm_mode_config mode_config;
|
2017-08-02 19:56:01 +08:00
|
|
|
|
2019-01-09 03:29:28 +08:00
|
|
|
/** @object_name_lock: GEM information */
|
2017-08-02 19:56:01 +08:00
|
|
|
struct mutex object_name_lock;
|
2019-01-09 03:29:28 +08:00
|
|
|
|
|
|
|
/** @object_name_idr: GEM information */
|
2017-08-02 19:56:01 +08:00
|
|
|
struct idr object_name_idr;
|
2019-01-09 03:29:28 +08:00
|
|
|
|
|
|
|
/** @vma_offset_manager: GEM information */
|
2017-08-02 19:56:01 +08:00
|
|
|
struct drm_vma_offset_manager *vma_offset_manager;
|
2019-01-09 03:29:28 +08:00
|
|
|
|
2019-05-08 16:26:18 +08:00
|
|
|
/** @vram_mm: VRAM MM memory manager */
|
|
|
|
struct drm_vram_mm *vram_mm;
|
|
|
|
|
2019-01-09 03:29:29 +08:00
|
|
|
/**
|
|
|
|
* @switch_power_state:
|
|
|
|
*
|
|
|
|
* Power state of the client.
|
|
|
|
* Used by drivers supporting the switcheroo driver.
|
|
|
|
* The state is maintained in the
|
|
|
|
* &vga_switcheroo_client_ops.set_gpu_state callback
|
|
|
|
*/
|
|
|
|
enum switch_power_state switch_power_state;
|
2017-10-30 23:39:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @fb_helper:
|
|
|
|
*
|
|
|
|
* Pointer to the fbdev emulation structure.
|
|
|
|
* Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
|
|
|
|
*/
|
|
|
|
struct drm_fb_helper *fb_helper;
|
2019-01-12 00:40:48 +08:00
|
|
|
|
|
|
|
/* Everything below here is for legacy driver, never use! */
|
|
|
|
/* private: */
|
2019-04-23 07:56:01 +08:00
|
|
|
#if IS_ENABLED(CONFIG_DRM_LEGACY)
|
2019-01-12 00:40:48 +08:00
|
|
|
/* Context handle management - linked list of context handles */
|
|
|
|
struct list_head ctxlist;
|
|
|
|
|
|
|
|
/* Context handle management - mutex for &ctxlist */
|
|
|
|
struct mutex ctxlist_mutex;
|
|
|
|
|
|
|
|
/* Context handle management */
|
|
|
|
struct idr ctx_idr;
|
|
|
|
|
|
|
|
/* Memory management - linked list of regions */
|
|
|
|
struct list_head maplist;
|
|
|
|
|
|
|
|
/* Memory management - user token hash table for maps */
|
|
|
|
struct drm_open_hash map_hash;
|
|
|
|
|
|
|
|
/* Context handle management - list of vmas (for debugging) */
|
|
|
|
struct list_head vmalist;
|
|
|
|
|
|
|
|
/* Optional pointer for DMA support */
|
|
|
|
struct drm_device_dma *dma;
|
|
|
|
|
|
|
|
/* Context swapping flag */
|
|
|
|
__volatile__ long context_flag;
|
|
|
|
|
|
|
|
/* Last current context */
|
|
|
|
int last_context;
|
|
|
|
|
|
|
|
/* Lock for &buf_use and a few other things. */
|
|
|
|
spinlock_t buf_lock;
|
|
|
|
|
|
|
|
/* Usage counter for buffers in use -- cannot alloc */
|
|
|
|
int buf_use;
|
|
|
|
|
|
|
|
/* Buffer allocation in progress */
|
|
|
|
atomic_t buf_alloc;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int context;
|
|
|
|
struct drm_hw_lock *lock;
|
|
|
|
} sigdata;
|
|
|
|
|
|
|
|
struct drm_local_map *agp_buffer_map;
|
|
|
|
unsigned int agp_buffer_token;
|
|
|
|
|
|
|
|
/* Scatter gather memory */
|
|
|
|
struct drm_sg_mem *sg;
|
2019-04-23 07:56:01 +08:00
|
|
|
#endif
|
2017-08-02 19:56:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|