blob: 87be9aeb1fe09d4908e09908129c1a39741b64c4 [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ønnesd81294a2019-05-31 16:01:11 +020010#include <drm/drm_crtc.h>
11
Noralf Trønnesc76f0f72018-07-03 18:03:47 +020012struct drm_client_dev;
13struct drm_device;
14struct drm_file;
15struct drm_framebuffer;
16struct drm_gem_object;
Noralf Trønnese896c1322018-07-03 18:03:51 +020017struct drm_minor;
Noralf Trønnesc76f0f72018-07-03 18:03:47 +020018struct module;
19
Noralf Trønnesd81294a2019-05-31 16:01:11 +020020#define DRM_CLIENT_MAX_CLONED_CONNECTORS 8
21
Noralf Trønnesc76f0f72018-07-03 18:03:47 +020022/**
23 * struct drm_client_funcs - DRM client callbacks
24 */
25struct drm_client_funcs {
26 /**
27 * @owner: The module owner
28 */
29 struct module *owner;
30
31 /**
32 * @unregister:
33 *
34 * Called when &drm_device is unregistered. The client should respond by
Matt Roper1e55a532019-02-01 17:23:26 -080035 * releasing its resources using drm_client_release().
Noralf Trønnesc76f0f72018-07-03 18:03:47 +020036 *
37 * This callback is optional.
38 */
39 void (*unregister)(struct drm_client_dev *client);
40
41 /**
42 * @restore:
43 *
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.
47 *
48 * This callback is optional.
49 */
50 int (*restore)(struct drm_client_dev *client);
51
52 /**
53 * @hotplug:
54 *
55 * Called on drm_kms_helper_hotplug_event().
56 * This callback is not called after @unregister has been called.
57 *
58 * This callback is optional.
59 */
60 int (*hotplug)(struct drm_client_dev *client);
61};
62
63/**
64 * struct drm_client_dev - DRM client instance
65 */
66struct drm_client_dev {
67 /**
68 * @dev: DRM device
69 */
70 struct drm_device *dev;
71
72 /**
73 * @name: Name of the client.
74 */
75 const char *name;
76
77 /**
78 * @list:
79 *
80 * List of all clients of a DRM device, linked into
81 * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex.
82 */
83 struct list_head list;
84
85 /**
86 * @funcs: DRM client functions (optional)
87 */
88 const struct drm_client_funcs *funcs;
89
90 /**
91 * @file: DRM file
92 */
93 struct drm_file *file;
Noralf Trønnesd81294a2019-05-31 16:01:11 +020094
95 /**
96 * @modeset_mutex: Protects @modesets.
97 */
98 struct mutex modeset_mutex;
99
100 /**
101 * @modesets: CRTC configurations
102 */
103 struct drm_mode_set *modesets;
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200104};
105
Noralf Trønnes4d4c2d82018-10-01 21:45:36 +0200106int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
107 const char *name, const struct drm_client_funcs *funcs);
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200108void drm_client_release(struct drm_client_dev *client);
Noralf Trønnese33898a2019-04-03 14:56:58 +0200109void drm_client_register(struct drm_client_dev *client);
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200110
111void drm_client_dev_unregister(struct drm_device *dev);
112void drm_client_dev_hotplug(struct drm_device *dev);
113void drm_client_dev_restore(struct drm_device *dev);
114
115/**
116 * struct drm_client_buffer - DRM client buffer
117 */
118struct drm_client_buffer {
119 /**
120 * @client: DRM client
121 */
122 struct drm_client_dev *client;
123
124 /**
125 * @handle: Buffer handle
126 */
127 u32 handle;
128
129 /**
130 * @pitch: Buffer pitch
131 */
132 u32 pitch;
133
134 /**
135 * @gem: GEM object backing this buffer
136 */
137 struct drm_gem_object *gem;
138
139 /**
140 * @vaddr: Virtual address for the buffer
141 */
142 void *vaddr;
143
144 /**
145 * @fb: DRM framebuffer
146 */
147 struct drm_framebuffer *fb;
148};
149
150struct drm_client_buffer *
151drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);
152void drm_client_framebuffer_delete(struct drm_client_buffer *buffer);
153
Noralf Trønnesd81294a2019-05-31 16:01:11 +0200154int drm_client_modeset_create(struct drm_client_dev *client);
155void drm_client_modeset_free(struct drm_client_dev *client);
156void drm_client_modeset_release(struct drm_client_dev *client);
157struct drm_mode_set *drm_client_find_modeset(struct drm_client_dev *client, struct drm_crtc *crtc);
158
159/**
160 * drm_client_for_each_modeset() - Iterate over client modesets
161 * @modeset: &drm_mode_set loop cursor
162 * @client: DRM client
163 */
164#define drm_client_for_each_modeset(modeset, client) \
165 for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \
166 modeset = (client)->modesets; modeset->crtc; modeset++)
167
Noralf Trønnese896c1322018-07-03 18:03:51 +0200168int drm_client_debugfs_init(struct drm_minor *minor);
169
Noralf Trønnesc76f0f72018-07-03 18:03:47 +0200170#endif