Emmanuel Vadot | ca96088 | 2020-04-30 17:33:46 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 or MIT */ |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 2 | |
| 3 | #ifndef _DRM_CLIENT_H_ |
| 4 | #define _DRM_CLIENT_H_ |
| 5 | |
Thomas Zimmermann | a859555 | 2020-11-03 10:30:13 +0100 | [diff] [blame] | 6 | #include <linux/dma-buf-map.h> |
Noralf Trønnes | d81294a | 2019-05-31 16:01:11 +0200 | [diff] [blame] | 7 | #include <linux/lockdep.h> |
| 8 | #include <linux/mutex.h> |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 9 | #include <linux/types.h> |
| 10 | |
Noralf Trønnes | e5852be | 2019-06-08 17:26:53 +0200 | [diff] [blame] | 11 | #include <drm/drm_connector.h> |
Noralf Trønnes | d81294a | 2019-05-31 16:01:11 +0200 | [diff] [blame] | 12 | #include <drm/drm_crtc.h> |
| 13 | |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 14 | struct drm_client_dev; |
| 15 | struct drm_device; |
| 16 | struct drm_file; |
| 17 | struct drm_framebuffer; |
| 18 | struct drm_gem_object; |
Noralf Trønnes | e896c132 | 2018-07-03 18:03:51 +0200 | [diff] [blame] | 19 | struct drm_minor; |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 20 | struct module; |
| 21 | |
| 22 | /** |
| 23 | * struct drm_client_funcs - DRM client callbacks |
| 24 | */ |
| 25 | struct 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 Roper | 1e55a53 | 2019-02-01 17:23:26 -0800 | [diff] [blame] | 35 | * releasing its resources using drm_client_release(). |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 36 | * |
| 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 | * |
Daniel Vetter | 64914da | 2020-02-04 16:01:43 +0100 | [diff] [blame] | 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(). |
| 52 | * |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 53 | * This callback is optional. |
| 54 | */ |
| 55 | int (*restore)(struct drm_client_dev *client); |
| 56 | |
| 57 | /** |
| 58 | * @hotplug: |
| 59 | * |
| 60 | * Called on drm_kms_helper_hotplug_event(). |
| 61 | * This callback is not called after @unregister has been called. |
| 62 | * |
| 63 | * This callback is optional. |
| 64 | */ |
| 65 | int (*hotplug)(struct drm_client_dev *client); |
| 66 | }; |
| 67 | |
| 68 | /** |
| 69 | * struct drm_client_dev - DRM client instance |
| 70 | */ |
| 71 | struct drm_client_dev { |
| 72 | /** |
| 73 | * @dev: DRM device |
| 74 | */ |
| 75 | struct drm_device *dev; |
| 76 | |
| 77 | /** |
| 78 | * @name: Name of the client. |
| 79 | */ |
| 80 | const char *name; |
| 81 | |
| 82 | /** |
| 83 | * @list: |
| 84 | * |
| 85 | * List of all clients of a DRM device, linked into |
| 86 | * &drm_device.clientlist. Protected by &drm_device.clientlist_mutex. |
| 87 | */ |
| 88 | struct list_head list; |
| 89 | |
| 90 | /** |
| 91 | * @funcs: DRM client functions (optional) |
| 92 | */ |
| 93 | const struct drm_client_funcs *funcs; |
| 94 | |
| 95 | /** |
| 96 | * @file: DRM file |
| 97 | */ |
| 98 | struct drm_file *file; |
Noralf Trønnes | d81294a | 2019-05-31 16:01:11 +0200 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * @modeset_mutex: Protects @modesets. |
| 102 | */ |
| 103 | struct mutex modeset_mutex; |
| 104 | |
| 105 | /** |
| 106 | * @modesets: CRTC configurations |
| 107 | */ |
| 108 | struct drm_mode_set *modesets; |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 109 | }; |
| 110 | |
Noralf Trønnes | 4d4c2d8 | 2018-10-01 21:45:36 +0200 | [diff] [blame] | 111 | int drm_client_init(struct drm_device *dev, struct drm_client_dev *client, |
| 112 | const char *name, const struct drm_client_funcs *funcs); |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 113 | void drm_client_release(struct drm_client_dev *client); |
Noralf Trønnes | e33898a | 2019-04-03 14:56:58 +0200 | [diff] [blame] | 114 | void drm_client_register(struct drm_client_dev *client); |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 115 | |
| 116 | void drm_client_dev_unregister(struct drm_device *dev); |
| 117 | void drm_client_dev_hotplug(struct drm_device *dev); |
| 118 | void drm_client_dev_restore(struct drm_device *dev); |
| 119 | |
| 120 | /** |
| 121 | * struct drm_client_buffer - DRM client buffer |
| 122 | */ |
| 123 | struct drm_client_buffer { |
| 124 | /** |
| 125 | * @client: DRM client |
| 126 | */ |
| 127 | struct drm_client_dev *client; |
| 128 | |
| 129 | /** |
| 130 | * @handle: Buffer handle |
| 131 | */ |
| 132 | u32 handle; |
| 133 | |
| 134 | /** |
| 135 | * @pitch: Buffer pitch |
| 136 | */ |
| 137 | u32 pitch; |
| 138 | |
| 139 | /** |
| 140 | * @gem: GEM object backing this buffer |
| 141 | */ |
| 142 | struct drm_gem_object *gem; |
| 143 | |
| 144 | /** |
Thomas Zimmermann | a859555 | 2020-11-03 10:30:13 +0100 | [diff] [blame] | 145 | * @map: Virtual address for the buffer |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 146 | */ |
Thomas Zimmermann | a859555 | 2020-11-03 10:30:13 +0100 | [diff] [blame] | 147 | struct dma_buf_map map; |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * @fb: DRM framebuffer |
| 151 | */ |
| 152 | struct drm_framebuffer *fb; |
| 153 | }; |
| 154 | |
| 155 | struct drm_client_buffer * |
| 156 | drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format); |
| 157 | void drm_client_framebuffer_delete(struct drm_client_buffer *buffer); |
Noralf Trønnes | c9c03e3 | 2020-05-09 16:16:12 +0200 | [diff] [blame] | 158 | int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect); |
Thomas Zimmermann | a859555 | 2020-11-03 10:30:13 +0100 | [diff] [blame] | 159 | int drm_client_buffer_vmap(struct drm_client_buffer *buffer, struct dma_buf_map *map); |
Thomas Zimmermann | 15dd0fc | 2019-07-03 09:58:18 +0200 | [diff] [blame] | 160 | void drm_client_buffer_vunmap(struct drm_client_buffer *buffer); |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 161 | |
Noralf Trønnes | d81294a | 2019-05-31 16:01:11 +0200 | [diff] [blame] | 162 | int drm_client_modeset_create(struct drm_client_dev *client); |
| 163 | void drm_client_modeset_free(struct drm_client_dev *client); |
Noralf Trønnes | cf13909 | 2019-06-08 17:26:55 +0200 | [diff] [blame] | 164 | int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height); |
Maxime Ripard | a99076e | 2019-06-19 12:17:49 +0200 | [diff] [blame] | 165 | bool drm_client_rotation(struct drm_mode_set *modeset, unsigned int *rotation); |
Noralf Trønnes | 64593f2 | 2020-05-09 16:16:13 +0200 | [diff] [blame] | 166 | int drm_client_modeset_check(struct drm_client_dev *client); |
Daniel Vetter | c368ec1 | 2020-02-04 16:01:44 +0100 | [diff] [blame] | 167 | int drm_client_modeset_commit_locked(struct drm_client_dev *client); |
Noralf Trønnes | aec3925 | 2019-05-31 16:01:13 +0200 | [diff] [blame] | 168 | int drm_client_modeset_commit(struct drm_client_dev *client); |
| 169 | int drm_client_modeset_dpms(struct drm_client_dev *client, int mode); |
Noralf Trønnes | d81294a | 2019-05-31 16:01:11 +0200 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * drm_client_for_each_modeset() - Iterate over client modesets |
| 173 | * @modeset: &drm_mode_set loop cursor |
| 174 | * @client: DRM client |
| 175 | */ |
| 176 | #define drm_client_for_each_modeset(modeset, client) \ |
| 177 | for (({ lockdep_assert_held(&(client)->modeset_mutex); }), \ |
| 178 | modeset = (client)->modesets; modeset->crtc; modeset++) |
| 179 | |
Noralf Trønnes | e5852be | 2019-06-08 17:26:53 +0200 | [diff] [blame] | 180 | /** |
| 181 | * drm_client_for_each_connector_iter - connector_list iterator macro |
| 182 | * @connector: &struct drm_connector pointer used as cursor |
| 183 | * @iter: &struct drm_connector_list_iter |
| 184 | * |
| 185 | * This iterates the connectors that are useable for internal clients (excludes |
| 186 | * writeback connectors). |
| 187 | * |
| 188 | * For more info see drm_for_each_connector_iter(). |
| 189 | */ |
| 190 | #define drm_client_for_each_connector_iter(connector, iter) \ |
| 191 | drm_for_each_connector_iter(connector, iter) \ |
| 192 | if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) |
| 193 | |
Wambui Karuga | 7ce84471 | 2020-03-10 16:31:21 +0300 | [diff] [blame] | 194 | void drm_client_debugfs_init(struct drm_minor *minor); |
Noralf Trønnes | e896c132 | 2018-07-03 18:03:51 +0200 | [diff] [blame] | 195 | |
Noralf Trønnes | c76f0f7 | 2018-07-03 18:03:47 +0200 | [diff] [blame] | 196 | #endif |