1c76f0f7cSNoralf Trønnes // SPDX-License-Identifier: GPL-2.0 2c76f0f7cSNoralf Trønnes /* 3c76f0f7cSNoralf Trønnes * Copyright 2018 Noralf Trønnes 4c76f0f7cSNoralf Trønnes */ 5c76f0f7cSNoralf Trønnes 6c76f0f7cSNoralf Trønnes #include <linux/list.h> 7c76f0f7cSNoralf Trønnes #include <linux/module.h> 8c76f0f7cSNoralf Trønnes #include <linux/mutex.h> 9c76f0f7cSNoralf Trønnes #include <linux/seq_file.h> 10c76f0f7cSNoralf Trønnes #include <linux/slab.h> 11c76f0f7cSNoralf Trønnes 12c76f0f7cSNoralf Trønnes #include <drm/drm_client.h> 13c76f0f7cSNoralf Trønnes #include <drm/drm_debugfs.h> 14c76f0f7cSNoralf Trønnes #include <drm/drm_device.h> 15c76f0f7cSNoralf Trønnes #include <drm/drm_drv.h> 16c76f0f7cSNoralf Trønnes #include <drm/drm_file.h> 17c76f0f7cSNoralf Trønnes #include <drm/drm_fourcc.h> 18*0500c04eSSam Ravnborg #include <drm/drm_framebuffer.h> 19c76f0f7cSNoralf Trønnes #include <drm/drm_gem.h> 20c76f0f7cSNoralf Trønnes #include <drm/drm_mode.h> 21c76f0f7cSNoralf Trønnes #include <drm/drm_print.h> 22c76f0f7cSNoralf Trønnes 23c76f0f7cSNoralf Trønnes #include "drm_crtc_internal.h" 24c76f0f7cSNoralf Trønnes #include "drm_internal.h" 25c76f0f7cSNoralf Trønnes 26c76f0f7cSNoralf Trønnes /** 27c76f0f7cSNoralf Trønnes * DOC: overview 28c76f0f7cSNoralf Trønnes * 29c76f0f7cSNoralf Trønnes * This library provides support for clients running in the kernel like fbdev and bootsplash. 30c76f0f7cSNoralf Trønnes * Currently it's only partially implemented, just enough to support fbdev. 31c76f0f7cSNoralf Trønnes * 32c76f0f7cSNoralf Trønnes * GEM drivers which provide a GEM based dumb buffer with a virtual address are supported. 33c76f0f7cSNoralf Trønnes */ 34c76f0f7cSNoralf Trønnes 35c76f0f7cSNoralf Trønnes static int drm_client_open(struct drm_client_dev *client) 36c76f0f7cSNoralf Trønnes { 37c76f0f7cSNoralf Trønnes struct drm_device *dev = client->dev; 38c76f0f7cSNoralf Trønnes struct drm_file *file; 39c76f0f7cSNoralf Trønnes 40c76f0f7cSNoralf Trønnes file = drm_file_alloc(dev->primary); 41c76f0f7cSNoralf Trønnes if (IS_ERR(file)) 42c76f0f7cSNoralf Trønnes return PTR_ERR(file); 43c76f0f7cSNoralf Trønnes 44c76f0f7cSNoralf Trønnes mutex_lock(&dev->filelist_mutex); 45c76f0f7cSNoralf Trønnes list_add(&file->lhead, &dev->filelist_internal); 46c76f0f7cSNoralf Trønnes mutex_unlock(&dev->filelist_mutex); 47c76f0f7cSNoralf Trønnes 48c76f0f7cSNoralf Trønnes client->file = file; 49c76f0f7cSNoralf Trønnes 50c76f0f7cSNoralf Trønnes return 0; 51c76f0f7cSNoralf Trønnes } 52c76f0f7cSNoralf Trønnes 53c76f0f7cSNoralf Trønnes static void drm_client_close(struct drm_client_dev *client) 54c76f0f7cSNoralf Trønnes { 55c76f0f7cSNoralf Trønnes struct drm_device *dev = client->dev; 56c76f0f7cSNoralf Trønnes 57c76f0f7cSNoralf Trønnes mutex_lock(&dev->filelist_mutex); 58c76f0f7cSNoralf Trønnes list_del(&client->file->lhead); 59c76f0f7cSNoralf Trønnes mutex_unlock(&dev->filelist_mutex); 60c76f0f7cSNoralf Trønnes 61c76f0f7cSNoralf Trønnes drm_file_free(client->file); 62c76f0f7cSNoralf Trønnes } 63c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_close); 64c76f0f7cSNoralf Trønnes 65c76f0f7cSNoralf Trønnes /** 664d4c2d89SNoralf Trønnes * drm_client_init - Initialise a DRM client 67c76f0f7cSNoralf Trønnes * @dev: DRM device 68c76f0f7cSNoralf Trønnes * @client: DRM client 69c76f0f7cSNoralf Trønnes * @name: Client name 70c76f0f7cSNoralf Trønnes * @funcs: DRM client functions (optional) 71c76f0f7cSNoralf Trønnes * 72e33898a2SNoralf Trønnes * This initialises the client and opens a &drm_file. 73e33898a2SNoralf Trønnes * Use drm_client_register() to complete the process. 74c76f0f7cSNoralf Trønnes * The caller needs to hold a reference on @dev before calling this function. 75c76f0f7cSNoralf Trønnes * The client is freed when the &drm_device is unregistered. See drm_client_release(). 76c76f0f7cSNoralf Trønnes * 77c76f0f7cSNoralf Trønnes * Returns: 78c76f0f7cSNoralf Trønnes * Zero on success or negative error code on failure. 79c76f0f7cSNoralf Trønnes */ 804d4c2d89SNoralf Trønnes int drm_client_init(struct drm_device *dev, struct drm_client_dev *client, 81c76f0f7cSNoralf Trønnes const char *name, const struct drm_client_funcs *funcs) 82c76f0f7cSNoralf Trønnes { 83c76f0f7cSNoralf Trønnes int ret; 84c76f0f7cSNoralf Trønnes 85b39b5394SNoralf Trønnes if (!drm_core_check_feature(dev, DRIVER_MODESET) || !dev->driver->dumb_create) 8669fdf420SChris Wilson return -EOPNOTSUPP; 87c76f0f7cSNoralf Trønnes 88c76f0f7cSNoralf Trønnes if (funcs && !try_module_get(funcs->owner)) 89c76f0f7cSNoralf Trønnes return -ENODEV; 90c76f0f7cSNoralf Trønnes 91c76f0f7cSNoralf Trønnes client->dev = dev; 92c76f0f7cSNoralf Trønnes client->name = name; 93c76f0f7cSNoralf Trønnes client->funcs = funcs; 94c76f0f7cSNoralf Trønnes 95c76f0f7cSNoralf Trønnes ret = drm_client_open(client); 96c76f0f7cSNoralf Trønnes if (ret) 97c76f0f7cSNoralf Trønnes goto err_put_module; 98c76f0f7cSNoralf Trønnes 99c76f0f7cSNoralf Trønnes drm_dev_get(dev); 100c76f0f7cSNoralf Trønnes 101c76f0f7cSNoralf Trønnes return 0; 102c76f0f7cSNoralf Trønnes 103c76f0f7cSNoralf Trønnes err_put_module: 104c76f0f7cSNoralf Trønnes if (funcs) 105c76f0f7cSNoralf Trønnes module_put(funcs->owner); 106c76f0f7cSNoralf Trønnes 107c76f0f7cSNoralf Trønnes return ret; 108c76f0f7cSNoralf Trønnes } 1094d4c2d89SNoralf Trønnes EXPORT_SYMBOL(drm_client_init); 1104d4c2d89SNoralf Trønnes 1114d4c2d89SNoralf Trønnes /** 112e33898a2SNoralf Trønnes * drm_client_register - Register client 1134d4c2d89SNoralf Trønnes * @client: DRM client 1144d4c2d89SNoralf Trønnes * 1154d4c2d89SNoralf Trønnes * Add the client to the &drm_device client list to activate its callbacks. 1164d4c2d89SNoralf Trønnes * @client must be initialized by a call to drm_client_init(). After 117e33898a2SNoralf Trønnes * drm_client_register() it is no longer permissible to call drm_client_release() 1184d4c2d89SNoralf Trønnes * directly (outside the unregister callback), instead cleanup will happen 1194d4c2d89SNoralf Trønnes * automatically on driver unload. 1204d4c2d89SNoralf Trønnes */ 121e33898a2SNoralf Trønnes void drm_client_register(struct drm_client_dev *client) 1224d4c2d89SNoralf Trønnes { 1234d4c2d89SNoralf Trønnes struct drm_device *dev = client->dev; 1244d4c2d89SNoralf Trønnes 1254d4c2d89SNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 1264d4c2d89SNoralf Trønnes list_add(&client->list, &dev->clientlist); 1274d4c2d89SNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 1284d4c2d89SNoralf Trønnes } 129e33898a2SNoralf Trønnes EXPORT_SYMBOL(drm_client_register); 130c76f0f7cSNoralf Trønnes 131c76f0f7cSNoralf Trønnes /** 132c76f0f7cSNoralf Trønnes * drm_client_release - Release DRM client resources 133c76f0f7cSNoralf Trønnes * @client: DRM client 134c76f0f7cSNoralf Trønnes * 1354d4c2d89SNoralf Trønnes * Releases resources by closing the &drm_file that was opened by drm_client_init(). 136c76f0f7cSNoralf Trønnes * It is called automatically if the &drm_client_funcs.unregister callback is _not_ set. 137c76f0f7cSNoralf Trønnes * 138c76f0f7cSNoralf Trønnes * This function should only be called from the unregister callback. An exception 139c76f0f7cSNoralf Trønnes * is fbdev which cannot free the buffer if userspace has open file descriptors. 140c76f0f7cSNoralf Trønnes * 141c76f0f7cSNoralf Trønnes * Note: 142c76f0f7cSNoralf Trønnes * Clients cannot initiate a release by themselves. This is done to keep the code simple. 143c76f0f7cSNoralf Trønnes * The driver has to be unloaded before the client can be unloaded. 144c76f0f7cSNoralf Trønnes */ 145c76f0f7cSNoralf Trønnes void drm_client_release(struct drm_client_dev *client) 146c76f0f7cSNoralf Trønnes { 147c76f0f7cSNoralf Trønnes struct drm_device *dev = client->dev; 148c76f0f7cSNoralf Trønnes 149c76f0f7cSNoralf Trønnes DRM_DEV_DEBUG_KMS(dev->dev, "%s\n", client->name); 150c76f0f7cSNoralf Trønnes 151c76f0f7cSNoralf Trønnes drm_client_close(client); 152c76f0f7cSNoralf Trønnes drm_dev_put(dev); 153c76f0f7cSNoralf Trønnes if (client->funcs) 154c76f0f7cSNoralf Trønnes module_put(client->funcs->owner); 155c76f0f7cSNoralf Trønnes } 156c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_release); 157c76f0f7cSNoralf Trønnes 158c76f0f7cSNoralf Trønnes void drm_client_dev_unregister(struct drm_device *dev) 159c76f0f7cSNoralf Trønnes { 160c76f0f7cSNoralf Trønnes struct drm_client_dev *client, *tmp; 161c76f0f7cSNoralf Trønnes 162c76f0f7cSNoralf Trønnes if (!drm_core_check_feature(dev, DRIVER_MODESET)) 163c76f0f7cSNoralf Trønnes return; 164c76f0f7cSNoralf Trønnes 165c76f0f7cSNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 166c76f0f7cSNoralf Trønnes list_for_each_entry_safe(client, tmp, &dev->clientlist, list) { 167c76f0f7cSNoralf Trønnes list_del(&client->list); 168c76f0f7cSNoralf Trønnes if (client->funcs && client->funcs->unregister) { 169c76f0f7cSNoralf Trønnes client->funcs->unregister(client); 170c76f0f7cSNoralf Trønnes } else { 171c76f0f7cSNoralf Trønnes drm_client_release(client); 172c76f0f7cSNoralf Trønnes kfree(client); 173c76f0f7cSNoralf Trønnes } 174c76f0f7cSNoralf Trønnes } 175c76f0f7cSNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 176c76f0f7cSNoralf Trønnes } 177c76f0f7cSNoralf Trønnes 178c76f0f7cSNoralf Trønnes /** 179c76f0f7cSNoralf Trønnes * drm_client_dev_hotplug - Send hotplug event to clients 180c76f0f7cSNoralf Trønnes * @dev: DRM device 181c76f0f7cSNoralf Trønnes * 182c76f0f7cSNoralf Trønnes * This function calls the &drm_client_funcs.hotplug callback on the attached clients. 183c76f0f7cSNoralf Trønnes * 184c76f0f7cSNoralf Trønnes * drm_kms_helper_hotplug_event() calls this function, so drivers that use it 185c76f0f7cSNoralf Trønnes * don't need to call this function themselves. 186c76f0f7cSNoralf Trønnes */ 187c76f0f7cSNoralf Trønnes void drm_client_dev_hotplug(struct drm_device *dev) 188c76f0f7cSNoralf Trønnes { 189c76f0f7cSNoralf Trønnes struct drm_client_dev *client; 190c76f0f7cSNoralf Trønnes int ret; 191c76f0f7cSNoralf Trønnes 192c76f0f7cSNoralf Trønnes if (!drm_core_check_feature(dev, DRIVER_MODESET)) 193c76f0f7cSNoralf Trønnes return; 194c76f0f7cSNoralf Trønnes 195c76f0f7cSNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 196c76f0f7cSNoralf Trønnes list_for_each_entry(client, &dev->clientlist, list) { 197c76f0f7cSNoralf Trønnes if (!client->funcs || !client->funcs->hotplug) 198c76f0f7cSNoralf Trønnes continue; 199c76f0f7cSNoralf Trønnes 200c76f0f7cSNoralf Trønnes ret = client->funcs->hotplug(client); 201c76f0f7cSNoralf Trønnes DRM_DEV_DEBUG_KMS(dev->dev, "%s: ret=%d\n", client->name, ret); 202c76f0f7cSNoralf Trønnes } 203c76f0f7cSNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 204c76f0f7cSNoralf Trønnes } 205c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_dev_hotplug); 206c76f0f7cSNoralf Trønnes 207c76f0f7cSNoralf Trønnes void drm_client_dev_restore(struct drm_device *dev) 208c76f0f7cSNoralf Trønnes { 209c76f0f7cSNoralf Trønnes struct drm_client_dev *client; 210c76f0f7cSNoralf Trønnes int ret; 211c76f0f7cSNoralf Trønnes 212c76f0f7cSNoralf Trønnes if (!drm_core_check_feature(dev, DRIVER_MODESET)) 213c76f0f7cSNoralf Trønnes return; 214c76f0f7cSNoralf Trønnes 215c76f0f7cSNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 216c76f0f7cSNoralf Trønnes list_for_each_entry(client, &dev->clientlist, list) { 217c76f0f7cSNoralf Trønnes if (!client->funcs || !client->funcs->restore) 218c76f0f7cSNoralf Trønnes continue; 219c76f0f7cSNoralf Trønnes 220c76f0f7cSNoralf Trønnes ret = client->funcs->restore(client); 221c76f0f7cSNoralf Trønnes DRM_DEV_DEBUG_KMS(dev->dev, "%s: ret=%d\n", client->name, ret); 222c76f0f7cSNoralf Trønnes if (!ret) /* The first one to return zero gets the privilege to restore */ 223c76f0f7cSNoralf Trønnes break; 224c76f0f7cSNoralf Trønnes } 225c76f0f7cSNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 226c76f0f7cSNoralf Trønnes } 227c76f0f7cSNoralf Trønnes 228c76f0f7cSNoralf Trønnes static void drm_client_buffer_delete(struct drm_client_buffer *buffer) 229c76f0f7cSNoralf Trønnes { 230c76f0f7cSNoralf Trønnes struct drm_device *dev = buffer->client->dev; 231c76f0f7cSNoralf Trønnes 232b39b5394SNoralf Trønnes drm_gem_vunmap(buffer->gem, buffer->vaddr); 233c76f0f7cSNoralf Trønnes 234c76f0f7cSNoralf Trønnes if (buffer->gem) 235c76f0f7cSNoralf Trønnes drm_gem_object_put_unlocked(buffer->gem); 236c76f0f7cSNoralf Trønnes 237cf19fa2cSNoralf Trønnes if (buffer->handle) 238c76f0f7cSNoralf Trønnes drm_mode_destroy_dumb(dev, buffer->handle, buffer->client->file); 239cf19fa2cSNoralf Trønnes 240c76f0f7cSNoralf Trønnes kfree(buffer); 241c76f0f7cSNoralf Trønnes } 242c76f0f7cSNoralf Trønnes 243c76f0f7cSNoralf Trønnes static struct drm_client_buffer * 244c76f0f7cSNoralf Trønnes drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format) 245c76f0f7cSNoralf Trønnes { 24624c478eaSMaxime Ripard const struct drm_format_info *info = drm_format_info(format); 247c76f0f7cSNoralf Trønnes struct drm_mode_create_dumb dumb_args = { }; 248c76f0f7cSNoralf Trønnes struct drm_device *dev = client->dev; 249c76f0f7cSNoralf Trønnes struct drm_client_buffer *buffer; 250c76f0f7cSNoralf Trønnes struct drm_gem_object *obj; 251c76f0f7cSNoralf Trønnes void *vaddr; 252c76f0f7cSNoralf Trønnes int ret; 253c76f0f7cSNoralf Trønnes 254c76f0f7cSNoralf Trønnes buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); 255c76f0f7cSNoralf Trønnes if (!buffer) 256c76f0f7cSNoralf Trønnes return ERR_PTR(-ENOMEM); 257c76f0f7cSNoralf Trønnes 258c76f0f7cSNoralf Trønnes buffer->client = client; 259c76f0f7cSNoralf Trønnes 260c76f0f7cSNoralf Trønnes dumb_args.width = width; 261c76f0f7cSNoralf Trønnes dumb_args.height = height; 262b0f986b4SMaxime Ripard dumb_args.bpp = info->cpp[0] * 8; 263c76f0f7cSNoralf Trønnes ret = drm_mode_create_dumb(dev, &dumb_args, client->file); 264c76f0f7cSNoralf Trønnes if (ret) 265cf19fa2cSNoralf Trønnes goto err_delete; 266c76f0f7cSNoralf Trønnes 267c76f0f7cSNoralf Trønnes buffer->handle = dumb_args.handle; 268c76f0f7cSNoralf Trønnes buffer->pitch = dumb_args.pitch; 269c76f0f7cSNoralf Trønnes 270c76f0f7cSNoralf Trønnes obj = drm_gem_object_lookup(client->file, dumb_args.handle); 271c76f0f7cSNoralf Trønnes if (!obj) { 272c76f0f7cSNoralf Trønnes ret = -ENOENT; 273c76f0f7cSNoralf Trønnes goto err_delete; 274c76f0f7cSNoralf Trønnes } 275c76f0f7cSNoralf Trønnes 276c76f0f7cSNoralf Trønnes buffer->gem = obj; 277c76f0f7cSNoralf Trønnes 278c76f0f7cSNoralf Trønnes /* 279c76f0f7cSNoralf Trønnes * FIXME: The dependency on GEM here isn't required, we could 280c76f0f7cSNoralf Trønnes * convert the driver handle to a dma-buf instead and use the 281c76f0f7cSNoralf Trønnes * backend-agnostic dma-buf vmap support instead. This would 282c76f0f7cSNoralf Trønnes * require that the handle2fd prime ioctl is reworked to pull the 283c76f0f7cSNoralf Trønnes * fd_install step out of the driver backend hooks, to make that 284c76f0f7cSNoralf Trønnes * final step optional for internal users. 285c76f0f7cSNoralf Trønnes */ 286b39b5394SNoralf Trønnes vaddr = drm_gem_vmap(obj); 287b39b5394SNoralf Trønnes if (IS_ERR(vaddr)) { 288b39b5394SNoralf Trønnes ret = PTR_ERR(vaddr); 289c76f0f7cSNoralf Trønnes goto err_delete; 290c76f0f7cSNoralf Trønnes } 291c76f0f7cSNoralf Trønnes 292c76f0f7cSNoralf Trønnes buffer->vaddr = vaddr; 293c76f0f7cSNoralf Trønnes 294c76f0f7cSNoralf Trønnes return buffer; 295c76f0f7cSNoralf Trønnes 296c76f0f7cSNoralf Trønnes err_delete: 297c76f0f7cSNoralf Trønnes drm_client_buffer_delete(buffer); 298c76f0f7cSNoralf Trønnes 299c76f0f7cSNoralf Trønnes return ERR_PTR(ret); 300c76f0f7cSNoralf Trønnes } 301c76f0f7cSNoralf Trønnes 302c76f0f7cSNoralf Trønnes static void drm_client_buffer_rmfb(struct drm_client_buffer *buffer) 303c76f0f7cSNoralf Trønnes { 304c76f0f7cSNoralf Trønnes int ret; 305c76f0f7cSNoralf Trønnes 306c76f0f7cSNoralf Trønnes if (!buffer->fb) 307c76f0f7cSNoralf Trønnes return; 308c76f0f7cSNoralf Trønnes 309c76f0f7cSNoralf Trønnes ret = drm_mode_rmfb(buffer->client->dev, buffer->fb->base.id, buffer->client->file); 310c76f0f7cSNoralf Trønnes if (ret) 311c76f0f7cSNoralf Trønnes DRM_DEV_ERROR(buffer->client->dev->dev, 312c76f0f7cSNoralf Trønnes "Error removing FB:%u (%d)\n", buffer->fb->base.id, ret); 313c76f0f7cSNoralf Trønnes 314c76f0f7cSNoralf Trønnes buffer->fb = NULL; 315c76f0f7cSNoralf Trønnes } 316c76f0f7cSNoralf Trønnes 317c76f0f7cSNoralf Trønnes static int drm_client_buffer_addfb(struct drm_client_buffer *buffer, 318c76f0f7cSNoralf Trønnes u32 width, u32 height, u32 format) 319c76f0f7cSNoralf Trønnes { 320c76f0f7cSNoralf Trønnes struct drm_client_dev *client = buffer->client; 321c76f0f7cSNoralf Trønnes struct drm_mode_fb_cmd fb_req = { }; 322c76f0f7cSNoralf Trønnes const struct drm_format_info *info; 323c76f0f7cSNoralf Trønnes int ret; 324c76f0f7cSNoralf Trønnes 325c76f0f7cSNoralf Trønnes info = drm_format_info(format); 326c76f0f7cSNoralf Trønnes fb_req.bpp = info->cpp[0] * 8; 327c76f0f7cSNoralf Trønnes fb_req.depth = info->depth; 328c76f0f7cSNoralf Trønnes fb_req.width = width; 329c76f0f7cSNoralf Trønnes fb_req.height = height; 330c76f0f7cSNoralf Trønnes fb_req.handle = buffer->handle; 331c76f0f7cSNoralf Trønnes fb_req.pitch = buffer->pitch; 332c76f0f7cSNoralf Trønnes 333c76f0f7cSNoralf Trønnes ret = drm_mode_addfb(client->dev, &fb_req, client->file); 334c76f0f7cSNoralf Trønnes if (ret) 335c76f0f7cSNoralf Trønnes return ret; 336c76f0f7cSNoralf Trønnes 337c76f0f7cSNoralf Trønnes buffer->fb = drm_framebuffer_lookup(client->dev, buffer->client->file, fb_req.fb_id); 338c76f0f7cSNoralf Trønnes if (WARN_ON(!buffer->fb)) 339c76f0f7cSNoralf Trønnes return -ENOENT; 340c76f0f7cSNoralf Trønnes 341c76f0f7cSNoralf Trønnes /* drop the reference we picked up in framebuffer lookup */ 342c76f0f7cSNoralf Trønnes drm_framebuffer_put(buffer->fb); 343c76f0f7cSNoralf Trønnes 344c76f0f7cSNoralf Trønnes strscpy(buffer->fb->comm, client->name, TASK_COMM_LEN); 345c76f0f7cSNoralf Trønnes 346c76f0f7cSNoralf Trønnes return 0; 347c76f0f7cSNoralf Trønnes } 348c76f0f7cSNoralf Trønnes 349c76f0f7cSNoralf Trønnes /** 350c76f0f7cSNoralf Trønnes * drm_client_framebuffer_create - Create a client framebuffer 351c76f0f7cSNoralf Trønnes * @client: DRM client 352c76f0f7cSNoralf Trønnes * @width: Framebuffer width 353c76f0f7cSNoralf Trønnes * @height: Framebuffer height 354c76f0f7cSNoralf Trønnes * @format: Buffer format 355c76f0f7cSNoralf Trønnes * 356c76f0f7cSNoralf Trønnes * This function creates a &drm_client_buffer which consists of a 357c76f0f7cSNoralf Trønnes * &drm_framebuffer backed by a dumb buffer. 358c76f0f7cSNoralf Trønnes * Call drm_client_framebuffer_delete() to free the buffer. 359c76f0f7cSNoralf Trønnes * 360c76f0f7cSNoralf Trønnes * Returns: 361c76f0f7cSNoralf Trønnes * Pointer to a client buffer or an error pointer on failure. 362c76f0f7cSNoralf Trønnes */ 363c76f0f7cSNoralf Trønnes struct drm_client_buffer * 364c76f0f7cSNoralf Trønnes drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format) 365c76f0f7cSNoralf Trønnes { 366c76f0f7cSNoralf Trønnes struct drm_client_buffer *buffer; 367c76f0f7cSNoralf Trønnes int ret; 368c76f0f7cSNoralf Trønnes 369c76f0f7cSNoralf Trønnes buffer = drm_client_buffer_create(client, width, height, format); 370c76f0f7cSNoralf Trønnes if (IS_ERR(buffer)) 371c76f0f7cSNoralf Trønnes return buffer; 372c76f0f7cSNoralf Trønnes 373c76f0f7cSNoralf Trønnes ret = drm_client_buffer_addfb(buffer, width, height, format); 374c76f0f7cSNoralf Trønnes if (ret) { 375c76f0f7cSNoralf Trønnes drm_client_buffer_delete(buffer); 376c76f0f7cSNoralf Trønnes return ERR_PTR(ret); 377c76f0f7cSNoralf Trønnes } 378c76f0f7cSNoralf Trønnes 379c76f0f7cSNoralf Trønnes return buffer; 380c76f0f7cSNoralf Trønnes } 381c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_framebuffer_create); 382c76f0f7cSNoralf Trønnes 383c76f0f7cSNoralf Trønnes /** 384c76f0f7cSNoralf Trønnes * drm_client_framebuffer_delete - Delete a client framebuffer 385c76f0f7cSNoralf Trønnes * @buffer: DRM client buffer (can be NULL) 386c76f0f7cSNoralf Trønnes */ 387c76f0f7cSNoralf Trønnes void drm_client_framebuffer_delete(struct drm_client_buffer *buffer) 388c76f0f7cSNoralf Trønnes { 389c76f0f7cSNoralf Trønnes if (!buffer) 390c76f0f7cSNoralf Trønnes return; 391c76f0f7cSNoralf Trønnes 392c76f0f7cSNoralf Trønnes drm_client_buffer_rmfb(buffer); 393c76f0f7cSNoralf Trønnes drm_client_buffer_delete(buffer); 394c76f0f7cSNoralf Trønnes } 395c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_framebuffer_delete); 396e896c132SNoralf Trønnes 397e896c132SNoralf Trønnes #ifdef CONFIG_DEBUG_FS 398e896c132SNoralf Trønnes static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data) 399e896c132SNoralf Trønnes { 400e896c132SNoralf Trønnes struct drm_info_node *node = m->private; 401e896c132SNoralf Trønnes struct drm_device *dev = node->minor->dev; 402e896c132SNoralf Trønnes struct drm_printer p = drm_seq_file_printer(m); 403e896c132SNoralf Trønnes struct drm_client_dev *client; 404e896c132SNoralf Trønnes 405e896c132SNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 406e896c132SNoralf Trønnes list_for_each_entry(client, &dev->clientlist, list) 407e896c132SNoralf Trønnes drm_printf(&p, "%s\n", client->name); 408e896c132SNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 409e896c132SNoralf Trønnes 410e896c132SNoralf Trønnes return 0; 411e896c132SNoralf Trønnes } 412e896c132SNoralf Trønnes 413e896c132SNoralf Trønnes static const struct drm_info_list drm_client_debugfs_list[] = { 414e896c132SNoralf Trønnes { "internal_clients", drm_client_debugfs_internal_clients, 0 }, 415e896c132SNoralf Trønnes }; 416e896c132SNoralf Trønnes 417e896c132SNoralf Trønnes int drm_client_debugfs_init(struct drm_minor *minor) 418e896c132SNoralf Trønnes { 419e896c132SNoralf Trønnes return drm_debugfs_create_files(drm_client_debugfs_list, 420e896c132SNoralf Trønnes ARRAY_SIZE(drm_client_debugfs_list), 421e896c132SNoralf Trønnes minor->debugfs_root, minor); 422e896c132SNoralf Trønnes } 423e896c132SNoralf Trønnes #endif 424