1 /* SPDX-License-Identifier: GPL-2.0 or MIT */
6 #include <linux/iosys-map.h>
7 #include <linux/lockdep.h>
8 #include <linux/mutex.h>
9 #include <linux/types.h>
11 #include <drm/drm_connector.h>
12 #include <drm/drm_crtc.h>
14 struct drm_client_dev;
17 struct drm_framebuffer;
18 struct drm_gem_object;
23 * struct drm_client_funcs - DRM client callbacks
25 struct drm_client_funcs {
27 * @owner: The module owner
34 * Called when &drm_device is unregistered. The client should respond by
35 * releasing its resources using drm_client_release().
37 * This callback is optional.
39 void (*unregister)(struct drm_client_dev *client);
44 * Called on drm_lastclose(). The first client instance in the list that
45 * returns zero gets the privilege to restore and no more clients are
46 * called. This callback is not called after @unregister has been called.
48 * Note that the core does not guarantee exclusion against concurrent
49 * drm_open(). Clients need to ensure this themselves, for example by
50 * using drm_master_internal_acquire() and
51 * drm_master_internal_release().
53 * This callback is optional.
55 int (*restore)(struct drm_client_dev *client);
60 * Called on drm_kms_helper_hotplug_event().
61 * This callback is not called after @unregister has been called.
63 * This callback is optional.
65 int (*hotplug)(struct drm_client_dev *client);
69 * struct drm_client_dev - DRM client instance
71 struct drm_client_dev {
75 struct drm_device *dev;
78 * @name: Name of the client.
85 * List of all clients of a DRM device, linked into
86 * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
88 struct list_head list;
91 * @funcs: DRM client functions (optional)
93 const struct drm_client_funcs *funcs;
98 struct drm_file *file;
101 * @modeset_mutex: Protects @modesets.
103 struct mutex modeset_mutex;
106 * @modesets: CRTC configurations
108 struct drm_mode_set *modesets;
113 * Set by client hotplug helpers if the hotplugging failed
114 * before. It is usually not tried again.
119 int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
120 const char *name, const struct drm_client_funcs *funcs);
121 void drm_client_release(struct drm_client_dev *client);
122 void drm_client_register(struct drm_client_dev *client);
124 void drm_client_dev_unregister(struct drm_device *dev);
125 void drm_client_dev_hotplug(struct drm_device *dev);
126 void drm_client_dev_restore(struct drm_device *dev);
129 * struct drm_client_buffer - DRM client buffer
131 struct drm_client_buffer {
133 * @client: DRM client
135 struct drm_client_dev *client;
138 * @pitch: Buffer pitch
143 * @gem: GEM object backing this buffer
145 struct drm_gem_object *gem;
148 * @map: Virtual address for the buffer
150 struct iosys_map map;
153 * @fb: DRM framebuffer
155 struct drm_framebuffer *fb;
158 struct drm_client_buffer *
159 drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
160 void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
161 int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect);
162 int drm_client_buffer_vmap(struct drm_client_buffer *buffer,
163 struct iosys_map *map);
164 void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);
166 int drm_client_modeset_create(struct drm_client_dev *client);
167 void drm_client_modeset_free(struct drm_client_dev *client);
168 int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
169 bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
170 int drm_client_modeset_check(struct drm_client_dev *client);
171 int drm_client_modeset_commit_locked(struct drm_client_dev *client);
172 int drm_client_modeset_commit(struct drm_client_dev *client);
173 int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
176 * drm_client_for_each_modeset() - Iterate over client modesets
177 * @modeset: &drm_mode_set loop cursor
178 * @client: DRM client
180 #define drm_client_for_each_modeset(modeset, client) \
181 for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
182 modeset = (client)->modesets; modeset->crtc; modeset++)
185 * drm_client_for_each_connector_iter - connector_list iterator macro
186 * @connector: &struct drm_connector pointer used as cursor
187 * @iter: &struct drm_connector_list_iter
189 * This iterates the connectors that are useable for internal clients (excludes
190 * writeback connectors).
192 * For more info see drm_for_each_connector_iter().
194 #define drm_client_for_each_connector_iter(connector, iter) \
195 drm_for_each_connector_iter(connector, iter) \
196 if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
198 void drm_client_debugfs_init(struct drm_minor *minor);