blob: 72d51d1e9dd9ea33ea83b7c6fcdbdc0cc1f250ef [file] [log] [blame]
Noralf Trønnesc76f0f72018-07-03 18:03:47 +02001/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef _DRM_CLIENT_H_
4#define _DRM_CLIENT_H_
5
Noralf Trønnesd81294a2019-05-31 16:01:11 +02006#include <linux/lockdep.h>
7#include <linux/mutex.h>
Noralf Trønnesc76f0f72018-07-03 18:03:47 +02008#include <linux/types.h>
9
Noralf Trønnese5852be2019-06-08 17:26:53 +020010#include <drm/drm_connector.h>
Noralf Trønnesd81294a2019-05-31 16:01:11 +020011#include <drm/drm_crtc.h>
12
Noralf Trønnesc76f0f72018-07-03 18:03:47 +020013struct drm_client_dev;
14struct drm_device;
15struct drm_file;
16struct drm_framebuffer;
17struct drm_gem_object;
Noralf Trønnese896c1322018-07-03 18:03:51 +020018struct drm_minor;
Noralf Trønnesc76f0f72018-07-03 18:03:47 +020019struct module;
20
21/**
22 * struct drm_client_funcs - DRM client callbacks
23 */
24struct drm_client_funcs {
25 /**
26 * @owner: The module owner
27 */
28 struct module *owner;
29
30 /**
31 * @unregister:
32 *
33 * Called when &drm_device is unregistered. The client should respond by
Matt Roper1e55a532019-02-01 17:23:26 -080034 * releasing its resources using drm_client_release().
Noralf Trønnesc76f0f72018-07-03 18:03:47 +020035 *
36 * This callback is optional.
37 */
38 void (*unregister)(struct drm_client_dev *client);
39
40 /**
41 * @restore:
42 *
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.
46 *
47 * This callback is optional.
48 */
49 int (*restore)(struct drm_client_dev *client);
50
51 /**
52 * @hotplug:
53 *
54 * Called on drm_kms_helper_hotplug_event().
55 * This callback is not called after @unregister has been called.
56 *
57 * This callback is optional.
58 */
59 int (*hotplug)(struct drm_client_dev *client);
60};
61
62/**
63 * struct drm_client_dev - DRM client instance
64 */
65struct drm_client_dev {
66 /**
67 * @dev: DRM device
68 */
69 struct drm_device *dev;
70
71 /**
72 * @name: Name of the client.
73 */
74 const char *name;
75
76 /**
77 * @list:
78 *
79 * List of all clients of a DRM device, linked into
80 * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
81 */
82 struct list_head list;
83
84 /**
85 * @funcs: DRM client functions (optional)
86 */
87 const struct drm_client_funcs *funcs;
88
89 /**
90 * @file: DRM file
91 */
92 struct drm_file *file;
Noralf Trønnesd81294a2019-05-31 16:01:11 +020093
94 /**
95 * @modeset_mutex: Protects @modesets.
96 */
97 struct mutex modeset_mutex;
98
99 /**
100 * @modesets: CRTC configurations
101 */
102 struct drm_mode_set *modesets;
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200103};
104
Noralf Trønnes4d4c2d82018-10-01 21:45:36 +0200105int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
106 const char *name, const struct drm_client_funcs *funcs);
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200107void drm_client_release(struct drm_client_dev *client);
Noralf Trønnese33898a2019-04-03 14:56:58 +0200108void drm_client_register(struct drm_client_dev *client);
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200109
110void drm_client_dev_unregister(struct drm_device *dev);
111void drm_client_dev_hotplug(struct drm_device *dev);
112void drm_client_dev_restore(struct drm_device *dev);
113
114/**
115 * struct drm_client_buffer - DRM client buffer
116 */
117struct drm_client_buffer {
118 /**
119 * @client: DRM client
120 */
121 struct drm_client_dev *client;
122
123 /**
124 * @handle: Buffer handle
125 */
126 u32 handle;
127
128 /**
129 * @pitch: Buffer pitch
130 */
131 u32 pitch;
132
133 /**
134 * @gem: GEM object backing this buffer
135 */
136 struct drm_gem_object *gem;
137
138 /**
139 * @vaddr: Virtual address for the buffer
140 */
141 void *vaddr;
142
143 /**
144 * @fb: DRM framebuffer
145 */
146 struct drm_framebuffer *fb;
147};
148
149struct drm_client_buffer *
150drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
151void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
152
Noralf Trønnesd81294a2019-05-31 16:01:11 +0200153int drm_client_modeset_create(struct drm_client_dev *client);
154void drm_client_modeset_free(struct drm_client_dev *client);
Noralf Trønnescf139092019-06-08 17:26:55 +0200155int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height);
Maxime Riparda99076e2019-06-19 12:17:49 +0200156bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation);
Noralf Trønnesaec39252019-05-31 16:01:13 +0200157int drm_client_modeset_commit_force(struct drm_client_dev *client);
158int drm_client_modeset_commit(struct drm_client_dev *client);
159int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
Noralf Trønnesd81294a2019-05-31 16:01:11 +0200160
161/**
162 * drm_client_for_each_modeset() - Iterate over client modesets
163 * @modeset: &drm_mode_set loop cursor
164 * @client: DRM client
165 */
166#define drm_client_for_each_modeset(modeset, client) \
167 for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
168 modeset = (client)->modesets; modeset->crtc; modeset++)
169
Noralf Trønnese5852be2019-06-08 17:26:53 +0200170/**
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
174 *
175 * This iterates the connectors that are useable for internal clients (excludes
176 * writeback connectors).
177 *
178 * For more info see drm_for_each_connector_iter().
179 */
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)
183
Noralf Trønnese896c1322018-07-03 18:03:51 +0200184int drm_client_debugfs_init(struct drm_minor *minor);
185
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200186#endif