| .. | .. |
|---|
| 1 | | -// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 or MIT |
|---|
| 2 | 2 | /* |
|---|
| 3 | 3 | * Copyright 2018 Noralf Trønnes |
|---|
| 4 | 4 | */ |
|---|
| .. | .. |
|---|
| 15 | 15 | #include <drm/drm_drv.h> |
|---|
| 16 | 16 | #include <drm/drm_file.h> |
|---|
| 17 | 17 | #include <drm/drm_fourcc.h> |
|---|
| 18 | +#include <drm/drm_framebuffer.h> |
|---|
| 18 | 19 | #include <drm/drm_gem.h> |
|---|
| 19 | 20 | #include <drm/drm_mode.h> |
|---|
| 20 | 21 | #include <drm/drm_print.h> |
|---|
| 21 | | -#include <drm/drmP.h> |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | #include "drm_crtc_internal.h" |
|---|
| 24 | 24 | #include "drm_internal.h" |
|---|
| .. | .. |
|---|
| 27 | 27 | * DOC: overview |
|---|
| 28 | 28 | * |
|---|
| 29 | 29 | * This library provides support for clients running in the kernel like fbdev and bootsplash. |
|---|
| 30 | | - * Currently it's only partially implemented, just enough to support fbdev. |
|---|
| 31 | 30 | * |
|---|
| 32 | 31 | * GEM drivers which provide a GEM based dumb buffer with a virtual address are supported. |
|---|
| 33 | 32 | */ |
|---|
| .. | .. |
|---|
| 68 | 67 | * @name: Client name |
|---|
| 69 | 68 | * @funcs: DRM client functions (optional) |
|---|
| 70 | 69 | * |
|---|
| 71 | | - * This initialises the client and opens a &drm_file. Use drm_client_add() to complete the process. |
|---|
| 70 | + * This initialises the client and opens a &drm_file. |
|---|
| 71 | + * Use drm_client_register() to complete the process. |
|---|
| 72 | 72 | * The caller needs to hold a reference on @dev before calling this function. |
|---|
| 73 | 73 | * The client is freed when the &drm_device is unregistered. See drm_client_release(). |
|---|
| 74 | 74 | * |
|---|
| .. | .. |
|---|
| 80 | 80 | { |
|---|
| 81 | 81 | int ret; |
|---|
| 82 | 82 | |
|---|
| 83 | | - if (!drm_core_check_feature(dev, DRIVER_MODESET) || |
|---|
| 84 | | - !dev->driver->dumb_create || !dev->driver->gem_prime_vmap) |
|---|
| 85 | | - return -ENOTSUPP; |
|---|
| 83 | + if (!drm_core_check_feature(dev, DRIVER_MODESET) || !dev->driver->dumb_create) |
|---|
| 84 | + return -EOPNOTSUPP; |
|---|
| 86 | 85 | |
|---|
| 87 | 86 | if (funcs && !try_module_get(funcs->owner)) |
|---|
| 88 | 87 | return -ENODEV; |
|---|
| .. | .. |
|---|
| 91 | 90 | client->name = name; |
|---|
| 92 | 91 | client->funcs = funcs; |
|---|
| 93 | 92 | |
|---|
| 94 | | - ret = drm_client_open(client); |
|---|
| 93 | + ret = drm_client_modeset_create(client); |
|---|
| 95 | 94 | if (ret) |
|---|
| 96 | 95 | goto err_put_module; |
|---|
| 96 | + |
|---|
| 97 | + ret = drm_client_open(client); |
|---|
| 98 | + if (ret) |
|---|
| 99 | + goto err_free; |
|---|
| 97 | 100 | |
|---|
| 98 | 101 | drm_dev_get(dev); |
|---|
| 99 | 102 | |
|---|
| 100 | 103 | return 0; |
|---|
| 101 | 104 | |
|---|
| 105 | +err_free: |
|---|
| 106 | + drm_client_modeset_free(client); |
|---|
| 102 | 107 | err_put_module: |
|---|
| 103 | 108 | if (funcs) |
|---|
| 104 | 109 | module_put(funcs->owner); |
|---|
| .. | .. |
|---|
| 108 | 113 | EXPORT_SYMBOL(drm_client_init); |
|---|
| 109 | 114 | |
|---|
| 110 | 115 | /** |
|---|
| 111 | | - * drm_client_add - Add client to the device list |
|---|
| 116 | + * drm_client_register - Register client |
|---|
| 112 | 117 | * @client: DRM client |
|---|
| 113 | 118 | * |
|---|
| 114 | 119 | * Add the client to the &drm_device client list to activate its callbacks. |
|---|
| 115 | 120 | * @client must be initialized by a call to drm_client_init(). After |
|---|
| 116 | | - * drm_client_add() it is no longer permissible to call drm_client_release() |
|---|
| 121 | + * drm_client_register() it is no longer permissible to call drm_client_release() |
|---|
| 117 | 122 | * directly (outside the unregister callback), instead cleanup will happen |
|---|
| 118 | 123 | * automatically on driver unload. |
|---|
| 119 | 124 | */ |
|---|
| 120 | | -void drm_client_add(struct drm_client_dev *client) |
|---|
| 125 | +void drm_client_register(struct drm_client_dev *client) |
|---|
| 121 | 126 | { |
|---|
| 122 | 127 | struct drm_device *dev = client->dev; |
|---|
| 123 | 128 | |
|---|
| .. | .. |
|---|
| 125 | 130 | list_add(&client->list, &dev->clientlist); |
|---|
| 126 | 131 | mutex_unlock(&dev->clientlist_mutex); |
|---|
| 127 | 132 | } |
|---|
| 128 | | -EXPORT_SYMBOL(drm_client_add); |
|---|
| 133 | +EXPORT_SYMBOL(drm_client_register); |
|---|
| 129 | 134 | |
|---|
| 130 | 135 | /** |
|---|
| 131 | 136 | * drm_client_release - Release DRM client resources |
|---|
| .. | .. |
|---|
| 145 | 150 | { |
|---|
| 146 | 151 | struct drm_device *dev = client->dev; |
|---|
| 147 | 152 | |
|---|
| 148 | | - DRM_DEV_DEBUG_KMS(dev->dev, "%s\n", client->name); |
|---|
| 153 | + drm_dbg_kms(dev, "%s\n", client->name); |
|---|
| 149 | 154 | |
|---|
| 155 | + drm_client_modeset_free(client); |
|---|
| 150 | 156 | drm_client_close(client); |
|---|
| 151 | 157 | drm_dev_put(dev); |
|---|
| 152 | 158 | if (client->funcs) |
|---|
| .. | .. |
|---|
| 197 | 203 | continue; |
|---|
| 198 | 204 | |
|---|
| 199 | 205 | ret = client->funcs->hotplug(client); |
|---|
| 200 | | - DRM_DEV_DEBUG_KMS(dev->dev, "%s: ret=%d\n", client->name, ret); |
|---|
| 206 | + drm_dbg_kms(dev, "%s: ret=%d\n", client->name, ret); |
|---|
| 201 | 207 | } |
|---|
| 202 | 208 | mutex_unlock(&dev->clientlist_mutex); |
|---|
| 203 | 209 | } |
|---|
| .. | .. |
|---|
| 217 | 223 | continue; |
|---|
| 218 | 224 | |
|---|
| 219 | 225 | ret = client->funcs->restore(client); |
|---|
| 220 | | - DRM_DEV_DEBUG_KMS(dev->dev, "%s: ret=%d\n", client->name, ret); |
|---|
| 226 | + drm_dbg_kms(dev, "%s: ret=%d\n", client->name, ret); |
|---|
| 221 | 227 | if (!ret) /* The first one to return zero gets the privilege to restore */ |
|---|
| 222 | 228 | break; |
|---|
| 223 | 229 | } |
|---|
| .. | .. |
|---|
| 228 | 234 | { |
|---|
| 229 | 235 | struct drm_device *dev = buffer->client->dev; |
|---|
| 230 | 236 | |
|---|
| 231 | | - if (buffer->vaddr && dev->driver->gem_prime_vunmap) |
|---|
| 232 | | - dev->driver->gem_prime_vunmap(buffer->gem, buffer->vaddr); |
|---|
| 237 | + drm_gem_vunmap(buffer->gem, buffer->vaddr); |
|---|
| 233 | 238 | |
|---|
| 234 | 239 | if (buffer->gem) |
|---|
| 235 | | - drm_gem_object_put_unlocked(buffer->gem); |
|---|
| 240 | + drm_gem_object_put(buffer->gem); |
|---|
| 236 | 241 | |
|---|
| 237 | 242 | if (buffer->handle) |
|---|
| 238 | 243 | drm_mode_destroy_dumb(dev, buffer->handle, buffer->client->file); |
|---|
| .. | .. |
|---|
| 243 | 248 | static struct drm_client_buffer * |
|---|
| 244 | 249 | drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format) |
|---|
| 245 | 250 | { |
|---|
| 251 | + const struct drm_format_info *info = drm_format_info(format); |
|---|
| 246 | 252 | struct drm_mode_create_dumb dumb_args = { }; |
|---|
| 247 | 253 | struct drm_device *dev = client->dev; |
|---|
| 248 | 254 | struct drm_client_buffer *buffer; |
|---|
| 249 | 255 | struct drm_gem_object *obj; |
|---|
| 250 | | - void *vaddr; |
|---|
| 251 | 256 | int ret; |
|---|
| 252 | 257 | |
|---|
| 253 | 258 | buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 258 | 263 | |
|---|
| 259 | 264 | dumb_args.width = width; |
|---|
| 260 | 265 | dumb_args.height = height; |
|---|
| 261 | | - dumb_args.bpp = drm_format_plane_cpp(format, 0) * 8; |
|---|
| 266 | + dumb_args.bpp = info->cpp[0] * 8; |
|---|
| 262 | 267 | ret = drm_mode_create_dumb(dev, &dumb_args, client->file); |
|---|
| 263 | 268 | if (ret) |
|---|
| 264 | 269 | goto err_delete; |
|---|
| .. | .. |
|---|
| 274 | 279 | |
|---|
| 275 | 280 | buffer->gem = obj; |
|---|
| 276 | 281 | |
|---|
| 282 | + return buffer; |
|---|
| 283 | + |
|---|
| 284 | +err_delete: |
|---|
| 285 | + drm_client_buffer_delete(buffer); |
|---|
| 286 | + |
|---|
| 287 | + return ERR_PTR(ret); |
|---|
| 288 | +} |
|---|
| 289 | + |
|---|
| 290 | +/** |
|---|
| 291 | + * drm_client_buffer_vmap - Map DRM client buffer into address space |
|---|
| 292 | + * @buffer: DRM client buffer |
|---|
| 293 | + * |
|---|
| 294 | + * This function maps a client buffer into kernel address space. If the |
|---|
| 295 | + * buffer is already mapped, it returns the mapping's address. |
|---|
| 296 | + * |
|---|
| 297 | + * Client buffer mappings are not ref'counted. Each call to |
|---|
| 298 | + * drm_client_buffer_vmap() should be followed by a call to |
|---|
| 299 | + * drm_client_buffer_vunmap(); or the client buffer should be mapped |
|---|
| 300 | + * throughout its lifetime. |
|---|
| 301 | + * |
|---|
| 302 | + * Returns: |
|---|
| 303 | + * The mapped memory's address |
|---|
| 304 | + */ |
|---|
| 305 | +void *drm_client_buffer_vmap(struct drm_client_buffer *buffer) |
|---|
| 306 | +{ |
|---|
| 307 | + void *vaddr; |
|---|
| 308 | + |
|---|
| 309 | + if (buffer->vaddr) |
|---|
| 310 | + return buffer->vaddr; |
|---|
| 311 | + |
|---|
| 277 | 312 | /* |
|---|
| 278 | 313 | * FIXME: The dependency on GEM here isn't required, we could |
|---|
| 279 | 314 | * convert the driver handle to a dma-buf instead and use the |
|---|
| .. | .. |
|---|
| 282 | 317 | * fd_install step out of the driver backend hooks, to make that |
|---|
| 283 | 318 | * final step optional for internal users. |
|---|
| 284 | 319 | */ |
|---|
| 285 | | - vaddr = dev->driver->gem_prime_vmap(obj); |
|---|
| 286 | | - if (!vaddr) { |
|---|
| 287 | | - ret = -ENOMEM; |
|---|
| 288 | | - goto err_delete; |
|---|
| 289 | | - } |
|---|
| 320 | + vaddr = drm_gem_vmap(buffer->gem); |
|---|
| 321 | + if (IS_ERR(vaddr)) |
|---|
| 322 | + return vaddr; |
|---|
| 290 | 323 | |
|---|
| 291 | 324 | buffer->vaddr = vaddr; |
|---|
| 292 | 325 | |
|---|
| 293 | | - return buffer; |
|---|
| 294 | | - |
|---|
| 295 | | -err_delete: |
|---|
| 296 | | - drm_client_buffer_delete(buffer); |
|---|
| 297 | | - |
|---|
| 298 | | - return ERR_PTR(ret); |
|---|
| 326 | + return vaddr; |
|---|
| 299 | 327 | } |
|---|
| 328 | +EXPORT_SYMBOL(drm_client_buffer_vmap); |
|---|
| 329 | + |
|---|
| 330 | +/** |
|---|
| 331 | + * drm_client_buffer_vunmap - Unmap DRM client buffer |
|---|
| 332 | + * @buffer: DRM client buffer |
|---|
| 333 | + * |
|---|
| 334 | + * This function removes a client buffer's memory mapping. Calling this |
|---|
| 335 | + * function is only required by clients that manage their buffer mappings |
|---|
| 336 | + * by themselves. |
|---|
| 337 | + */ |
|---|
| 338 | +void drm_client_buffer_vunmap(struct drm_client_buffer *buffer) |
|---|
| 339 | +{ |
|---|
| 340 | + drm_gem_vunmap(buffer->gem, buffer->vaddr); |
|---|
| 341 | + buffer->vaddr = NULL; |
|---|
| 342 | +} |
|---|
| 343 | +EXPORT_SYMBOL(drm_client_buffer_vunmap); |
|---|
| 300 | 344 | |
|---|
| 301 | 345 | static void drm_client_buffer_rmfb(struct drm_client_buffer *buffer) |
|---|
| 302 | 346 | { |
|---|
| .. | .. |
|---|
| 307 | 351 | |
|---|
| 308 | 352 | ret = drm_mode_rmfb(buffer->client->dev, buffer->fb->base.id, buffer->client->file); |
|---|
| 309 | 353 | if (ret) |
|---|
| 310 | | - DRM_DEV_ERROR(buffer->client->dev->dev, |
|---|
| 311 | | - "Error removing FB:%u (%d)\n", buffer->fb->base.id, ret); |
|---|
| 354 | + drm_err(buffer->client->dev, |
|---|
| 355 | + "Error removing FB:%u (%d)\n", buffer->fb->base.id, ret); |
|---|
| 312 | 356 | |
|---|
| 313 | 357 | buffer->fb = NULL; |
|---|
| 314 | 358 | } |
|---|
| .. | .. |
|---|
| 322 | 366 | int ret; |
|---|
| 323 | 367 | |
|---|
| 324 | 368 | info = drm_format_info(format); |
|---|
| 325 | | - fb_req.bpp = info->bpp[0]; |
|---|
| 369 | + fb_req.bpp = info->cpp[0] * 8; |
|---|
| 326 | 370 | fb_req.depth = info->depth; |
|---|
| 327 | 371 | fb_req.width = width; |
|---|
| 328 | 372 | fb_req.height = height; |
|---|
| .. | .. |
|---|
| 393 | 437 | } |
|---|
| 394 | 438 | EXPORT_SYMBOL(drm_client_framebuffer_delete); |
|---|
| 395 | 439 | |
|---|
| 440 | +/** |
|---|
| 441 | + * drm_client_framebuffer_flush - Manually flush client framebuffer |
|---|
| 442 | + * @buffer: DRM client buffer (can be NULL) |
|---|
| 443 | + * @rect: Damage rectangle (if NULL flushes all) |
|---|
| 444 | + * |
|---|
| 445 | + * This calls &drm_framebuffer_funcs->dirty (if present) to flush buffer changes |
|---|
| 446 | + * for drivers that need it. |
|---|
| 447 | + * |
|---|
| 448 | + * Returns: |
|---|
| 449 | + * Zero on success or negative error code on failure. |
|---|
| 450 | + */ |
|---|
| 451 | +int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_rect *rect) |
|---|
| 452 | +{ |
|---|
| 453 | + if (!buffer || !buffer->fb || !buffer->fb->funcs->dirty) |
|---|
| 454 | + return 0; |
|---|
| 455 | + |
|---|
| 456 | + if (rect) { |
|---|
| 457 | + struct drm_clip_rect clip = { |
|---|
| 458 | + .x1 = rect->x1, |
|---|
| 459 | + .y1 = rect->y1, |
|---|
| 460 | + .x2 = rect->x2, |
|---|
| 461 | + .y2 = rect->y2, |
|---|
| 462 | + }; |
|---|
| 463 | + |
|---|
| 464 | + return buffer->fb->funcs->dirty(buffer->fb, buffer->client->file, |
|---|
| 465 | + 0, 0, &clip, 1); |
|---|
| 466 | + } |
|---|
| 467 | + |
|---|
| 468 | + return buffer->fb->funcs->dirty(buffer->fb, buffer->client->file, |
|---|
| 469 | + 0, 0, NULL, 0); |
|---|
| 470 | +} |
|---|
| 471 | +EXPORT_SYMBOL(drm_client_framebuffer_flush); |
|---|
| 472 | + |
|---|
| 396 | 473 | #ifdef CONFIG_DEBUG_FS |
|---|
| 397 | 474 | static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data) |
|---|
| 398 | 475 | { |
|---|
| .. | .. |
|---|
| 413 | 490 | { "internal_clients", drm_client_debugfs_internal_clients, 0 }, |
|---|
| 414 | 491 | }; |
|---|
| 415 | 492 | |
|---|
| 416 | | -int drm_client_debugfs_init(struct drm_minor *minor) |
|---|
| 493 | +void drm_client_debugfs_init(struct drm_minor *minor) |
|---|
| 417 | 494 | { |
|---|
| 418 | | - return drm_debugfs_create_files(drm_client_debugfs_list, |
|---|
| 419 | | - ARRAY_SIZE(drm_client_debugfs_list), |
|---|
| 420 | | - minor->debugfs_root, minor); |
|---|
| 495 | + drm_debugfs_create_files(drm_client_debugfs_list, |
|---|
| 496 | + ARRAY_SIZE(drm_client_debugfs_list), |
|---|
| 497 | + minor->debugfs_root, minor); |
|---|
| 421 | 498 | } |
|---|
| 422 | 499 | #endif |
|---|