Skip to content

Commit cf1ca9a

Browse files
committed
drm/fb-helper: Map DRM client buffer only when required
This patch changes DRM clients to not map the buffer by default. The buffer, like any buffer object, should be mapped and unmapped when needed. An unmapped buffer object can be evicted to system memory and does not consume video ram until displayed. This allows to use generic fbdev emulation with drivers for low-memory devices, such as ast and mgag200. This change affects the generic framebuffer console. HW-based consoles map their console buffer once and keep it mapped. Userspace can mmap this buffer into its address space. The shadow-buffered framebuffer console only needs the buffer object to be mapped during updates. While not being updated from the shadow buffer, the buffer object can remain unmapped. Userspace will always mmap the shadow buffer. v2: * change DRM client to not map buffer by default * manually map client buffer for fbdev with HW framebuffer Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Noralf Trønnes <noralf@tronnes.org> Link: https://patchwork.freedesktop.org/patch/315830/
1 parent 15dd0fc commit cf1ca9a

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

‎drivers/gpu/drm/drm_client.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u
254254
struct drm_device *dev = client->dev;
255255
struct drm_client_buffer *buffer;
256256
struct drm_gem_object *obj;
257-
void *vaddr;
258257
int ret;
259258

260259
buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
@@ -281,12 +280,6 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u
281280

282281
buffer->gem = obj;
283282

284-
vaddr = drm_client_buffer_vmap(buffer);
285-
if (IS_ERR(vaddr)) {
286-
ret = PTR_ERR(vaddr);
287-
goto err_delete;
288-
}
289-
290283
return buffer;
291284

292285
err_delete:
@@ -305,7 +298,7 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u
305298
* Client buffer mappings are not ref'counted. Each call to
306299
* drm_client_buffer_vmap() should be followed by a call to
307300
* drm_client_buffer_vunmap(); or the client buffer should be mapped
308-
* throughout its lifetime. The latter is the default.
301+
* throughout its lifetime.
309302
*
310303
* Returns:
311304
* The mapped memory's address
@@ -339,10 +332,9 @@ EXPORT_SYMBOL(drm_client_buffer_vmap);
339332
* drm_client_buffer_vunmap - Unmap DRM client buffer
340333
* @buffer: DRM client buffer
341334
*
342-
* This function removes a client buffer's memory mapping. This
343-
* function is only required by clients that manage their buffers
344-
* by themselves. By default, DRM client buffers are mapped throughout
345-
* their entire lifetime.
335+
* This function removes a client buffer's memory mapping. Calling this
336+
* function is only required by clients that manage their buffer mappings
337+
* by themselves.
346338
*/
347339
void drm_client_buffer_vunmap(struct drm_client_buffer *buffer)
348340
{

‎drivers/gpu/drm/drm_fb_helper.c‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ static void drm_fb_helper_dirty_work(struct work_struct *work)
403403
struct drm_clip_rect *clip = &helper->dirty_clip;
404404
struct drm_clip_rect clip_copy;
405405
unsigned long flags;
406+
void *vaddr;
406407

407408
spin_lock_irqsave(&helper->dirty_lock, flags);
408409
clip_copy = *clip;
@@ -412,10 +413,18 @@ static void drm_fb_helper_dirty_work(struct work_struct *work)
412413

413414
/* call dirty callback only when it has been really touched */
414415
if (clip_copy.x1 < clip_copy.x2 && clip_copy.y1 < clip_copy.y2) {
416+
415417
/* Generic fbdev uses a shadow buffer */
416-
if (helper->buffer)
418+
if (helper->buffer) {
419+
vaddr = drm_client_buffer_vmap(helper->buffer);
420+
if (IS_ERR(vaddr))
421+
return;
417422
drm_fb_helper_dirty_blit_real(helper, &clip_copy);
423+
}
418424
helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, &clip_copy, 1);
425+
426+
if (helper->buffer)
427+
drm_client_buffer_vunmap(helper->buffer);
419428
}
420429
}
421430

@@ -2178,6 +2187,7 @@ int drm_fb_helper_generic_probe(struct drm_fb_helper *fb_helper,
21782187
struct drm_framebuffer *fb;
21792188
struct fb_info *fbi;
21802189
u32 format;
2190+
void *vaddr;
21812191

21822192
DRM_DEBUG_KMS("surface width(%d), height(%d) and bpp(%d)\n",
21832193
sizes->surface_width, sizes->surface_height,
@@ -2200,13 +2210,7 @@ int drm_fb_helper_generic_probe(struct drm_fb_helper *fb_helper,
22002210
fbi->fbops = &drm_fbdev_fb_ops;
22012211
fbi->screen_size = fb->height * fb->pitches[0];
22022212
fbi->fix.smem_len = fbi->screen_size;
2203-
fbi->screen_buffer = buffer->vaddr;
2204-
/* Shamelessly leak the physical address to user-space */
2205-
#if IS_ENABLED(CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM)
2206-
if (drm_leak_fbdev_smem && fbi->fix.smem_start == 0)
2207-
fbi->fix.smem_start =
2208-
page_to_phys(virt_to_page(fbi->screen_buffer));
2209-
#endif
2213+
22102214
drm_fb_helper_fill_info(fbi, fb_helper, sizes);
22112215

22122216
if (fb->funcs->dirty) {
@@ -2231,6 +2235,19 @@ int drm_fb_helper_generic_probe(struct drm_fb_helper *fb_helper,
22312235
fbi->fbdefio = &drm_fbdev_defio;
22322236

22332237
fb_deferred_io_init(fbi);
2238+
} else {
2239+
/* buffer is mapped for HW framebuffer */
2240+
vaddr = drm_client_buffer_vmap(fb_helper->buffer);
2241+
if (IS_ERR(vaddr))
2242+
return PTR_ERR(vaddr);
2243+
2244+
fbi->screen_buffer = vaddr;
2245+
/* Shamelessly leak the physical address to user-space */
2246+
#if IS_ENABLED(CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM)
2247+
if (drm_leak_fbdev_smem && fbi->fix.smem_start == 0)
2248+
fbi->fix.smem_start =
2249+
page_to_phys(virt_to_page(fbi->screen_buffer));
2250+
#endif
22342251
}
22352252

22362253
return 0;

0 commit comments

Comments
 (0)