1c76f0f7cSNoralf Trønnes /* SPDX-License-Identifier: GPL-2.0 */ 2c76f0f7cSNoralf Trønnes 3c76f0f7cSNoralf Trønnes #ifndef _DRM_CLIENT_H_ 4c76f0f7cSNoralf Trønnes #define _DRM_CLIENT_H_ 5c76f0f7cSNoralf Trønnes 6d81294afSNoralf Trønnes #include <linux/lockdep.h> 7d81294afSNoralf Trønnes #include <linux/mutex.h> 8c76f0f7cSNoralf Trønnes #include <linux/types.h> 9c76f0f7cSNoralf Trønnes 10e5852beeSNoralf Trønnes #include <drm/drm_connector.h> 11d81294afSNoralf Trønnes #include <drm/drm_crtc.h> 12d81294afSNoralf Trønnes 13c76f0f7cSNoralf Trønnes struct drm_client_dev; 14c76f0f7cSNoralf Trønnes struct drm_device; 15c76f0f7cSNoralf Trønnes struct drm_file; 16c76f0f7cSNoralf Trønnes struct drm_framebuffer; 17c76f0f7cSNoralf Trønnes struct drm_gem_object; 18e896c132SNoralf Trønnes struct drm_minor; 19c76f0f7cSNoralf Trønnes struct module; 20c76f0f7cSNoralf Trønnes 21d81294afSNoralf Trønnes #define DRM_CLIENT_MAX_CLONED_CONNECTORS 8 22d81294afSNoralf Trønnes 23c76f0f7cSNoralf Trønnes /** 24c76f0f7cSNoralf Trønnes * struct drm_client_funcs - DRM client callbacks 25c76f0f7cSNoralf Trønnes */ 26c76f0f7cSNoralf Trønnes struct drm_client_funcs { 27c76f0f7cSNoralf Trønnes /** 28c76f0f7cSNoralf Trønnes * @owner: The module owner 29c76f0f7cSNoralf Trønnes */ 30c76f0f7cSNoralf Trønnes struct module *owner; 31c76f0f7cSNoralf Trønnes 32c76f0f7cSNoralf Trønnes /** 33c76f0f7cSNoralf Trønnes * @unregister: 34c76f0f7cSNoralf Trønnes * 35c76f0f7cSNoralf Trønnes * Called when &drm_device is unregistered. The client should respond by 361e55a53aSMatt Roper * releasing its resources using drm_client_release(). 37c76f0f7cSNoralf Trønnes * 38c76f0f7cSNoralf Trønnes * This callback is optional. 39c76f0f7cSNoralf Trønnes */ 40c76f0f7cSNoralf Trønnes void (*unregister)(struct drm_client_dev *client); 41c76f0f7cSNoralf Trønnes 42c76f0f7cSNoralf Trønnes /** 43c76f0f7cSNoralf Trønnes * @restore: 44c76f0f7cSNoralf Trønnes * 45c76f0f7cSNoralf Trønnes * Called on drm_lastclose(). The first client instance in the list that 46c76f0f7cSNoralf Trønnes * returns zero gets the privilege to restore and no more clients are 47c76f0f7cSNoralf Trønnes * called. This callback is not called after @unregister has been called. 48c76f0f7cSNoralf Trønnes * 49c76f0f7cSNoralf Trønnes * This callback is optional. 50c76f0f7cSNoralf Trønnes */ 51c76f0f7cSNoralf Trønnes int (*restore)(struct drm_client_dev *client); 52c76f0f7cSNoralf Trønnes 53c76f0f7cSNoralf Trønnes /** 54c76f0f7cSNoralf Trønnes * @hotplug: 55c76f0f7cSNoralf Trønnes * 56c76f0f7cSNoralf Trønnes * Called on drm_kms_helper_hotplug_event(). 57c76f0f7cSNoralf Trønnes * This callback is not called after @unregister has been called. 58c76f0f7cSNoralf Trønnes * 59c76f0f7cSNoralf Trønnes * This callback is optional. 60c76f0f7cSNoralf Trønnes */ 61c76f0f7cSNoralf Trønnes int (*hotplug)(struct drm_client_dev *client); 62c76f0f7cSNoralf Trønnes }; 63c76f0f7cSNoralf Trønnes 64c76f0f7cSNoralf Trønnes /** 65c76f0f7cSNoralf Trønnes * struct drm_client_dev - DRM client instance 66c76f0f7cSNoralf Trønnes */ 67c76f0f7cSNoralf Trønnes struct drm_client_dev { 68c76f0f7cSNoralf Trønnes /** 69c76f0f7cSNoralf Trønnes * @dev: DRM device 70c76f0f7cSNoralf Trønnes */ 71c76f0f7cSNoralf Trønnes struct drm_device *dev; 72c76f0f7cSNoralf Trønnes 73c76f0f7cSNoralf Trønnes /** 74c76f0f7cSNoralf Trønnes * @name: Name of the client. 75c76f0f7cSNoralf Trønnes */ 76c76f0f7cSNoralf Trønnes const char *name; 77c76f0f7cSNoralf Trønnes 78c76f0f7cSNoralf Trønnes /** 79c76f0f7cSNoralf Trønnes * @list: 80c76f0f7cSNoralf Trønnes * 81c76f0f7cSNoralf Trønnes * List of all clients of a DRM device, linked into 82c76f0f7cSNoralf Trønnes * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex. 83c76f0f7cSNoralf Trønnes */ 84c76f0f7cSNoralf Trønnes struct list_head list; 85c76f0f7cSNoralf Trønnes 86c76f0f7cSNoralf Trønnes /** 87c76f0f7cSNoralf Trønnes * @funcs: DRM client functions (optional) 88c76f0f7cSNoralf Trønnes */ 89c76f0f7cSNoralf Trønnes const struct drm_client_funcs *funcs; 90c76f0f7cSNoralf Trønnes 91c76f0f7cSNoralf Trønnes /** 92c76f0f7cSNoralf Trønnes * @file: DRM file 93c76f0f7cSNoralf Trønnes */ 94c76f0f7cSNoralf Trønnes struct drm_file *file; 95d81294afSNoralf Trønnes 96d81294afSNoralf Trønnes /** 97d81294afSNoralf Trønnes * @modeset_mutex: Protects @modesets. 98d81294afSNoralf Trønnes */ 99d81294afSNoralf Trønnes struct mutex modeset_mutex; 100d81294afSNoralf Trønnes 101d81294afSNoralf Trønnes /** 102d81294afSNoralf Trønnes * @modesets: CRTC configurations 103d81294afSNoralf Trønnes */ 104d81294afSNoralf Trønnes struct drm_mode_set *modesets; 105c76f0f7cSNoralf Trønnes }; 106c76f0f7cSNoralf Trønnes 1074d4c2d89SNoralf Trønnes int drm_client_init(struct drm_device *dev, struct drm_client_dev *client, 108c76f0f7cSNoralf Trønnes const char *name, const struct drm_client_funcs *funcs); 109c76f0f7cSNoralf Trønnes void drm_client_release(struct drm_client_dev *client); 110e33898a2SNoralf Trønnes void drm_client_register(struct drm_client_dev *client); 111c76f0f7cSNoralf Trønnes 112c76f0f7cSNoralf Trønnes void drm_client_dev_unregister(struct drm_device *dev); 113c76f0f7cSNoralf Trønnes void drm_client_dev_hotplug(struct drm_device *dev); 114c76f0f7cSNoralf Trønnes void drm_client_dev_restore(struct drm_device *dev); 115c76f0f7cSNoralf Trønnes 116c76f0f7cSNoralf Trønnes /** 117c76f0f7cSNoralf Trønnes * struct drm_client_buffer - DRM client buffer 118c76f0f7cSNoralf Trønnes */ 119c76f0f7cSNoralf Trønnes struct drm_client_buffer { 120c76f0f7cSNoralf Trønnes /** 121c76f0f7cSNoralf Trønnes * @client: DRM client 122c76f0f7cSNoralf Trønnes */ 123c76f0f7cSNoralf Trønnes struct drm_client_dev *client; 124c76f0f7cSNoralf Trønnes 125c76f0f7cSNoralf Trønnes /** 126c76f0f7cSNoralf Trønnes * @handle: Buffer handle 127c76f0f7cSNoralf Trønnes */ 128c76f0f7cSNoralf Trønnes u32 handle; 129c76f0f7cSNoralf Trønnes 130c76f0f7cSNoralf Trønnes /** 131c76f0f7cSNoralf Trønnes * @pitch: Buffer pitch 132c76f0f7cSNoralf Trønnes */ 133c76f0f7cSNoralf Trønnes u32 pitch; 134c76f0f7cSNoralf Trønnes 135c76f0f7cSNoralf Trønnes /** 136c76f0f7cSNoralf Trønnes * @gem: GEM object backing this buffer 137c76f0f7cSNoralf Trønnes */ 138c76f0f7cSNoralf Trønnes struct drm_gem_object *gem; 139c76f0f7cSNoralf Trønnes 140c76f0f7cSNoralf Trønnes /** 141c76f0f7cSNoralf Trønnes * @vaddr: Virtual address for the buffer 142c76f0f7cSNoralf Trønnes */ 143c76f0f7cSNoralf Trønnes void *vaddr; 144c76f0f7cSNoralf Trønnes 145c76f0f7cSNoralf Trønnes /** 146c76f0f7cSNoralf Trønnes * @fb: DRM framebuffer 147c76f0f7cSNoralf Trønnes */ 148c76f0f7cSNoralf Trønnes struct drm_framebuffer *fb; 149c76f0f7cSNoralf Trønnes }; 150c76f0f7cSNoralf Trønnes 151c76f0f7cSNoralf Trønnes struct drm_client_buffer * 152c76f0f7cSNoralf Trønnes drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format); 153c76f0f7cSNoralf Trønnes void drm_client_framebuffer_delete(struct drm_client_buffer *buffer); 154c76f0f7cSNoralf Trønnes 155d81294afSNoralf Trønnes int drm_client_modeset_create(struct drm_client_dev *client); 156d81294afSNoralf Trønnes void drm_client_modeset_free(struct drm_client_dev *client); 157d81294afSNoralf Trønnes void drm_client_modeset_release(struct drm_client_dev *client); 158d81294afSNoralf Trønnes struct drm_mode_set *drm_client_find_modeset(struct drm_client_dev *client, struct drm_crtc *crtc); 159aec3925fSNoralf Trønnes bool drm_client_panel_rotation(struct drm_mode_set *modeset, unsigned int *rotation); 160aec3925fSNoralf Trønnes int drm_client_modeset_commit_force(struct drm_client_dev *client); 161aec3925fSNoralf Trønnes int drm_client_modeset_commit(struct drm_client_dev *client); 162aec3925fSNoralf Trønnes int drm_client_modeset_dpms(struct drm_client_dev *client, int mode); 163d81294afSNoralf Trønnes 164d81294afSNoralf Trønnes /** 165d81294afSNoralf Trønnes * drm_client_for_each_modeset() - Iterate over client modesets 166d81294afSNoralf Trønnes * @modeset: &drm_mode_set loop cursor 167d81294afSNoralf Trønnes * @client: DRM client 168d81294afSNoralf Trønnes */ 169d81294afSNoralf Trønnes #define drm_client_for_each_modeset(modeset, client) \ 170d81294afSNoralf Trønnes for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \ 171d81294afSNoralf Trønnes modeset = (client)->modesets; modeset->crtc; modeset++) 172d81294afSNoralf Trønnes 173e5852beeSNoralf Trønnes /** 174e5852beeSNoralf Trønnes * drm_client_for_each_connector_iter - connector_list iterator macro 175e5852beeSNoralf Trønnes * @connector: &struct drm_connector pointer used as cursor 176e5852beeSNoralf Trønnes * @iter: &struct drm_connector_list_iter 177e5852beeSNoralf Trønnes * 178e5852beeSNoralf Trønnes * This iterates the connectors that are useable for internal clients (excludes 179e5852beeSNoralf Trønnes * writeback connectors). 180e5852beeSNoralf Trønnes * 181e5852beeSNoralf Trønnes * For more info see drm_for_each_connector_iter(). 182e5852beeSNoralf Trønnes */ 183e5852beeSNoralf Trønnes #define drm_client_for_each_connector_iter(connector, iter) \ 184e5852beeSNoralf Trønnes drm_for_each_connector_iter(connector, iter) \ 185e5852beeSNoralf Trønnes if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) 186e5852beeSNoralf Trønnes 187e896c132SNoralf Trønnes int drm_client_debugfs_init(struct drm_minor *minor); 188e896c132SNoralf Trønnes 189c76f0f7cSNoralf Trønnes #endif 190