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> 18c76f0f7cSNoralf Trønnes #include <drm/drm_gem.h> 19c76f0f7cSNoralf Trønnes #include <drm/drm_mode.h> 20c76f0f7cSNoralf Trønnes #include <drm/drm_print.h> 21c76f0f7cSNoralf Trønnes #include <drm/drmP.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 /** 66c76f0f7cSNoralf Trønnes * drm_client_new - Create 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 * 72c76f0f7cSNoralf Trønnes * The caller needs to hold a reference on @dev before calling this function. 73c76f0f7cSNoralf Trønnes * The client is freed when the &drm_device is unregistered. See drm_client_release(). 74c76f0f7cSNoralf Trønnes * 75c76f0f7cSNoralf Trønnes * Returns: 76c76f0f7cSNoralf Trønnes * Zero on success or negative error code on failure. 77c76f0f7cSNoralf Trønnes */ 78c76f0f7cSNoralf Trønnes int drm_client_new(struct drm_device *dev, struct drm_client_dev *client, 79c76f0f7cSNoralf Trønnes const char *name, const struct drm_client_funcs *funcs) 80c76f0f7cSNoralf Trønnes { 81c76f0f7cSNoralf Trønnes int ret; 82c76f0f7cSNoralf Trønnes 83c76f0f7cSNoralf Trønnes if (!drm_core_check_feature(dev, DRIVER_MODESET) || 84c76f0f7cSNoralf Trønnes !dev->driver->dumb_create || !dev->driver->gem_prime_vmap) 85*69fdf420SChris Wilson return -EOPNOTSUPP; 86c76f0f7cSNoralf Trønnes 87c76f0f7cSNoralf Trønnes if (funcs && !try_module_get(funcs->owner)) 88c76f0f7cSNoralf Trønnes return -ENODEV; 89c76f0f7cSNoralf Trønnes 90c76f0f7cSNoralf Trønnes client->dev = dev; 91c76f0f7cSNoralf Trønnes client->name = name; 92c76f0f7cSNoralf Trønnes client->funcs = funcs; 93c76f0f7cSNoralf Trønnes 94c76f0f7cSNoralf Trønnes ret = drm_client_open(client); 95c76f0f7cSNoralf Trønnes if (ret) 96c76f0f7cSNoralf Trønnes goto err_put_module; 97c76f0f7cSNoralf Trønnes 98c76f0f7cSNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 99c76f0f7cSNoralf Trønnes list_add(&client->list, &dev->clientlist); 100c76f0f7cSNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 101c76f0f7cSNoralf Trønnes 102c76f0f7cSNoralf Trønnes drm_dev_get(dev); 103c76f0f7cSNoralf Trønnes 104c76f0f7cSNoralf Trønnes return 0; 105c76f0f7cSNoralf Trønnes 106c76f0f7cSNoralf Trønnes err_put_module: 107c76f0f7cSNoralf Trønnes if (funcs) 108c76f0f7cSNoralf Trønnes module_put(funcs->owner); 109c76f0f7cSNoralf Trønnes 110c76f0f7cSNoralf Trønnes return ret; 111c76f0f7cSNoralf Trønnes } 112c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_new); 113c76f0f7cSNoralf Trønnes 114c76f0f7cSNoralf Trønnes /** 115c76f0f7cSNoralf Trønnes * drm_client_release - Release DRM client resources 116c76f0f7cSNoralf Trønnes * @client: DRM client 117c76f0f7cSNoralf Trønnes * 118c76f0f7cSNoralf Trønnes * Releases resources by closing the &drm_file that was opened by drm_client_new(). 119c76f0f7cSNoralf Trønnes * It is called automatically if the &drm_client_funcs.unregister callback is _not_ set. 120c76f0f7cSNoralf Trønnes * 121c76f0f7cSNoralf Trønnes * This function should only be called from the unregister callback. An exception 122c76f0f7cSNoralf Trønnes * is fbdev which cannot free the buffer if userspace has open file descriptors. 123c76f0f7cSNoralf Trønnes * 124c76f0f7cSNoralf Trønnes * Note: 125c76f0f7cSNoralf Trønnes * Clients cannot initiate a release by themselves. This is done to keep the code simple. 126c76f0f7cSNoralf Trønnes * The driver has to be unloaded before the client can be unloaded. 127c76f0f7cSNoralf Trønnes */ 128c76f0f7cSNoralf Trønnes void drm_client_release(struct drm_client_dev *client) 129c76f0f7cSNoralf Trønnes { 130c76f0f7cSNoralf Trønnes struct drm_device *dev = client->dev; 131c76f0f7cSNoralf Trønnes 132c76f0f7cSNoralf Trønnes DRM_DEV_DEBUG_KMS(dev->dev, "%s\n", client->name); 133c76f0f7cSNoralf Trønnes 134c76f0f7cSNoralf Trønnes drm_client_close(client); 135c76f0f7cSNoralf Trønnes drm_dev_put(dev); 136c76f0f7cSNoralf Trønnes if (client->funcs) 137c76f0f7cSNoralf Trønnes module_put(client->funcs->owner); 138c76f0f7cSNoralf Trønnes } 139c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_release); 140c76f0f7cSNoralf Trønnes 141c76f0f7cSNoralf Trønnes void drm_client_dev_unregister(struct drm_device *dev) 142c76f0f7cSNoralf Trønnes { 143c76f0f7cSNoralf Trønnes struct drm_client_dev *client, *tmp; 144c76f0f7cSNoralf Trønnes 145c76f0f7cSNoralf Trønnes if (!drm_core_check_feature(dev, DRIVER_MODESET)) 146c76f0f7cSNoralf Trønnes return; 147c76f0f7cSNoralf Trønnes 148c76f0f7cSNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 149c76f0f7cSNoralf Trønnes list_for_each_entry_safe(client, tmp, &dev->clientlist, list) { 150c76f0f7cSNoralf Trønnes list_del(&client->list); 151c76f0f7cSNoralf Trønnes if (client->funcs && client->funcs->unregister) { 152c76f0f7cSNoralf Trønnes client->funcs->unregister(client); 153c76f0f7cSNoralf Trønnes } else { 154c76f0f7cSNoralf Trønnes drm_client_release(client); 155c76f0f7cSNoralf Trønnes kfree(client); 156c76f0f7cSNoralf Trønnes } 157c76f0f7cSNoralf Trønnes } 158c76f0f7cSNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 159c76f0f7cSNoralf Trønnes } 160c76f0f7cSNoralf Trønnes 161c76f0f7cSNoralf Trønnes /** 162c76f0f7cSNoralf Trønnes * drm_client_dev_hotplug - Send hotplug event to clients 163c76f0f7cSNoralf Trønnes * @dev: DRM device 164c76f0f7cSNoralf Trønnes * 165c76f0f7cSNoralf Trønnes * This function calls the &drm_client_funcs.hotplug callback on the attached clients. 166c76f0f7cSNoralf Trønnes * 167c76f0f7cSNoralf Trønnes * drm_kms_helper_hotplug_event() calls this function, so drivers that use it 168c76f0f7cSNoralf Trønnes * don't need to call this function themselves. 169c76f0f7cSNoralf Trønnes */ 170c76f0f7cSNoralf Trønnes void drm_client_dev_hotplug(struct drm_device *dev) 171c76f0f7cSNoralf Trønnes { 172c76f0f7cSNoralf Trønnes struct drm_client_dev *client; 173c76f0f7cSNoralf Trønnes int ret; 174c76f0f7cSNoralf Trønnes 175c76f0f7cSNoralf Trønnes if (!drm_core_check_feature(dev, DRIVER_MODESET)) 176c76f0f7cSNoralf Trønnes return; 177c76f0f7cSNoralf Trønnes 178c76f0f7cSNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 179c76f0f7cSNoralf Trønnes list_for_each_entry(client, &dev->clientlist, list) { 180c76f0f7cSNoralf Trønnes if (!client->funcs || !client->funcs->hotplug) 181c76f0f7cSNoralf Trønnes continue; 182c76f0f7cSNoralf Trønnes 183c76f0f7cSNoralf Trønnes ret = client->funcs->hotplug(client); 184c76f0f7cSNoralf Trønnes DRM_DEV_DEBUG_KMS(dev->dev, "%s: ret=%d\n", client->name, ret); 185c76f0f7cSNoralf Trønnes } 186c76f0f7cSNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 187c76f0f7cSNoralf Trønnes } 188c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_dev_hotplug); 189c76f0f7cSNoralf Trønnes 190c76f0f7cSNoralf Trønnes void drm_client_dev_restore(struct drm_device *dev) 191c76f0f7cSNoralf Trønnes { 192c76f0f7cSNoralf Trønnes struct drm_client_dev *client; 193c76f0f7cSNoralf Trønnes int ret; 194c76f0f7cSNoralf Trønnes 195c76f0f7cSNoralf Trønnes if (!drm_core_check_feature(dev, DRIVER_MODESET)) 196c76f0f7cSNoralf Trønnes return; 197c76f0f7cSNoralf Trønnes 198c76f0f7cSNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 199c76f0f7cSNoralf Trønnes list_for_each_entry(client, &dev->clientlist, list) { 200c76f0f7cSNoralf Trønnes if (!client->funcs || !client->funcs->restore) 201c76f0f7cSNoralf Trønnes continue; 202c76f0f7cSNoralf Trønnes 203c76f0f7cSNoralf Trønnes ret = client->funcs->restore(client); 204c76f0f7cSNoralf Trønnes DRM_DEV_DEBUG_KMS(dev->dev, "%s: ret=%d\n", client->name, ret); 205c76f0f7cSNoralf Trønnes if (!ret) /* The first one to return zero gets the privilege to restore */ 206c76f0f7cSNoralf Trønnes break; 207c76f0f7cSNoralf Trønnes } 208c76f0f7cSNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 209c76f0f7cSNoralf Trønnes } 210c76f0f7cSNoralf Trønnes 211c76f0f7cSNoralf Trønnes static void drm_client_buffer_delete(struct drm_client_buffer *buffer) 212c76f0f7cSNoralf Trønnes { 213c76f0f7cSNoralf Trønnes struct drm_device *dev = buffer->client->dev; 214c76f0f7cSNoralf Trønnes 215c76f0f7cSNoralf Trønnes if (buffer->vaddr && dev->driver->gem_prime_vunmap) 216c76f0f7cSNoralf Trønnes dev->driver->gem_prime_vunmap(buffer->gem, buffer->vaddr); 217c76f0f7cSNoralf Trønnes 218c76f0f7cSNoralf Trønnes if (buffer->gem) 219c76f0f7cSNoralf Trønnes drm_gem_object_put_unlocked(buffer->gem); 220c76f0f7cSNoralf Trønnes 221cf19fa2cSNoralf Trønnes if (buffer->handle) 222c76f0f7cSNoralf Trønnes drm_mode_destroy_dumb(dev, buffer->handle, buffer->client->file); 223cf19fa2cSNoralf Trønnes 224c76f0f7cSNoralf Trønnes kfree(buffer); 225c76f0f7cSNoralf Trønnes } 226c76f0f7cSNoralf Trønnes 227c76f0f7cSNoralf Trønnes static struct drm_client_buffer * 228c76f0f7cSNoralf Trønnes drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format) 229c76f0f7cSNoralf Trønnes { 230c76f0f7cSNoralf Trønnes struct drm_mode_create_dumb dumb_args = { }; 231c76f0f7cSNoralf Trønnes struct drm_device *dev = client->dev; 232c76f0f7cSNoralf Trønnes struct drm_client_buffer *buffer; 233c76f0f7cSNoralf Trønnes struct drm_gem_object *obj; 234c76f0f7cSNoralf Trønnes void *vaddr; 235c76f0f7cSNoralf Trønnes int ret; 236c76f0f7cSNoralf Trønnes 237c76f0f7cSNoralf Trønnes buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); 238c76f0f7cSNoralf Trønnes if (!buffer) 239c76f0f7cSNoralf Trønnes return ERR_PTR(-ENOMEM); 240c76f0f7cSNoralf Trønnes 241c76f0f7cSNoralf Trønnes buffer->client = client; 242c76f0f7cSNoralf Trønnes 243c76f0f7cSNoralf Trønnes dumb_args.width = width; 244c76f0f7cSNoralf Trønnes dumb_args.height = height; 245c76f0f7cSNoralf Trønnes dumb_args.bpp = drm_format_plane_cpp(format, 0) * 8; 246c76f0f7cSNoralf Trønnes ret = drm_mode_create_dumb(dev, &dumb_args, client->file); 247c76f0f7cSNoralf Trønnes if (ret) 248cf19fa2cSNoralf Trønnes goto err_delete; 249c76f0f7cSNoralf Trønnes 250c76f0f7cSNoralf Trønnes buffer->handle = dumb_args.handle; 251c76f0f7cSNoralf Trønnes buffer->pitch = dumb_args.pitch; 252c76f0f7cSNoralf Trønnes 253c76f0f7cSNoralf Trønnes obj = drm_gem_object_lookup(client->file, dumb_args.handle); 254c76f0f7cSNoralf Trønnes if (!obj) { 255c76f0f7cSNoralf Trønnes ret = -ENOENT; 256c76f0f7cSNoralf Trønnes goto err_delete; 257c76f0f7cSNoralf Trønnes } 258c76f0f7cSNoralf Trønnes 259c76f0f7cSNoralf Trønnes buffer->gem = obj; 260c76f0f7cSNoralf Trønnes 261c76f0f7cSNoralf Trønnes /* 262c76f0f7cSNoralf Trønnes * FIXME: The dependency on GEM here isn't required, we could 263c76f0f7cSNoralf Trønnes * convert the driver handle to a dma-buf instead and use the 264c76f0f7cSNoralf Trønnes * backend-agnostic dma-buf vmap support instead. This would 265c76f0f7cSNoralf Trønnes * require that the handle2fd prime ioctl is reworked to pull the 266c76f0f7cSNoralf Trønnes * fd_install step out of the driver backend hooks, to make that 267c76f0f7cSNoralf Trønnes * final step optional for internal users. 268c76f0f7cSNoralf Trønnes */ 269c76f0f7cSNoralf Trønnes vaddr = dev->driver->gem_prime_vmap(obj); 270c76f0f7cSNoralf Trønnes if (!vaddr) { 271c76f0f7cSNoralf Trønnes ret = -ENOMEM; 272c76f0f7cSNoralf Trønnes goto err_delete; 273c76f0f7cSNoralf Trønnes } 274c76f0f7cSNoralf Trønnes 275c76f0f7cSNoralf Trønnes buffer->vaddr = vaddr; 276c76f0f7cSNoralf Trønnes 277c76f0f7cSNoralf Trønnes return buffer; 278c76f0f7cSNoralf Trønnes 279c76f0f7cSNoralf Trønnes err_delete: 280c76f0f7cSNoralf Trønnes drm_client_buffer_delete(buffer); 281c76f0f7cSNoralf Trønnes 282c76f0f7cSNoralf Trønnes return ERR_PTR(ret); 283c76f0f7cSNoralf Trønnes } 284c76f0f7cSNoralf Trønnes 285c76f0f7cSNoralf Trønnes static void drm_client_buffer_rmfb(struct drm_client_buffer *buffer) 286c76f0f7cSNoralf Trønnes { 287c76f0f7cSNoralf Trønnes int ret; 288c76f0f7cSNoralf Trønnes 289c76f0f7cSNoralf Trønnes if (!buffer->fb) 290c76f0f7cSNoralf Trønnes return; 291c76f0f7cSNoralf Trønnes 292c76f0f7cSNoralf Trønnes ret = drm_mode_rmfb(buffer->client->dev, buffer->fb->base.id, buffer->client->file); 293c76f0f7cSNoralf Trønnes if (ret) 294c76f0f7cSNoralf Trønnes DRM_DEV_ERROR(buffer->client->dev->dev, 295c76f0f7cSNoralf Trønnes "Error removing FB:%u (%d)\n", buffer->fb->base.id, ret); 296c76f0f7cSNoralf Trønnes 297c76f0f7cSNoralf Trønnes buffer->fb = NULL; 298c76f0f7cSNoralf Trønnes } 299c76f0f7cSNoralf Trønnes 300c76f0f7cSNoralf Trønnes static int drm_client_buffer_addfb(struct drm_client_buffer *buffer, 301c76f0f7cSNoralf Trønnes u32 width, u32 height, u32 format) 302c76f0f7cSNoralf Trønnes { 303c76f0f7cSNoralf Trønnes struct drm_client_dev *client = buffer->client; 304c76f0f7cSNoralf Trønnes struct drm_mode_fb_cmd fb_req = { }; 305c76f0f7cSNoralf Trønnes const struct drm_format_info *info; 306c76f0f7cSNoralf Trønnes int ret; 307c76f0f7cSNoralf Trønnes 308c76f0f7cSNoralf Trønnes info = drm_format_info(format); 309c76f0f7cSNoralf Trønnes fb_req.bpp = info->cpp[0] * 8; 310c76f0f7cSNoralf Trønnes fb_req.depth = info->depth; 311c76f0f7cSNoralf Trønnes fb_req.width = width; 312c76f0f7cSNoralf Trønnes fb_req.height = height; 313c76f0f7cSNoralf Trønnes fb_req.handle = buffer->handle; 314c76f0f7cSNoralf Trønnes fb_req.pitch = buffer->pitch; 315c76f0f7cSNoralf Trønnes 316c76f0f7cSNoralf Trønnes ret = drm_mode_addfb(client->dev, &fb_req, client->file); 317c76f0f7cSNoralf Trønnes if (ret) 318c76f0f7cSNoralf Trønnes return ret; 319c76f0f7cSNoralf Trønnes 320c76f0f7cSNoralf Trønnes buffer->fb = drm_framebuffer_lookup(client->dev, buffer->client->file, fb_req.fb_id); 321c76f0f7cSNoralf Trønnes if (WARN_ON(!buffer->fb)) 322c76f0f7cSNoralf Trønnes return -ENOENT; 323c76f0f7cSNoralf Trønnes 324c76f0f7cSNoralf Trønnes /* drop the reference we picked up in framebuffer lookup */ 325c76f0f7cSNoralf Trønnes drm_framebuffer_put(buffer->fb); 326c76f0f7cSNoralf Trønnes 327c76f0f7cSNoralf Trønnes strscpy(buffer->fb->comm, client->name, TASK_COMM_LEN); 328c76f0f7cSNoralf Trønnes 329c76f0f7cSNoralf Trønnes return 0; 330c76f0f7cSNoralf Trønnes } 331c76f0f7cSNoralf Trønnes 332c76f0f7cSNoralf Trønnes /** 333c76f0f7cSNoralf Trønnes * drm_client_framebuffer_create - Create a client framebuffer 334c76f0f7cSNoralf Trønnes * @client: DRM client 335c76f0f7cSNoralf Trønnes * @width: Framebuffer width 336c76f0f7cSNoralf Trønnes * @height: Framebuffer height 337c76f0f7cSNoralf Trønnes * @format: Buffer format 338c76f0f7cSNoralf Trønnes * 339c76f0f7cSNoralf Trønnes * This function creates a &drm_client_buffer which consists of a 340c76f0f7cSNoralf Trønnes * &drm_framebuffer backed by a dumb buffer. 341c76f0f7cSNoralf Trønnes * Call drm_client_framebuffer_delete() to free the buffer. 342c76f0f7cSNoralf Trønnes * 343c76f0f7cSNoralf Trønnes * Returns: 344c76f0f7cSNoralf Trønnes * Pointer to a client buffer or an error pointer on failure. 345c76f0f7cSNoralf Trønnes */ 346c76f0f7cSNoralf Trønnes struct drm_client_buffer * 347c76f0f7cSNoralf Trønnes drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format) 348c76f0f7cSNoralf Trønnes { 349c76f0f7cSNoralf Trønnes struct drm_client_buffer *buffer; 350c76f0f7cSNoralf Trønnes int ret; 351c76f0f7cSNoralf Trønnes 352c76f0f7cSNoralf Trønnes buffer = drm_client_buffer_create(client, width, height, format); 353c76f0f7cSNoralf Trønnes if (IS_ERR(buffer)) 354c76f0f7cSNoralf Trønnes return buffer; 355c76f0f7cSNoralf Trønnes 356c76f0f7cSNoralf Trønnes ret = drm_client_buffer_addfb(buffer, width, height, format); 357c76f0f7cSNoralf Trønnes if (ret) { 358c76f0f7cSNoralf Trønnes drm_client_buffer_delete(buffer); 359c76f0f7cSNoralf Trønnes return ERR_PTR(ret); 360c76f0f7cSNoralf Trønnes } 361c76f0f7cSNoralf Trønnes 362c76f0f7cSNoralf Trønnes return buffer; 363c76f0f7cSNoralf Trønnes } 364c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_framebuffer_create); 365c76f0f7cSNoralf Trønnes 366c76f0f7cSNoralf Trønnes /** 367c76f0f7cSNoralf Trønnes * drm_client_framebuffer_delete - Delete a client framebuffer 368c76f0f7cSNoralf Trønnes * @buffer: DRM client buffer (can be NULL) 369c76f0f7cSNoralf Trønnes */ 370c76f0f7cSNoralf Trønnes void drm_client_framebuffer_delete(struct drm_client_buffer *buffer) 371c76f0f7cSNoralf Trønnes { 372c76f0f7cSNoralf Trønnes if (!buffer) 373c76f0f7cSNoralf Trønnes return; 374c76f0f7cSNoralf Trønnes 375c76f0f7cSNoralf Trønnes drm_client_buffer_rmfb(buffer); 376c76f0f7cSNoralf Trønnes drm_client_buffer_delete(buffer); 377c76f0f7cSNoralf Trønnes } 378c76f0f7cSNoralf Trønnes EXPORT_SYMBOL(drm_client_framebuffer_delete); 379e896c132SNoralf Trønnes 380e896c132SNoralf Trønnes #ifdef CONFIG_DEBUG_FS 381e896c132SNoralf Trønnes static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data) 382e896c132SNoralf Trønnes { 383e896c132SNoralf Trønnes struct drm_info_node *node = m->private; 384e896c132SNoralf Trønnes struct drm_device *dev = node->minor->dev; 385e896c132SNoralf Trønnes struct drm_printer p = drm_seq_file_printer(m); 386e896c132SNoralf Trønnes struct drm_client_dev *client; 387e896c132SNoralf Trønnes 388e896c132SNoralf Trønnes mutex_lock(&dev->clientlist_mutex); 389e896c132SNoralf Trønnes list_for_each_entry(client, &dev->clientlist, list) 390e896c132SNoralf Trønnes drm_printf(&p, "%s\n", client->name); 391e896c132SNoralf Trønnes mutex_unlock(&dev->clientlist_mutex); 392e896c132SNoralf Trønnes 393e896c132SNoralf Trønnes return 0; 394e896c132SNoralf Trønnes } 395e896c132SNoralf Trønnes 396e896c132SNoralf Trønnes static const struct drm_info_list drm_client_debugfs_list[] = { 397e896c132SNoralf Trønnes { "internal_clients", drm_client_debugfs_internal_clients, 0 }, 398e896c132SNoralf Trønnes }; 399e896c132SNoralf Trønnes 400e896c132SNoralf Trønnes int drm_client_debugfs_init(struct drm_minor *minor) 401e896c132SNoralf Trønnes { 402e896c132SNoralf Trønnes return drm_debugfs_create_files(drm_client_debugfs_list, 403e896c132SNoralf Trønnes ARRAY_SIZE(drm_client_debugfs_list), 404e896c132SNoralf Trønnes minor->debugfs_root, minor); 405e896c132SNoralf Trønnes } 406e896c132SNoralf Trønnes #endif 407