Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * Copyright 2018 Noralf Trønnes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <drm/drm_client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <drm/drm_debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <drm/drm_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <drm/drm_drv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <drm/drm_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <drm/drm_fourcc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <drm/drm_framebuffer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <drm/drm_gem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <drm/drm_mode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <drm/drm_print.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "drm_crtc_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "drm_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * DOC: overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * This library provides support for clients running in the kernel like fbdev and bootsplash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * GEM drivers which provide a GEM based dumb buffer with a virtual address are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static int drm_client_open(struct drm_client_dev *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct drm_device *dev = client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct drm_file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	file = drm_file_alloc(dev->primary);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	if (IS_ERR(file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return PTR_ERR(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	mutex_lock(&dev->filelist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	list_add(&file->lhead, &dev->filelist_internal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	mutex_unlock(&dev->filelist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	client->file = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static void drm_client_close(struct drm_client_dev *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct drm_device *dev = client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	mutex_lock(&dev->filelist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	list_del(&client->file->lhead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	mutex_unlock(&dev->filelist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	drm_file_free(client->file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * drm_client_init - Initialise a DRM client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * @dev: DRM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * @client: DRM client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * @name: Client name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * @funcs: DRM client functions (optional)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * This initialises the client and opens a &drm_file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * Use drm_client_register() to complete the process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * The caller needs to hold a reference on @dev before calling this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * The client is freed when the &drm_device is unregistered. See drm_client_release().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * Zero on success or negative error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) int drm_client_init(struct drm_device *dev, struct drm_client_dev *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		    const char *name, const struct drm_client_funcs *funcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (!drm_core_check_feature(dev, DRIVER_MODESET) || !dev->driver->dumb_create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (funcs && !try_module_get(funcs->owner))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	client->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	client->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	client->funcs = funcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	ret = drm_client_modeset_create(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		goto err_put_module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ret = drm_client_open(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	drm_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	drm_client_modeset_free(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) err_put_module:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (funcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		module_put(funcs->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) EXPORT_SYMBOL(drm_client_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * drm_client_register - Register client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * @client: DRM client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * Add the client to the &drm_device client list to activate its callbacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * @client must be initialized by a call to drm_client_init(). After
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * drm_client_register() it is no longer permissible to call drm_client_release()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * directly (outside the unregister callback), instead cleanup will happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * automatically on driver unload.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) void drm_client_register(struct drm_client_dev *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct drm_device *dev = client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	mutex_lock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	list_add(&client->list, &dev->clientlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	mutex_unlock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) EXPORT_SYMBOL(drm_client_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * drm_client_release - Release DRM client resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * @client: DRM client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * Releases resources by closing the &drm_file that was opened by drm_client_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * It is called automatically if the &drm_client_funcs.unregister callback is _not_ set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * This function should only be called from the unregister callback. An exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * is fbdev which cannot free the buffer if userspace has open file descriptors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * Note:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * Clients cannot initiate a release by themselves. This is done to keep the code simple.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * The driver has to be unloaded before the client can be unloaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void drm_client_release(struct drm_client_dev *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct drm_device *dev = client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	drm_dbg_kms(dev, "%s\n", client->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	drm_client_modeset_free(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	drm_client_close(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	drm_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (client->funcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		module_put(client->funcs->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) EXPORT_SYMBOL(drm_client_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) void drm_client_dev_unregister(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct drm_client_dev *client, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	mutex_lock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	list_for_each_entry_safe(client, tmp, &dev->clientlist, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		list_del(&client->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		if (client->funcs && client->funcs->unregister) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			client->funcs->unregister(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			drm_client_release(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			kfree(client);
^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) 	mutex_unlock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * drm_client_dev_hotplug - Send hotplug event to clients
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * @dev: DRM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * This function calls the &drm_client_funcs.hotplug callback on the attached clients.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * drm_kms_helper_hotplug_event() calls this function, so drivers that use it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * don't need to call this function themselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) void drm_client_dev_hotplug(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct drm_client_dev *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	mutex_lock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	list_for_each_entry(client, &dev->clientlist, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (!client->funcs || !client->funcs->hotplug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		ret = client->funcs->hotplug(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		drm_dbg_kms(dev, "%s: ret=%d\n", client->name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	mutex_unlock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) EXPORT_SYMBOL(drm_client_dev_hotplug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void drm_client_dev_restore(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct drm_client_dev *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	mutex_lock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	list_for_each_entry(client, &dev->clientlist, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (!client->funcs || !client->funcs->restore)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		ret = client->funcs->restore(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		drm_dbg_kms(dev, "%s: ret=%d\n", client->name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (!ret) /* The first one to return zero gets the privilege to restore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	mutex_unlock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static void drm_client_buffer_delete(struct drm_client_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct drm_device *dev = buffer->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	drm_gem_vunmap(buffer->gem, buffer->vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (buffer->gem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		drm_gem_object_put(buffer->gem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (buffer->handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		drm_mode_destroy_dumb(dev, buffer->handle, buffer->client->file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static struct drm_client_buffer *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	const struct drm_format_info *info = drm_format_info(format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct drm_mode_create_dumb dumb_args = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct drm_device *dev = client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct drm_client_buffer *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	struct drm_gem_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	buffer->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	dumb_args.width = width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	dumb_args.height = height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	dumb_args.bpp = info->cpp[0] * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	ret = drm_mode_create_dumb(dev, &dumb_args, client->file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		goto err_delete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	buffer->handle = dumb_args.handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	buffer->pitch = dumb_args.pitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	obj = drm_gem_object_lookup(client->file, dumb_args.handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (!obj)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		goto err_delete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	buffer->gem = obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	return buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) err_delete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	drm_client_buffer_delete(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * drm_client_buffer_vmap - Map DRM client buffer into address space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * @buffer: DRM client buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * This function maps a client buffer into kernel address space. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * buffer is already mapped, it returns the mapping's address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  * Client buffer mappings are not ref'counted. Each call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * drm_client_buffer_vmap() should be followed by a call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * drm_client_buffer_vunmap(); or the client buffer should be mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * throughout its lifetime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  *	The mapped memory's address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) void *drm_client_buffer_vmap(struct drm_client_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	void *vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (buffer->vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return buffer->vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	 * FIXME: The dependency on GEM here isn't required, we could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	 * convert the driver handle to a dma-buf instead and use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	 * backend-agnostic dma-buf vmap support instead. This would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	 * require that the handle2fd prime ioctl is reworked to pull the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	 * fd_install step out of the driver backend hooks, to make that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	 * final step optional for internal users.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	vaddr = drm_gem_vmap(buffer->gem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (IS_ERR(vaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	buffer->vaddr = vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) EXPORT_SYMBOL(drm_client_buffer_vmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * drm_client_buffer_vunmap - Unmap DRM client buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * @buffer: DRM client buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * This function removes a client buffer's memory mapping. Calling this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * function is only required by clients that manage their buffer mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * by themselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) void drm_client_buffer_vunmap(struct drm_client_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	drm_gem_vunmap(buffer->gem, buffer->vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	buffer->vaddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) EXPORT_SYMBOL(drm_client_buffer_vunmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static void drm_client_buffer_rmfb(struct drm_client_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	if (!buffer->fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	ret = drm_mode_rmfb(buffer->client->dev, buffer->fb->base.id, buffer->client->file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		drm_err(buffer->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			"Error removing FB:%u (%d)\n", buffer->fb->base.id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	buffer->fb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static int drm_client_buffer_addfb(struct drm_client_buffer *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 				   u32 width, u32 height, u32 format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	struct drm_client_dev *client = buffer->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	struct drm_mode_fb_cmd fb_req = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	const struct drm_format_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	info = drm_format_info(format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	fb_req.bpp = info->cpp[0] * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	fb_req.depth = info->depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	fb_req.width = width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	fb_req.height = height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	fb_req.handle = buffer->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	fb_req.pitch = buffer->pitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	ret = drm_mode_addfb(client->dev, &fb_req, client->file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	buffer->fb = drm_framebuffer_lookup(client->dev, buffer->client->file, fb_req.fb_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (WARN_ON(!buffer->fb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	/* drop the reference we picked up in framebuffer lookup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	drm_framebuffer_put(buffer->fb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	strscpy(buffer->fb->comm, client->name, TASK_COMM_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * drm_client_framebuffer_create - Create a client framebuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  * @client: DRM client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * @width: Framebuffer width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  * @height: Framebuffer height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  * @format: Buffer format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * This function creates a &drm_client_buffer which consists of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * &drm_framebuffer backed by a dumb buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * Call drm_client_framebuffer_delete() to free the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * Pointer to a client buffer or an error pointer on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct drm_client_buffer *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct drm_client_buffer *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	buffer = drm_client_buffer_create(client, width, height, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (IS_ERR(buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		return buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	ret = drm_client_buffer_addfb(buffer, width, height, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		drm_client_buffer_delete(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	return buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) EXPORT_SYMBOL(drm_client_framebuffer_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  * drm_client_framebuffer_delete - Delete a client framebuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  * @buffer: DRM client buffer (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) void drm_client_framebuffer_delete(struct drm_client_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	drm_client_buffer_rmfb(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	drm_client_buffer_delete(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) EXPORT_SYMBOL(drm_client_framebuffer_delete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * drm_client_framebuffer_flush - Manually flush client framebuffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * @buffer: DRM client buffer (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * @rect: Damage rectangle (if NULL flushes all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * This calls &drm_framebuffer_funcs->dirty (if present) to flush buffer changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * for drivers that need it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * Zero on success or negative error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	if (!buffer || !buffer->fb || !buffer->fb->funcs->dirty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (rect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		struct drm_clip_rect clip = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			.x1 = rect->x1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			.y1 = rect->y1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			.x2 = rect->x2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 			.y2 = rect->y2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		return buffer->fb->funcs->dirty(buffer->fb, buffer->client->file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 						0, 0, &clip, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	return buffer->fb->funcs->dirty(buffer->fb, buffer->client->file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 					0, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) EXPORT_SYMBOL(drm_client_framebuffer_flush);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	struct drm_info_node *node = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	struct drm_device *dev = node->minor->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	struct drm_printer p = drm_seq_file_printer(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	struct drm_client_dev *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	mutex_lock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	list_for_each_entry(client, &dev->clientlist, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		drm_printf(&p, "%s\n", client->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	mutex_unlock(&dev->clientlist_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static const struct drm_info_list drm_client_debugfs_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	{ "internal_clients", drm_client_debugfs_internal_clients, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) void drm_client_debugfs_init(struct drm_minor *minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	drm_debugfs_create_files(drm_client_debugfs_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 				 ARRAY_SIZE(drm_client_debugfs_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 				 minor->debugfs_root, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) #endif