Lines Matching +full:simple +full:- +full:framebuffer

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drm gem framebuffer helper functions
8 #include <linux/dma-buf.h>
9 #include <linux/dma-fence.h>
10 #include <linux/dma-resv.h>
43 * drm_gem_fb_get_obj() - Get GEM object backing the framebuffer
44 * @fb: Framebuffer
51 * Pointer to &drm_gem_object for the given framebuffer and plane index or NULL
60 return fb->obj[plane]; in drm_gem_fb_get_obj()
76 fb->obj[i] = obj[i]; in drm_gem_fb_init()
80 drm_err(dev, "Failed to init framebuffer: %d\n", ret); in drm_gem_fb_init()
86 * drm_gem_fb_destroy - Free GEM backed framebuffer
87 * @fb: Framebuffer
89 * Frees a GEM backed framebuffer with its backing buffer(s) and the structure
90 * itself. Drivers can use this as their &drm_framebuffer_funcs->destroy
98 drm_gem_object_put(fb->obj[i]); in drm_gem_fb_destroy()
106 * drm_gem_fb_create_handle - Create handle for GEM backed framebuffer
107 * @fb: Framebuffer
111 * This function creates a handle for the GEM object backing the framebuffer.
112 * Drivers can use this as their &drm_framebuffer_funcs->create_handle
121 return drm_gem_handle_create(file, fb->obj[0], handle); in drm_gem_fb_create_handle()
126 * drm_gem_fb_init_with_funcs() - Helper function for implementing
132 * @fb: framebuffer object
133 * @file: DRM file that holds the GEM handle(s) backing the framebuffer
134 * @mode_cmd: Metadata from the userspace framebuffer creation request
135 * @funcs: vtable to be used for the new framebuffer object
138 * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
142 * non-conflicting.
159 return -EINVAL; in drm_gem_fb_init_with_funcs()
161 for (i = 0; i < info->num_planes; i++) { in drm_gem_fb_init_with_funcs()
162 unsigned int width = mode_cmd->width / (i ? info->hsub : 1); in drm_gem_fb_init_with_funcs()
163 unsigned int height = mode_cmd->height / (i ? info->vsub : 1); in drm_gem_fb_init_with_funcs()
166 objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]); in drm_gem_fb_init_with_funcs()
169 ret = -ENOENT; in drm_gem_fb_init_with_funcs()
173 min_size = (height - 1) * mode_cmd->pitches[i] in drm_gem_fb_init_with_funcs()
175 + mode_cmd->offsets[i]; in drm_gem_fb_init_with_funcs()
177 if (objs[i]->size < min_size) { in drm_gem_fb_init_with_funcs()
179 ret = -EINVAL; in drm_gem_fb_init_with_funcs()
191 for (i--; i >= 0; i--) in drm_gem_fb_init_with_funcs()
199 * drm_gem_fb_create_with_funcs() - Helper function for the
203 * @file: DRM file that holds the GEM handle(s) backing the framebuffer
204 * @mode_cmd: Metadata from the userspace framebuffer creation request
205 * @funcs: vtable to be used for the new framebuffer object
208 * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
224 return ERR_PTR(-ENOMEM); in drm_gem_fb_create_with_funcs()
242 * drm_gem_fb_create() - Helper function for the
245 * @file: DRM file that holds the GEM handle(s) backing the framebuffer
246 * @mode_cmd: Metadata from the userspace framebuffer creation request
248 * This function creates a new framebuffer object described by
250 * backing the framebuffer.
254 * validation. Use drm_gem_fb_create_with_dirty() if you need framebuffer
279 * drm_gem_fb_create_with_dirty() - Helper function for the
282 * @file: DRM file that holds the GEM handle(s) backing the framebuffer
283 * @mode_cmd: Metadata from the userspace framebuffer creation request
285 * This function creates a new framebuffer object described by
287 * backing the framebuffer. drm_atomic_helper_dirtyfb() is used for the dirty
288 * callback giving framebuffer flushing through the atomic machinery. Use
318 if (info->cpp[0]) in drm_gem_afbc_get_bpp()
319 return info->cpp[0] * 8; in drm_gem_afbc_get_bpp()
322 switch (info->format) { in drm_gem_afbc_get_bpp()
345 switch (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) { in drm_gem_afbc_min_size()
347 afbc_fb->block_width = 16; in drm_gem_afbc_min_size()
348 afbc_fb->block_height = 16; in drm_gem_afbc_min_size()
351 afbc_fb->block_width = 32; in drm_gem_afbc_min_size()
352 afbc_fb->block_height = 8; in drm_gem_afbc_min_size()
354 /* no user exists yet - fall through */ in drm_gem_afbc_min_size()
359 mode_cmd->modifier[0] in drm_gem_afbc_min_size()
361 return -EINVAL; in drm_gem_afbc_min_size()
365 w_alignment = afbc_fb->block_width; in drm_gem_afbc_min_size()
366 h_alignment = afbc_fb->block_height; in drm_gem_afbc_min_size()
368 if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { in drm_gem_afbc_min_size()
374 afbc_fb->aligned_width = ALIGN(mode_cmd->width, w_alignment); in drm_gem_afbc_min_size()
375 afbc_fb->aligned_height = ALIGN(mode_cmd->height, h_alignment); in drm_gem_afbc_min_size()
376 afbc_fb->offset = mode_cmd->offsets[0]; in drm_gem_afbc_min_size()
381 return -EINVAL; in drm_gem_afbc_min_size()
384 n_blocks = (afbc_fb->aligned_width * afbc_fb->aligned_height) in drm_gem_afbc_min_size()
386 afbc_fb->afbc_size = ALIGN(n_blocks * AFBC_HEADER_SIZE, hdr_alignment); in drm_gem_afbc_min_size()
387 afbc_fb->afbc_size += n_blocks * ALIGN(bpp * AFBC_SUPERBLOCK_PIXELS / 8, in drm_gem_afbc_min_size()
394 * drm_gem_fb_afbc_init() - Helper function for drivers using afbc to
395 * fill and validate all the afbc-specific
399 * @afbc_fb: afbc-specific framebuffer
400 * @mode_cmd: Metadata from the userspace framebuffer creation request
401 * @afbc_fb: afbc framebuffer
406 * It is caller's responsibility to put afbc_fb->base.obj objects in case
420 objs = afbc_fb->base.obj; in drm_gem_fb_afbc_init()
423 return -EINVAL; in drm_gem_fb_afbc_init()
429 if (objs[0]->size < afbc_fb->afbc_size) in drm_gem_fb_afbc_init()
430 return -EINVAL; in drm_gem_fb_afbc_init()
437 * drm_gem_fb_prepare_fb() - Prepare a GEM backed framebuffer
447 * There is no need for &drm_plane_helper_funcs.cleanup_fb hook for simple
448 * gem based framebuffer drivers which have their buffers always pinned in
460 if (!state->fb) in drm_gem_fb_prepare_fb()
463 obj = drm_gem_fb_get_obj(state->fb, 0); in drm_gem_fb_prepare_fb()
464 fence = dma_resv_get_excl_rcu(obj->resv); in drm_gem_fb_prepare_fb()
472 * drm_gem_fb_simple_display_pipe_prepare_fb - prepare_fb helper for
474 * @pipe: Simple display pipe
489 return drm_gem_fb_prepare_fb(&pipe->plane, plane_state); in drm_gem_fb_simple_display_pipe_prepare_fb()