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