Skip to content

Commit c47160d

Browse files
committed
drm/mipi-dbi: Remove dependency on GEM CMA helper library
The MIPI DBI helpers access struct drm_gem_cma_object.vaddr in a few places. Replace all instances with the correct generic GEM functions. Use drm_gem_fb_vmap() for mapping a framebuffer's GEM objects and drm_gem_fb_vunmap() for unmapping them. This removes the dependency on CMA helpers within MIPI DBI. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20211106193509.17472-2-tzimmermann@suse.de
1 parent e580ea2 commit c47160d

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

drivers/gpu/drm/drm_mipi_dbi.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
#include <drm/drm_connector.h>
1616
#include <drm/drm_damage_helper.h>
1717
#include <drm/drm_drv.h>
18-
#include <drm/drm_gem_cma_helper.h>
18+
#include <drm/drm_file.h>
1919
#include <drm/drm_format_helper.h>
2020
#include <drm/drm_fourcc.h>
21+
#include <drm/drm_gem.h>
2122
#include <drm/drm_gem_framebuffer_helper.h>
2223
#include <drm/drm_mipi_dbi.h>
2324
#include <drm/drm_modes.h>
@@ -200,13 +201,19 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
200201
struct drm_rect *clip, bool swap)
201202
{
202203
struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0);
203-
struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(gem);
204-
void *src = cma_obj->vaddr;
204+
struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];
205+
struct dma_buf_map data[DRM_FORMAT_MAX_PLANES];
206+
void *src;
205207
int ret;
206208

207209
ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
208210
if (ret)
209211
return ret;
212+
src = data[0].vaddr; /* TODO: Use mapping abstraction properly */
213+
214+
ret = drm_gem_fb_vmap(fb, map, data);
215+
if (ret)
216+
goto out_drm_gem_fb_end_cpu_access;
210217

211218
switch (fb->format->format) {
212219
case DRM_FORMAT_RGB565:
@@ -221,9 +228,11 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
221228
default:
222229
drm_err_once(fb->dev, "Format is not supported: %p4cc\n",
223230
&fb->format->format);
224-
return -EINVAL;
231+
ret = -EINVAL;
225232
}
226233

234+
drm_gem_fb_vunmap(fb, map);
235+
out_drm_gem_fb_end_cpu_access:
227236
drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
228237

229238
return ret;
@@ -249,8 +258,8 @@ static void mipi_dbi_set_window_address(struct mipi_dbi_dev *dbidev,
249258

250259
static void mipi_dbi_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect)
251260
{
252-
struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0);
253-
struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(gem);
261+
struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];
262+
struct dma_buf_map data[DRM_FORMAT_MAX_PLANES];
254263
struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev);
255264
unsigned int height = rect->y2 - rect->y1;
256265
unsigned int width = rect->x2 - rect->x1;
@@ -266,6 +275,10 @@ static void mipi_dbi_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect)
266275
if (!drm_dev_enter(fb->dev, &idx))
267276
return;
268277

278+
ret = drm_gem_fb_vmap(fb, map, data);
279+
if (ret)
280+
goto err_drm_dev_exit;
281+
269282
full = width == fb->width && height == fb->height;
270283

271284
DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect));
@@ -277,7 +290,7 @@ static void mipi_dbi_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect)
277290
if (ret)
278291
goto err_msg;
279292
} else {
280-
tr = cma_obj->vaddr;
293+
tr = data[0].vaddr; /* TODO: Use mapping abstraction properly */
281294
}
282295

283296
mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1,
@@ -289,6 +302,9 @@ static void mipi_dbi_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect)
289302
if (ret)
290303
drm_err_once(fb->dev, "Failed to update display %d\n", ret);
291304

305+
drm_gem_fb_vunmap(fb, map);
306+
307+
err_drm_dev_exit:
292308
drm_dev_exit(idx);
293309
}
294310

@@ -1117,8 +1133,8 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
11171133

11181134
/*
11191135
* Even though it's not the SPI device that does DMA (the master does),
1120-
* the dma mask is necessary for the dma_alloc_wc() in
1121-
* drm_gem_cma_create(). The dma_addr returned will be a physical
1136+
* the dma mask is necessary for the dma_alloc_wc() in the GEM code
1137+
* (e.g., drm_gem_cma_create()). The dma_addr returned will be a physical
11221138
* address which might be different from the bus address, but this is
11231139
* not a problem since the address will not be used.
11241140
* The virtual address is used in the transfer and the SPI core

0 commit comments

Comments
 (0)