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);
70 * Called when suspending the device.
72 * This callback is optional.
74 * FIXME: Some callers hold the console lock when invoking this
75 * function. This interferes with fbdev emulation, which
76 * also tries to acquire the lock. Push the console lock
77 * into the callback and remove 'holds_console_lock'.
79 int (*suspend)(struct drm_client_dev *client, bool holds_console_lock);
84 * Called when resuming the device from suspend.
86 * This callback is optional.
88 * FIXME: Some callers hold the console lock when invoking this
89 * function. This interferes with fbdev emulation, which
90 * also tries to acquire the lock. Push the console lock
91 * into the callback and remove 'holds_console_lock'.
93 int (*resume)(struct drm_client_dev *client, bool holds_console_lock);
97 * struct drm_client_dev - DRM client instance
99 struct drm_client_dev {
103 struct drm_device *dev;
106 * @name: Name of the client.
113 * List of all clients of a DRM device, linked into
114 * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
116 struct list_head list;
119 * @funcs: DRM client functions (optional)
121 const struct drm_client_funcs *funcs;
126 struct drm_file *file;
129 * @modeset_mutex: Protects @modesets.
131 struct mutex modeset_mutex;
134 * @modesets: CRTC configurations
136 struct drm_mode_set *modesets;
141 * The client has been suspended.
148 * Set by client hotplug helpers if the hotplugging failed
149 * before. It is usually not tried again.
154 int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
155 const char *name, const struct drm_client_funcs *funcs);
156 void drm_client_release(struct drm_client_dev *client);
157 void drm_client_register(struct drm_client_dev *client);
160 * struct drm_client_buffer - DRM client buffer
162 struct drm_client_buffer {
164 * @client: DRM client
166 struct drm_client_dev *client;
169 * @pitch: Buffer pitch
174 * @gem: GEM object backing this buffer
176 * FIXME: The dependency on GEM here isn't required, we could
177 * convert the driver handle to a dma-buf instead and use the
178 * backend-agnostic dma-buf vmap support instead. This would
179 * require that the handle2fd prime ioctl is reworked to pull the
180 * fd_install step out of the driver backend hooks, to make that
181 * final step optional for internal users.
183 struct drm_gem_object *gem;
186 * @map: Virtual address for the buffer
188 struct iosys_map map;
191 * @fb: DRM framebuffer
193 struct drm_framebuffer *fb;
196 struct drm_client_buffer *
197 drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
198 void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
199 int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect);
200 int drm_client_buffer_vmap_local(struct drm_client_buffer *buffer,
201 struct iosys_map *map_copy);
202 void drm_client_buffer_vunmap_local(struct drm_client_buffer *buffer);
203 int drm_client_buffer_vmap(struct drm_client_buffer *buffer,
204 struct iosys_map *map);
205 void drm_client_buffer_vunmap(struct drm_client_buffer *buffer);
207 int drm_client_modeset_create(struct drm_client_dev *client);
208 void drm_client_modeset_free(struct drm_client_dev *client);
209 int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
210 bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
211 int drm_client_modeset_check(struct drm_client_dev *client);
212 int drm_client_modeset_commit_locked(struct drm_client_dev *client);
213 int drm_client_modeset_commit(struct drm_client_dev *client);
214 int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
217 * drm_client_for_each_modeset() - Iterate over client modesets
218 * @modeset: &drm_mode_set loop cursor
219 * @client: DRM client
221 #define drm_client_for_each_modeset(modeset, client) \
222 for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
223 modeset = (client)->modesets; modeset->crtc; modeset++)
226 * drm_client_for_each_connector_iter - connector_list iterator macro
227 * @connector: &struct drm_connector pointer used as cursor
228 * @iter: &struct drm_connector_list_iter
230 * This iterates the connectors that are useable for internal clients (excludes
231 * writeback connectors).
233 * For more info see drm_for_each_connector_iter().
235 #define drm_client_for_each_connector_iter(connector, iter) \
236 drm_for_each_connector_iter(connector, iter) \
237 if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)