1 /* SPDX-License-Identifier: GPL-2.0 */
6 #include <linux/lockdep.h>
7 #include <linux/mutex.h>
8 #include <linux/types.h>
10 #include <drm/drm_connector.h>
11 #include <drm/drm_crtc.h>
13 struct drm_client_dev;
16 struct drm_framebuffer;
17 struct drm_gem_object;
22 * struct drm_client_funcs - DRM client callbacks
24 struct drm_client_funcs {
26 * @owner: The module owner
33 * Called when &drm_device is unregistered. The client should respond by
34 * releasing its resources using drm_client_release().
36 * This callback is optional.
38 void (*unregister)(struct drm_client_dev *client);
43 * Called on drm_lastclose(). The first client instance in the list that
44 * returns zero gets the privilege to restore and no more clients are
45 * called. This callback is not called after @unregister has been called.
47 * This callback is optional.
49 int (*restore)(struct drm_client_dev *client);
54 * Called on drm_kms_helper_hotplug_event().
55 * This callback is not called after @unregister has been called.
57 * This callback is optional.
59 int (*hotplug)(struct drm_client_dev *client);
63 * struct drm_client_dev - DRM client instance
65 struct drm_client_dev {
69 struct drm_device *dev;
72 * @name: Name of the client.
79 * List of all clients of a DRM device, linked into
80 * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
82 struct list_head list;
85 * @funcs: DRM client functions (optional)
87 const struct drm_client_funcs *funcs;
92 struct drm_file *file;
95 * @modeset_mutex: Protects @modesets.
97 struct mutex modeset_mutex;
100 * @modesets: CRTC configurations
102 struct drm_mode_set *modesets;
105 int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
106 const char *name, const struct drm_client_funcs *funcs);
107 void drm_client_release(struct drm_client_dev *client);
108 void drm_client_register(struct drm_client_dev *client);
110 void drm_client_dev_unregister(struct drm_device *dev);
111 void drm_client_dev_hotplug(struct drm_device *dev);
112 void drm_client_dev_restore(struct drm_device *dev);
115 * struct drm_client_buffer - DRM client buffer
117 struct drm_client_buffer {
119 * @client: DRM client
121 struct drm_client_dev *client;
124 * @handle: Buffer handle
129 * @pitch: Buffer pitch
134 * @gem: GEM object backing this buffer
136 struct drm_gem_object *gem;
139 * @vaddr: Virtual address for the buffer
144 * @fb: DRM framebuffer
146 struct drm_framebuffer *fb;
149 struct drm_client_buffer *
150 drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
151 void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
153 int drm_client_modeset_create(struct drm_client_dev *client);
154 void drm_client_modeset_free(struct drm_client_dev *client);
155 int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
156 bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
157 int drm_client_modeset_commit_force(struct drm_client_dev *client);
158 int drm_client_modeset_commit(struct drm_client_dev *client);
159 int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
162 * drm_client_for_each_modeset() - Iterate over client modesets
163 * @modeset: &drm_mode_set loop cursor
164 * @client: DRM client
166 #define drm_client_for_each_modeset(modeset, client) \
167 for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
168 modeset = (client)->modesets; modeset->crtc; modeset++)
171 * drm_client_for_each_connector_iter - connector_list iterator macro
172 * @connector: &struct drm_connector pointer used as cursor
173 * @iter: &struct drm_connector_list_iter
175 * This iterates the connectors that are useable for internal clients (excludes
176 * writeback connectors).
178 * For more info see drm_for_each_connector_iter().
180 #define drm_client_for_each_connector_iter(connector, iter) \
181 drm_for_each_connector_iter(connector, iter) \
182 if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
184 int drm_client_debugfs_init(struct drm_minor *minor);