@@ -56,6 +56,49 @@ struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb,
}
EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj);
+static void *drm_fb_cma_fb_panic_vmap(struct drm_framebuffer *fb)
+{
+ return drm_fb_cma_get_gem_obj(fb, 0)->vaddr;
+}
+
+static const struct drm_framebuffer_funcs drm_fb_cma_fb_funcs = {
+ .destroy = drm_gem_fb_destroy,
+ .create_handle = drm_gem_fb_create_handle,
+ .panic_vmap = drm_fb_cma_fb_panic_vmap,
+};
+
+/**
+ * drm_fb_cma_fb_create() - &drm_mode_config_funcs.fb_create callback function
+ * @dev: DRM device
+ * @file: DRM file that holds the GEM handle(s) backing the framebuffer
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ *
+ * This function creates a new framebuffer object described by
+ * &drm_mode_fb_cmd2. This description includes handles for the buffer(s)
+ * backing the framebuffer.
+ *
+ * If your hardware has special alignment or pitch requirements these should be
+ * checked before calling this function. The function does buffer size
+ * validation.
+ *
+ * Drivers can use this as their &drm_mode_config_funcs.fb_create callback.
+ * The ADDFB2 IOCTL calls into this callback.
+ *
+ * The &drm_framebuffer_funcs.panic_vmap() callback is set supporting panic
+ * screen rendering.
+ *
+ * Returns:
+ * Pointer to a &drm_framebuffer on success or an error pointer on failure.
+ */
+struct drm_framebuffer *
+drm_fb_cma_fb_create(struct drm_device *dev, struct drm_file *file,
+ const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+ return drm_gem_fb_create_with_funcs(dev, file, mode_cmd,
+ &drm_fb_cma_fb_funcs);
+}
+EXPORT_SYMBOL_GPL(drm_fb_cma_fb_create);
+
/**
* drm_fb_cma_get_gem_addr() - Get physical address for framebuffer, for pixel
* formats where values are grouped in blocks this will get you the beginning of
@@ -507,6 +507,9 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
cma_obj->paddr = sg_dma_address(sgt->sgl);
cma_obj->sgt = sgt;
+ /* Try to vmap the buffer to support panic rendering */
+ cma_obj->vaddr = dma_buf_vmap(attach->dmabuf);
+
DRM_DEBUG_PRIME("dma_addr = %pad, size = %zu\n", &cma_obj->paddr, attach->dmabuf->size);
return &cma_obj->base;
@@ -7,7 +7,9 @@ struct drm_plane_state;
struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb,
unsigned int plane);
-
+struct drm_framebuffer *
+drm_fb_cma_fb_create(struct drm_device *dev, struct drm_file *file,
+ const struct drm_mode_fb_cmd2 *mode_cmd);
dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb,
struct drm_plane_state *state,
unsigned int plane);
Add drm_fb_cma_fb_create() which creates a framebuffer that supports panic message output. vmap PRIME buffers on import to support panic on those as well. There is no atomic way to get a virtual address on a dma_buf. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> --- drivers/gpu/drm/drm_fb_cma_helper.c | 43 ++++++++++++++++++++++++++++ drivers/gpu/drm/drm_gem_cma_helper.c | 3 ++ include/drm/drm_fb_cma_helper.h | 4 ++- 3 files changed, 49 insertions(+), 1 deletion(-)