Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/client: Move client event handlers to drm_client_event.c

A number of DRM-client functions serve as entry points from device
operations to client code. Moving them info a separate file will later
allow for a more fine-grained kernel configuration. For most of the
users it is sufficient to include <drm/drm_client_event.h> instead of
the full driver-side interface in <drm/drm_client.h>

v2:
- rename new files to drm_client_event.{c,h}

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: Karol Herbst <kherbst@redhat.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Danilo Krummrich <dakr@redhat.com>
Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241014085740.582287-7-tzimmermann@suse.de

+156 -130
+3
Documentation/gpu/drm-client.rst
··· 13 13 14 14 .. kernel-doc:: drivers/gpu/drm/drm_client_modeset.c 15 15 :export: 16 + 17 + .. kernel-doc:: drivers/gpu/drm/drm_client_event.c 18 + :export:
+1
drivers/gpu/drm/Makefile
··· 41 41 drm_bridge.o \ 42 42 drm_cache.o \ 43 43 drm_client.o \ 44 + drm_client_event.o \ 44 45 drm_client_modeset.o \ 45 46 drm_color_mgmt.o \ 46 47 drm_connector.o \
-121
drivers/gpu/drm/drm_client.c
··· 10 10 #include <linux/slab.h> 11 11 12 12 #include <drm/drm_client.h> 13 - #include <drm/drm_debugfs.h> 14 13 #include <drm/drm_device.h> 15 14 #include <drm/drm_drv.h> 16 15 #include <drm/drm_file.h> ··· 170 171 drm_dev_put(dev); 171 172 } 172 173 EXPORT_SYMBOL(drm_client_release); 173 - 174 - /** 175 - * drm_client_dev_unregister - Unregister clients 176 - * @dev: DRM device 177 - * 178 - * This function releases all clients by calling each client's 179 - * &drm_client_funcs.unregister callback. The callback function 180 - * is responsibe for releaseing all resources including the client 181 - * itself. 182 - * 183 - * The helper drm_dev_unregister() calls this function. Drivers 184 - * that use it don't need to call this function themselves. 185 - */ 186 - void drm_client_dev_unregister(struct drm_device *dev) 187 - { 188 - struct drm_client_dev *client, *tmp; 189 - 190 - if (!drm_core_check_feature(dev, DRIVER_MODESET)) 191 - return; 192 - 193 - mutex_lock(&dev->clientlist_mutex); 194 - list_for_each_entry_safe(client, tmp, &dev->clientlist, list) { 195 - list_del(&client->list); 196 - if (client->funcs && client->funcs->unregister) { 197 - client->funcs->unregister(client); 198 - } else { 199 - drm_client_release(client); 200 - kfree(client); 201 - } 202 - } 203 - mutex_unlock(&dev->clientlist_mutex); 204 - } 205 - EXPORT_SYMBOL(drm_client_dev_unregister); 206 - 207 - /** 208 - * drm_client_dev_hotplug - Send hotplug event to clients 209 - * @dev: DRM device 210 - * 211 - * This function calls the &drm_client_funcs.hotplug callback on the attached clients. 212 - * 213 - * drm_kms_helper_hotplug_event() calls this function, so drivers that use it 214 - * don't need to call this function themselves. 215 - */ 216 - void drm_client_dev_hotplug(struct drm_device *dev) 217 - { 218 - struct drm_client_dev *client; 219 - int ret; 220 - 221 - if (!drm_core_check_feature(dev, DRIVER_MODESET)) 222 - return; 223 - 224 - if (!dev->mode_config.num_connector) { 225 - drm_dbg_kms(dev, "No connectors found, will not send hotplug events!\n"); 226 - return; 227 - } 228 - 229 - mutex_lock(&dev->clientlist_mutex); 230 - list_for_each_entry(client, &dev->clientlist, list) { 231 - if (!client->funcs || !client->funcs->hotplug) 232 - continue; 233 - 234 - if (client->hotplug_failed) 235 - continue; 236 - 237 - ret = client->funcs->hotplug(client); 238 - drm_dbg_kms(dev, "%s: ret=%d\n", client->name, ret); 239 - if (ret) 240 - client->hotplug_failed = true; 241 - } 242 - mutex_unlock(&dev->clientlist_mutex); 243 - } 244 - EXPORT_SYMBOL(drm_client_dev_hotplug); 245 - 246 - void drm_client_dev_restore(struct drm_device *dev) 247 - { 248 - struct drm_client_dev *client; 249 - int ret; 250 - 251 - if (!drm_core_check_feature(dev, DRIVER_MODESET)) 252 - return; 253 - 254 - mutex_lock(&dev->clientlist_mutex); 255 - list_for_each_entry(client, &dev->clientlist, list) { 256 - if (!client->funcs || !client->funcs->restore) 257 - continue; 258 - 259 - ret = client->funcs->restore(client); 260 - drm_dbg_kms(dev, "%s: ret=%d\n", client->name, ret); 261 - if (!ret) /* The first one to return zero gets the privilege to restore */ 262 - break; 263 - } 264 - mutex_unlock(&dev->clientlist_mutex); 265 - } 266 174 267 175 static void drm_client_buffer_delete(struct drm_client_buffer *buffer) 268 176 { ··· 490 584 0, 0, NULL, 0); 491 585 } 492 586 EXPORT_SYMBOL(drm_client_framebuffer_flush); 493 - 494 - #ifdef CONFIG_DEBUG_FS 495 - static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data) 496 - { 497 - struct drm_debugfs_entry *entry = m->private; 498 - struct drm_device *dev = entry->dev; 499 - struct drm_printer p = drm_seq_file_printer(m); 500 - struct drm_client_dev *client; 501 - 502 - mutex_lock(&dev->clientlist_mutex); 503 - list_for_each_entry(client, &dev->clientlist, list) 504 - drm_printf(&p, "%s\n", client->name); 505 - mutex_unlock(&dev->clientlist_mutex); 506 - 507 - return 0; 508 - } 509 - 510 - static const struct drm_debugfs_info drm_client_debugfs_list[] = { 511 - { "internal_clients", drm_client_debugfs_internal_clients, 0 }, 512 - }; 513 - 514 - void drm_client_debugfs_init(struct drm_device *dev) 515 - { 516 - drm_debugfs_add_files(dev, drm_client_debugfs_list, 517 - ARRAY_SIZE(drm_client_debugfs_list)); 518 - } 519 - #endif
+135
drivers/gpu/drm/drm_client_event.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 or MIT 2 + /* 3 + * Copyright 2018 Noralf Trønnes 4 + */ 5 + 6 + #include <linux/list.h> 7 + #include <linux/mutex.h> 8 + #include <linux/seq_file.h> 9 + 10 + #include <drm/drm_client.h> 11 + #include <drm/drm_client_event.h> 12 + #include <drm/drm_debugfs.h> 13 + #include <drm/drm_device.h> 14 + #include <drm/drm_drv.h> 15 + #include <drm/drm_print.h> 16 + 17 + /** 18 + * drm_client_dev_unregister - Unregister clients 19 + * @dev: DRM device 20 + * 21 + * This function releases all clients by calling each client's 22 + * &drm_client_funcs.unregister callback. The callback function 23 + * is responsibe for releaseing all resources including the client 24 + * itself. 25 + * 26 + * The helper drm_dev_unregister() calls this function. Drivers 27 + * that use it don't need to call this function themselves. 28 + */ 29 + void drm_client_dev_unregister(struct drm_device *dev) 30 + { 31 + struct drm_client_dev *client, *tmp; 32 + 33 + if (!drm_core_check_feature(dev, DRIVER_MODESET)) 34 + return; 35 + 36 + mutex_lock(&dev->clientlist_mutex); 37 + list_for_each_entry_safe(client, tmp, &dev->clientlist, list) { 38 + list_del(&client->list); 39 + if (client->funcs && client->funcs->unregister) { 40 + client->funcs->unregister(client); 41 + } else { 42 + drm_client_release(client); 43 + kfree(client); 44 + } 45 + } 46 + mutex_unlock(&dev->clientlist_mutex); 47 + } 48 + EXPORT_SYMBOL(drm_client_dev_unregister); 49 + 50 + /** 51 + * drm_client_dev_hotplug - Send hotplug event to clients 52 + * @dev: DRM device 53 + * 54 + * This function calls the &drm_client_funcs.hotplug callback on the attached clients. 55 + * 56 + * drm_kms_helper_hotplug_event() calls this function, so drivers that use it 57 + * don't need to call this function themselves. 58 + */ 59 + void drm_client_dev_hotplug(struct drm_device *dev) 60 + { 61 + struct drm_client_dev *client; 62 + int ret; 63 + 64 + if (!drm_core_check_feature(dev, DRIVER_MODESET)) 65 + return; 66 + 67 + if (!dev->mode_config.num_connector) { 68 + drm_dbg_kms(dev, "No connectors found, will not send hotplug events!\n"); 69 + return; 70 + } 71 + 72 + mutex_lock(&dev->clientlist_mutex); 73 + list_for_each_entry(client, &dev->clientlist, list) { 74 + if (!client->funcs || !client->funcs->hotplug) 75 + continue; 76 + 77 + if (client->hotplug_failed) 78 + continue; 79 + 80 + ret = client->funcs->hotplug(client); 81 + drm_dbg_kms(dev, "%s: ret=%d\n", client->name, ret); 82 + if (ret) 83 + client->hotplug_failed = true; 84 + } 85 + mutex_unlock(&dev->clientlist_mutex); 86 + } 87 + EXPORT_SYMBOL(drm_client_dev_hotplug); 88 + 89 + void drm_client_dev_restore(struct drm_device *dev) 90 + { 91 + struct drm_client_dev *client; 92 + int ret; 93 + 94 + if (!drm_core_check_feature(dev, DRIVER_MODESET)) 95 + return; 96 + 97 + mutex_lock(&dev->clientlist_mutex); 98 + list_for_each_entry(client, &dev->clientlist, list) { 99 + if (!client->funcs || !client->funcs->restore) 100 + continue; 101 + 102 + ret = client->funcs->restore(client); 103 + drm_dbg_kms(dev, "%s: ret=%d\n", client->name, ret); 104 + if (!ret) /* The first one to return zero gets the privilege to restore */ 105 + break; 106 + } 107 + mutex_unlock(&dev->clientlist_mutex); 108 + } 109 + 110 + #ifdef CONFIG_DEBUG_FS 111 + static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data) 112 + { 113 + struct drm_debugfs_entry *entry = m->private; 114 + struct drm_device *dev = entry->dev; 115 + struct drm_printer p = drm_seq_file_printer(m); 116 + struct drm_client_dev *client; 117 + 118 + mutex_lock(&dev->clientlist_mutex); 119 + list_for_each_entry(client, &dev->clientlist, list) 120 + drm_printf(&p, "%s\n", client->name); 121 + mutex_unlock(&dev->clientlist_mutex); 122 + 123 + return 0; 124 + } 125 + 126 + static const struct drm_debugfs_info drm_client_debugfs_list[] = { 127 + { "internal_clients", drm_client_debugfs_internal_clients, 0 }, 128 + }; 129 + 130 + void drm_client_debugfs_init(struct drm_device *dev) 131 + { 132 + drm_debugfs_add_files(dev, drm_client_debugfs_list, 133 + ARRAY_SIZE(drm_client_debugfs_list)); 134 + } 135 + #endif
+1 -1
drivers/gpu/drm/drm_drv.c
··· 38 38 39 39 #include <drm/drm_accel.h> 40 40 #include <drm/drm_cache.h> 41 - #include <drm/drm_client.h> 41 + #include <drm/drm_client_event.h> 42 42 #include <drm/drm_color_mgmt.h> 43 43 #include <drm/drm_drv.h> 44 44 #include <drm/drm_file.h>
+1 -1
drivers/gpu/drm/drm_file.c
··· 40 40 #include <linux/slab.h> 41 41 #include <linux/vga_switcheroo.h> 42 42 43 - #include <drm/drm_client.h> 43 + #include <drm/drm_client_event.h> 44 44 #include <drm/drm_drv.h> 45 45 #include <drm/drm_file.h> 46 46 #include <drm/drm_gem.h>
+1 -1
drivers/gpu/drm/drm_probe_helper.c
··· 33 33 #include <linux/moduleparam.h> 34 34 35 35 #include <drm/drm_bridge.h> 36 - #include <drm/drm_client.h> 36 + #include <drm/drm_client_event.h> 37 37 #include <drm/drm_crtc.h> 38 38 #include <drm/drm_edid.h> 39 39 #include <drm/drm_fourcc.h>
+1 -1
drivers/gpu/drm/i915/display/intel_display_driver.c
··· 11 11 #include <acpi/video.h> 12 12 #include <drm/display/drm_dp_mst_helper.h> 13 13 #include <drm/drm_atomic_helper.h> 14 - #include <drm/drm_client.h> 14 + #include <drm/drm_client_event.h> 15 15 #include <drm/drm_mode_config.h> 16 16 #include <drm/drm_privacy_screen_consumer.h> 17 17 #include <drm/drm_probe_helper.h>
+1 -1
drivers/gpu/drm/nouveau/nouveau_vga.c
··· 2 2 #include <linux/vgaarb.h> 3 3 #include <linux/vga_switcheroo.h> 4 4 5 - #include <drm/drm_fb_helper.h> 5 + #include <drm/drm_client_event.h> 6 6 7 7 #include "nouveau_drv.h" 8 8 #include "nouveau_acpi.h"
-4
include/drm/drm_client.h
··· 121 121 void drm_client_release(struct drm_client_dev *client); 122 122 void drm_client_register(struct drm_client_dev *client); 123 123 124 - void drm_client_dev_unregister(struct drm_device *dev); 125 - void drm_client_dev_hotplug(struct drm_device *dev); 126 - void drm_client_dev_restore(struct drm_device *dev); 127 - 128 124 /** 129 125 * struct drm_client_buffer - DRM client buffer 130 126 */
+12
include/drm/drm_client_event.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 or MIT */ 2 + 3 + #ifndef _DRM_CLIENT_EVENT_H_ 4 + #define _DRM_CLIENT_EVENT_H_ 5 + 6 + struct drm_device; 7 + 8 + void drm_client_dev_unregister(struct drm_device *dev); 9 + void drm_client_dev_hotplug(struct drm_device *dev); 10 + void drm_client_dev_restore(struct drm_device *dev); 11 + 12 + #endif