Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
0003  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
0004  * Copyright (c) 2009-2010, Code Aurora Forum.
0005  * Copyright 2016 Intel Corp.
0006  *
0007  * Permission is hereby granted, free of charge, to any person obtaining a
0008  * copy of this software and associated documentation files (the "Software"),
0009  * to deal in the Software without restriction, including without limitation
0010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0011  * and/or sell copies of the Software, and to permit persons to whom the
0012  * Software is furnished to do so, subject to the following conditions:
0013  *
0014  * The above copyright notice and this permission notice (including the next
0015  * paragraph) shall be included in all copies or substantial portions of the
0016  * Software.
0017  *
0018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0021  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0022  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0023  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0024  * OTHER DEALINGS IN THE SOFTWARE.
0025  */
0026 
0027 #ifndef _DRM_DRV_H_
0028 #define _DRM_DRV_H_
0029 
0030 #include <linux/list.h>
0031 #include <linux/irqreturn.h>
0032 
0033 #include <drm/drm_device.h>
0034 
0035 struct drm_file;
0036 struct drm_gem_object;
0037 struct drm_master;
0038 struct drm_minor;
0039 struct dma_buf;
0040 struct dma_buf_attachment;
0041 struct drm_display_mode;
0042 struct drm_mode_create_dumb;
0043 struct drm_printer;
0044 struct sg_table;
0045 
0046 /**
0047  * enum drm_driver_feature - feature flags
0048  *
0049  * See &drm_driver.driver_features, drm_device.driver_features and
0050  * drm_core_check_feature().
0051  */
0052 enum drm_driver_feature {
0053     /**
0054      * @DRIVER_GEM:
0055      *
0056      * Driver use the GEM memory manager. This should be set for all modern
0057      * drivers.
0058      */
0059     DRIVER_GEM          = BIT(0),
0060     /**
0061      * @DRIVER_MODESET:
0062      *
0063      * Driver supports mode setting interfaces (KMS).
0064      */
0065     DRIVER_MODESET          = BIT(1),
0066     /**
0067      * @DRIVER_RENDER:
0068      *
0069      * Driver supports dedicated render nodes. See also the :ref:`section on
0070      * render nodes <drm_render_node>` for details.
0071      */
0072     DRIVER_RENDER           = BIT(3),
0073     /**
0074      * @DRIVER_ATOMIC:
0075      *
0076      * Driver supports the full atomic modesetting userspace API. Drivers
0077      * which only use atomic internally, but do not support the full
0078      * userspace API (e.g. not all properties converted to atomic, or
0079      * multi-plane updates are not guaranteed to be tear-free) should not
0080      * set this flag.
0081      */
0082     DRIVER_ATOMIC           = BIT(4),
0083     /**
0084      * @DRIVER_SYNCOBJ:
0085      *
0086      * Driver supports &drm_syncobj for explicit synchronization of command
0087      * submission.
0088      */
0089     DRIVER_SYNCOBJ                  = BIT(5),
0090     /**
0091      * @DRIVER_SYNCOBJ_TIMELINE:
0092      *
0093      * Driver supports the timeline flavor of &drm_syncobj for explicit
0094      * synchronization of command submission.
0095      */
0096     DRIVER_SYNCOBJ_TIMELINE         = BIT(6),
0097 
0098     /* IMPORTANT: Below are all the legacy flags, add new ones above. */
0099 
0100     /**
0101      * @DRIVER_USE_AGP:
0102      *
0103      * Set up DRM AGP support, see drm_agp_init(), the DRM core will manage
0104      * AGP resources. New drivers don't need this.
0105      */
0106     DRIVER_USE_AGP          = BIT(25),
0107     /**
0108      * @DRIVER_LEGACY:
0109      *
0110      * Denote a legacy driver using shadow attach. Do not use.
0111      */
0112     DRIVER_LEGACY           = BIT(26),
0113     /**
0114      * @DRIVER_PCI_DMA:
0115      *
0116      * Driver is capable of PCI DMA, mapping of PCI DMA buffers to userspace
0117      * will be enabled. Only for legacy drivers. Do not use.
0118      */
0119     DRIVER_PCI_DMA          = BIT(27),
0120     /**
0121      * @DRIVER_SG:
0122      *
0123      * Driver can perform scatter/gather DMA, allocation and mapping of
0124      * scatter/gather buffers will be enabled. Only for legacy drivers. Do
0125      * not use.
0126      */
0127     DRIVER_SG           = BIT(28),
0128 
0129     /**
0130      * @DRIVER_HAVE_DMA:
0131      *
0132      * Driver supports DMA, the userspace DMA API will be supported. Only
0133      * for legacy drivers. Do not use.
0134      */
0135     DRIVER_HAVE_DMA         = BIT(29),
0136     /**
0137      * @DRIVER_HAVE_IRQ:
0138      *
0139      * Legacy irq support. Only for legacy drivers. Do not use.
0140      */
0141     DRIVER_HAVE_IRQ         = BIT(30),
0142     /**
0143      * @DRIVER_KMS_LEGACY_CONTEXT:
0144      *
0145      * Used only by nouveau for backwards compatibility with existing
0146      * userspace.  Do not use.
0147      */
0148     DRIVER_KMS_LEGACY_CONTEXT   = BIT(31),
0149 };
0150 
0151 /**
0152  * struct drm_driver - DRM driver structure
0153  *
0154  * This structure represent the common code for a family of cards. There will be
0155  * one &struct drm_device for each card present in this family. It contains lots
0156  * of vfunc entries, and a pile of those probably should be moved to more
0157  * appropriate places like &drm_mode_config_funcs or into a new operations
0158  * structure for GEM drivers.
0159  */
0160 struct drm_driver {
0161     /**
0162      * @load:
0163      *
0164      * Backward-compatible driver callback to complete initialization steps
0165      * after the driver is registered.  For this reason, may suffer from
0166      * race conditions and its use is deprecated for new drivers.  It is
0167      * therefore only supported for existing drivers not yet converted to
0168      * the new scheme.  See devm_drm_dev_alloc() and drm_dev_register() for
0169      * proper and race-free way to set up a &struct drm_device.
0170      *
0171      * This is deprecated, do not use!
0172      *
0173      * Returns:
0174      *
0175      * Zero on success, non-zero value on failure.
0176      */
0177     int (*load) (struct drm_device *, unsigned long flags);
0178 
0179     /**
0180      * @open:
0181      *
0182      * Driver callback when a new &struct drm_file is opened. Useful for
0183      * setting up driver-private data structures like buffer allocators,
0184      * execution contexts or similar things. Such driver-private resources
0185      * must be released again in @postclose.
0186      *
0187      * Since the display/modeset side of DRM can only be owned by exactly
0188      * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
0189      * there should never be a need to set up any modeset related resources
0190      * in this callback. Doing so would be a driver design bug.
0191      *
0192      * Returns:
0193      *
0194      * 0 on success, a negative error code on failure, which will be
0195      * promoted to userspace as the result of the open() system call.
0196      */
0197     int (*open) (struct drm_device *, struct drm_file *);
0198 
0199     /**
0200      * @postclose:
0201      *
0202      * One of the driver callbacks when a new &struct drm_file is closed.
0203      * Useful for tearing down driver-private data structures allocated in
0204      * @open like buffer allocators, execution contexts or similar things.
0205      *
0206      * Since the display/modeset side of DRM can only be owned by exactly
0207      * one &struct drm_file (see &drm_file.is_master and &drm_device.master)
0208      * there should never be a need to tear down any modeset related
0209      * resources in this callback. Doing so would be a driver design bug.
0210      */
0211     void (*postclose) (struct drm_device *, struct drm_file *);
0212 
0213     /**
0214      * @lastclose:
0215      *
0216      * Called when the last &struct drm_file has been closed and there's
0217      * currently no userspace client for the &struct drm_device.
0218      *
0219      * Modern drivers should only use this to force-restore the fbdev
0220      * framebuffer using drm_fb_helper_restore_fbdev_mode_unlocked().
0221      * Anything else would indicate there's something seriously wrong.
0222      * Modern drivers can also use this to execute delayed power switching
0223      * state changes, e.g. in conjunction with the :ref:`vga_switcheroo`
0224      * infrastructure.
0225      *
0226      * This is called after @postclose hook has been called.
0227      *
0228      * NOTE:
0229      *
0230      * All legacy drivers use this callback to de-initialize the hardware.
0231      * This is purely because of the shadow-attach model, where the DRM
0232      * kernel driver does not really own the hardware. Instead ownershipe is
0233      * handled with the help of userspace through an inheritedly racy dance
0234      * to set/unset the VT into raw mode.
0235      *
0236      * Legacy drivers initialize the hardware in the @firstopen callback,
0237      * which isn't even called for modern drivers.
0238      */
0239     void (*lastclose) (struct drm_device *);
0240 
0241     /**
0242      * @unload:
0243      *
0244      * Reverse the effects of the driver load callback.  Ideally,
0245      * the clean up performed by the driver should happen in the
0246      * reverse order of the initialization.  Similarly to the load
0247      * hook, this handler is deprecated and its usage should be
0248      * dropped in favor of an open-coded teardown function at the
0249      * driver layer.  See drm_dev_unregister() and drm_dev_put()
0250      * for the proper way to remove a &struct drm_device.
0251      *
0252      * The unload() hook is called right after unregistering
0253      * the device.
0254      *
0255      */
0256     void (*unload) (struct drm_device *);
0257 
0258     /**
0259      * @release:
0260      *
0261      * Optional callback for destroying device data after the final
0262      * reference is released, i.e. the device is being destroyed.
0263      *
0264      * This is deprecated, clean up all memory allocations associated with a
0265      * &drm_device using drmm_add_action(), drmm_kmalloc() and related
0266      * managed resources functions.
0267      */
0268     void (*release) (struct drm_device *);
0269 
0270     /**
0271      * @master_set:
0272      *
0273      * Called whenever the minor master is set. Only used by vmwgfx.
0274      */
0275     void (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
0276                bool from_open);
0277     /**
0278      * @master_drop:
0279      *
0280      * Called whenever the minor master is dropped. Only used by vmwgfx.
0281      */
0282     void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
0283 
0284     /**
0285      * @debugfs_init:
0286      *
0287      * Allows drivers to create driver-specific debugfs files.
0288      */
0289     void (*debugfs_init)(struct drm_minor *minor);
0290 
0291     /**
0292      * @gem_create_object: constructor for gem objects
0293      *
0294      * Hook for allocating the GEM object struct, for use by the CMA
0295      * and SHMEM GEM helpers. Returns a GEM object on success, or an
0296      * ERR_PTR()-encoded error code otherwise.
0297      */
0298     struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
0299                             size_t size);
0300 
0301     /**
0302      * @prime_handle_to_fd:
0303      *
0304      * Main PRIME export function. Should be implemented with
0305      * drm_gem_prime_handle_to_fd() for GEM based drivers.
0306      *
0307      * For an in-depth discussion see :ref:`PRIME buffer sharing
0308      * documentation <prime_buffer_sharing>`.
0309      */
0310     int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
0311                 uint32_t handle, uint32_t flags, int *prime_fd);
0312     /**
0313      * @prime_fd_to_handle:
0314      *
0315      * Main PRIME import function. Should be implemented with
0316      * drm_gem_prime_fd_to_handle() for GEM based drivers.
0317      *
0318      * For an in-depth discussion see :ref:`PRIME buffer sharing
0319      * documentation <prime_buffer_sharing>`.
0320      */
0321     int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
0322                 int prime_fd, uint32_t *handle);
0323 
0324     /**
0325      * @gem_prime_import:
0326      *
0327      * Import hook for GEM drivers.
0328      *
0329      * This defaults to drm_gem_prime_import() if not set.
0330      */
0331     struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
0332                 struct dma_buf *dma_buf);
0333     /**
0334      * @gem_prime_import_sg_table:
0335      *
0336      * Optional hook used by the PRIME helper functions
0337      * drm_gem_prime_import() respectively drm_gem_prime_import_dev().
0338      */
0339     struct drm_gem_object *(*gem_prime_import_sg_table)(
0340                 struct drm_device *dev,
0341                 struct dma_buf_attachment *attach,
0342                 struct sg_table *sgt);
0343     /**
0344      * @gem_prime_mmap:
0345      *
0346      * mmap hook for GEM drivers, used to implement dma-buf mmap in the
0347      * PRIME helpers.
0348      *
0349      * This hook only exists for historical reasons. Drivers must use
0350      * drm_gem_prime_mmap() to implement it.
0351      *
0352      * FIXME: Convert all drivers to implement mmap in struct
0353      * &drm_gem_object_funcs and inline drm_gem_prime_mmap() into
0354      * its callers. This hook should be removed afterwards.
0355      */
0356     int (*gem_prime_mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma);
0357 
0358     /**
0359      * @dumb_create:
0360      *
0361      * This creates a new dumb buffer in the driver's backing storage manager (GEM,
0362      * TTM or something else entirely) and returns the resulting buffer handle. This
0363      * handle can then be wrapped up into a framebuffer modeset object.
0364      *
0365      * Note that userspace is not allowed to use such objects for render
0366      * acceleration - drivers must create their own private ioctls for such a use
0367      * case.
0368      *
0369      * Width, height and depth are specified in the &drm_mode_create_dumb
0370      * argument. The callback needs to fill the handle, pitch and size for
0371      * the created buffer.
0372      *
0373      * Called by the user via ioctl.
0374      *
0375      * Returns:
0376      *
0377      * Zero on success, negative errno on failure.
0378      */
0379     int (*dumb_create)(struct drm_file *file_priv,
0380                struct drm_device *dev,
0381                struct drm_mode_create_dumb *args);
0382     /**
0383      * @dumb_map_offset:
0384      *
0385      * Allocate an offset in the drm device node's address space to be able to
0386      * memory map a dumb buffer.
0387      *
0388      * The default implementation is drm_gem_create_mmap_offset(). GEM based
0389      * drivers must not overwrite this.
0390      *
0391      * Called by the user via ioctl.
0392      *
0393      * Returns:
0394      *
0395      * Zero on success, negative errno on failure.
0396      */
0397     int (*dumb_map_offset)(struct drm_file *file_priv,
0398                    struct drm_device *dev, uint32_t handle,
0399                    uint64_t *offset);
0400     /**
0401      * @dumb_destroy:
0402      *
0403      * This destroys the userspace handle for the given dumb backing storage buffer.
0404      * Since buffer objects must be reference counted in the kernel a buffer object
0405      * won't be immediately freed if a framebuffer modeset object still uses it.
0406      *
0407      * Called by the user via ioctl.
0408      *
0409      * The default implementation is drm_gem_dumb_destroy(). GEM based drivers
0410      * must not overwrite this.
0411      *
0412      * Returns:
0413      *
0414      * Zero on success, negative errno on failure.
0415      */
0416     int (*dumb_destroy)(struct drm_file *file_priv,
0417                 struct drm_device *dev,
0418                 uint32_t handle);
0419 
0420     /** @major: driver major number */
0421     int major;
0422     /** @minor: driver minor number */
0423     int minor;
0424     /** @patchlevel: driver patch level */
0425     int patchlevel;
0426     /** @name: driver name */
0427     char *name;
0428     /** @desc: driver description */
0429     char *desc;
0430     /** @date: driver date */
0431     char *date;
0432 
0433     /**
0434      * @driver_features:
0435      * Driver features, see &enum drm_driver_feature. Drivers can disable
0436      * some features on a per-instance basis using
0437      * &drm_device.driver_features.
0438      */
0439     u32 driver_features;
0440 
0441     /**
0442      * @ioctls:
0443      *
0444      * Array of driver-private IOCTL description entries. See the chapter on
0445      * :ref:`IOCTL support in the userland interfaces
0446      * chapter<drm_driver_ioctl>` for the full details.
0447      */
0448 
0449     const struct drm_ioctl_desc *ioctls;
0450     /** @num_ioctls: Number of entries in @ioctls. */
0451     int num_ioctls;
0452 
0453     /**
0454      * @fops:
0455      *
0456      * File operations for the DRM device node. See the discussion in
0457      * :ref:`file operations<drm_driver_fops>` for in-depth coverage and
0458      * some examples.
0459      */
0460     const struct file_operations *fops;
0461 
0462 #ifdef CONFIG_DRM_LEGACY
0463     /* Everything below here is for legacy driver, never use! */
0464     /* private: */
0465 
0466     int (*firstopen) (struct drm_device *);
0467     void (*preclose) (struct drm_device *, struct drm_file *file_priv);
0468     int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
0469     int (*dma_quiescent) (struct drm_device *);
0470     int (*context_dtor) (struct drm_device *dev, int context);
0471     irqreturn_t (*irq_handler)(int irq, void *arg);
0472     void (*irq_preinstall)(struct drm_device *dev);
0473     int (*irq_postinstall)(struct drm_device *dev);
0474     void (*irq_uninstall)(struct drm_device *dev);
0475     u32 (*get_vblank_counter)(struct drm_device *dev, unsigned int pipe);
0476     int (*enable_vblank)(struct drm_device *dev, unsigned int pipe);
0477     void (*disable_vblank)(struct drm_device *dev, unsigned int pipe);
0478     int dev_priv_size;
0479 #endif
0480 };
0481 
0482 void *__devm_drm_dev_alloc(struct device *parent,
0483                const struct drm_driver *driver,
0484                size_t size, size_t offset);
0485 
0486 /**
0487  * devm_drm_dev_alloc - Resource managed allocation of a &drm_device instance
0488  * @parent: Parent device object
0489  * @driver: DRM driver
0490  * @type: the type of the struct which contains struct &drm_device
0491  * @member: the name of the &drm_device within @type.
0492  *
0493  * This allocates and initialize a new DRM device. No device registration is done.
0494  * Call drm_dev_register() to advertice the device to user space and register it
0495  * with other core subsystems. This should be done last in the device
0496  * initialization sequence to make sure userspace can't access an inconsistent
0497  * state.
0498  *
0499  * The initial ref-count of the object is 1. Use drm_dev_get() and
0500  * drm_dev_put() to take and drop further ref-counts.
0501  *
0502  * It is recommended that drivers embed &struct drm_device into their own device
0503  * structure.
0504  *
0505  * Note that this manages the lifetime of the resulting &drm_device
0506  * automatically using devres. The DRM device initialized with this function is
0507  * automatically put on driver detach using drm_dev_put().
0508  *
0509  * RETURNS:
0510  * Pointer to new DRM device, or ERR_PTR on failure.
0511  */
0512 #define devm_drm_dev_alloc(parent, driver, type, member) \
0513     ((type *) __devm_drm_dev_alloc(parent, driver, sizeof(type), \
0514                        offsetof(type, member)))
0515 
0516 struct drm_device *drm_dev_alloc(const struct drm_driver *driver,
0517                  struct device *parent);
0518 int drm_dev_register(struct drm_device *dev, unsigned long flags);
0519 void drm_dev_unregister(struct drm_device *dev);
0520 
0521 void drm_dev_get(struct drm_device *dev);
0522 void drm_dev_put(struct drm_device *dev);
0523 void drm_put_dev(struct drm_device *dev);
0524 bool drm_dev_enter(struct drm_device *dev, int *idx);
0525 void drm_dev_exit(int idx);
0526 void drm_dev_unplug(struct drm_device *dev);
0527 
0528 /**
0529  * drm_dev_is_unplugged - is a DRM device unplugged
0530  * @dev: DRM device
0531  *
0532  * This function can be called to check whether a hotpluggable is unplugged.
0533  * Unplugging itself is singalled through drm_dev_unplug(). If a device is
0534  * unplugged, these two functions guarantee that any store before calling
0535  * drm_dev_unplug() is visible to callers of this function after it completes
0536  *
0537  * WARNING: This function fundamentally races against drm_dev_unplug(). It is
0538  * recommended that drivers instead use the underlying drm_dev_enter() and
0539  * drm_dev_exit() function pairs.
0540  */
0541 static inline bool drm_dev_is_unplugged(struct drm_device *dev)
0542 {
0543     int idx;
0544 
0545     if (drm_dev_enter(dev, &idx)) {
0546         drm_dev_exit(idx);
0547         return false;
0548     }
0549 
0550     return true;
0551 }
0552 
0553 /**
0554  * drm_core_check_all_features - check driver feature flags mask
0555  * @dev: DRM device to check
0556  * @features: feature flag(s) mask
0557  *
0558  * This checks @dev for driver features, see &drm_driver.driver_features,
0559  * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
0560  *
0561  * Returns true if all features in the @features mask are supported, false
0562  * otherwise.
0563  */
0564 static inline bool drm_core_check_all_features(const struct drm_device *dev,
0565                            u32 features)
0566 {
0567     u32 supported = dev->driver->driver_features & dev->driver_features;
0568 
0569     return features && (supported & features) == features;
0570 }
0571 
0572 /**
0573  * drm_core_check_feature - check driver feature flags
0574  * @dev: DRM device to check
0575  * @feature: feature flag
0576  *
0577  * This checks @dev for driver features, see &drm_driver.driver_features,
0578  * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
0579  *
0580  * Returns true if the @feature is supported, false otherwise.
0581  */
0582 static inline bool drm_core_check_feature(const struct drm_device *dev,
0583                       enum drm_driver_feature feature)
0584 {
0585     return drm_core_check_all_features(dev, feature);
0586 }
0587 
0588 /**
0589  * drm_drv_uses_atomic_modeset - check if the driver implements
0590  * atomic_commit()
0591  * @dev: DRM device
0592  *
0593  * This check is useful if drivers do not have DRIVER_ATOMIC set but
0594  * have atomic modesetting internally implemented.
0595  */
0596 static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
0597 {
0598     return drm_core_check_feature(dev, DRIVER_ATOMIC) ||
0599         (dev->mode_config.funcs && dev->mode_config.funcs->atomic_commit != NULL);
0600 }
0601 
0602 
0603 int drm_dev_set_unique(struct drm_device *dev, const char *name);
0604 
0605 extern bool drm_firmware_drivers_only(void);
0606 
0607 #endif