Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 or MIT */
0002 
0003 #ifndef _DRM_CLIENT_H_
0004 #define _DRM_CLIENT_H_
0005 
0006 #include <linux/iosys-map.h>
0007 #include <linux/lockdep.h>
0008 #include <linux/mutex.h>
0009 #include <linux/types.h>
0010 
0011 #include <drm/drm_connector.h>
0012 #include <drm/drm_crtc.h>
0013 
0014 struct drm_client_dev;
0015 struct drm_device;
0016 struct drm_file;
0017 struct drm_framebuffer;
0018 struct drm_gem_object;
0019 struct drm_minor;
0020 struct module;
0021 
0022 /**
0023  * struct drm_client_funcs - DRM client callbacks
0024  */
0025 struct drm_client_funcs {
0026     /**
0027      * @owner: The module owner
0028      */
0029     struct module *owner;
0030 
0031     /**
0032      * @unregister:
0033      *
0034      * Called when &drm_device is unregistered. The client should respond by
0035      * releasing its resources using drm_client_release().
0036      *
0037      * This callback is optional.
0038      */
0039     void (*unregister)(struct drm_client_dev *client);
0040 
0041     /**
0042      * @restore:
0043      *
0044      * Called on drm_lastclose(). The first client instance in the list that
0045      * returns zero gets the privilege to restore and no more clients are
0046      * called. This callback is not called after @unregister has been called.
0047      *
0048      * Note that the core does not guarantee exclusion against concurrent
0049      * drm_open(). Clients need to ensure this themselves, for example by
0050      * using drm_master_internal_acquire() and
0051      * drm_master_internal_release().
0052      *
0053      * This callback is optional.
0054      */
0055     int (*restore)(struct drm_client_dev *client);
0056 
0057     /**
0058      * @hotplug:
0059      *
0060      * Called on drm_kms_helper_hotplug_event().
0061      * This callback is not called after @unregister has been called.
0062      *
0063      * This callback is optional.
0064      */
0065     int (*hotplug)(struct drm_client_dev *client);
0066 };
0067 
0068 /**
0069  * struct drm_client_dev - DRM client instance
0070  */
0071 struct drm_client_dev {
0072     /**
0073      * @dev: DRM device
0074      */
0075     struct drm_device *dev;
0076 
0077     /**
0078      * @name: Name of the client.
0079      */
0080     const char *name;
0081 
0082     /**
0083      * @list:
0084      *
0085      * List of all clients of a DRM device, linked into
0086      * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
0087      */
0088     struct list_head list;
0089 
0090     /**
0091      * @funcs: DRM client functions (optional)
0092      */
0093     const struct drm_client_funcs *funcs;
0094 
0095     /**
0096      * @file: DRM file
0097      */
0098     struct drm_file *file;
0099 
0100     /**
0101      * @modeset_mutex: Protects @modesets.
0102      */
0103     struct mutex modeset_mutex;
0104 
0105     /**
0106      * @modesets: CRTC configurations
0107      */
0108     struct drm_mode_set *modesets;
0109 };
0110 
0111 int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
0112             const char *name, const struct drm_client_funcs *funcs);
0113 void drm_client_release(struct drm_client_dev *client);
0114 void drm_client_register(struct drm_client_dev *client);
0115 
0116 void drm_client_dev_unregister(struct drm_device *dev);
0117 void drm_client_dev_hotplug(struct drm_device *dev);
0118 void drm_client_dev_restore(struct drm_device *dev);
0119 
0120 /**
0121  * struct drm_client_buffer - DRM client buffer
0122  */
0123 struct drm_client_buffer {
0124     /**
0125      * @client: DRM client
0126      */
0127     struct drm_client_dev *client;
0128 
0129     /**
0130      * @handle: Buffer handle
0131      */
0132     u32 handle;
0133 
0134     /**
0135      * @pitch: Buffer pitch
0136      */
0137     u32 pitch;
0138 
0139     /**
0140      * @gem: GEM object backing this buffer
0141      */
0142     struct drm_gem_object *gem;
0143 
0144     /**
0145      * @map: Virtual address for the buffer
0146      */
0147     struct iosys_map map;
0148 
0149     /**
0150      * @fb: DRM framebuffer
0151      */
0152     struct drm_framebuffer *fb;
0153 };
0154 
0155 struct drm_client_buffer *
0156 drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
0157 void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
0158 int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect);
0159 int drm_client_buffer_vmap(struct drm_client_buffer *buffer,
0160                struct iosys_map *map);
0161 void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);
0162 
0163 int drm_client_modeset_create(struct drm_client_dev *client);
0164 void drm_client_modeset_free(struct drm_client_dev *client);
0165 int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
0166 bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
0167 int drm_client_modeset_check(struct drm_client_dev *client);
0168 int drm_client_modeset_commit_locked(struct drm_client_dev *client);
0169 int drm_client_modeset_commit(struct drm_client_dev *client);
0170 int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
0171 
0172 /**
0173  * drm_client_for_each_modeset() - Iterate over client modesets
0174  * @modeset: &drm_mode_set loop cursor
0175  * @client: DRM client
0176  */
0177 #define drm_client_for_each_modeset(modeset, client) \
0178     for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
0179          modeset = (client)->modesets; modeset->crtc; modeset++)
0180 
0181 /**
0182  * drm_client_for_each_connector_iter - connector_list iterator macro
0183  * @connector: &struct drm_connector pointer used as cursor
0184  * @iter: &struct drm_connector_list_iter
0185  *
0186  * This iterates the connectors that are useable for internal clients (excludes
0187  * writeback connectors).
0188  *
0189  * For more info see drm_for_each_connector_iter().
0190  */
0191 #define drm_client_for_each_connector_iter(connector, iter) \
0192     drm_for_each_connector_iter(connector, iter) \
0193         if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
0194 
0195 void drm_client_debugfs_init(struct drm_minor *minor);
0196 
0197 #endif