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