Skip to content

Commit

Permalink
drm/rockchip: Only alloc a kmap for fbdev gem object
Browse files Browse the repository at this point in the history
In general, the data in drm/rockchip GEM objects is never accessed by
the kernel.  The objects are either accessed by a GPU, by display
controller DMA, or by mmap'ing them to user space.  Thus, these
buffers need not be mapped into kernel address space.

The only exception is the fbdev framebuffer(s), which may be written
in-kernel by fbcon.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
  • Loading branch information
Daniel Kurtz authored and Mark Yao committed Mar 16, 2015
1 parent 03be700 commit f76c83b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int rockchip_drm_fbdev_create(struct drm_fb_helper *helper,

size = mode_cmd.pitches[0] * mode_cmd.height;

rk_obj = rockchip_gem_create_object(dev, size);
rk_obj = rockchip_gem_create_object(dev, size, true);
if (IS_ERR(rk_obj))
return -ENOMEM;

Expand Down
17 changes: 12 additions & 5 deletions drivers/gpu/drm/rockchip/rockchip_drm_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
#include "rockchip_drm_drv.h"
#include "rockchip_drm_gem.h"

static int rockchip_gem_alloc_buf(struct rockchip_gem_object *rk_obj)
static int rockchip_gem_alloc_buf(struct rockchip_gem_object *rk_obj,
bool alloc_kmap)
{
struct drm_gem_object *obj = &rk_obj->base;
struct drm_device *drm = obj->dev;

init_dma_attrs(&rk_obj->dma_attrs);
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &rk_obj->dma_attrs);

/* TODO(djkurtz): Use DMA_ATTR_NO_KERNEL_MAPPING except for fbdev */
if (!alloc_kmap)
dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &rk_obj->dma_attrs);

rk_obj->kvaddr = dma_alloc_attrs(drm->dev, obj->size,
&rk_obj->dma_addr, GFP_KERNEL,
&rk_obj->dma_attrs);
Expand Down Expand Up @@ -103,7 +106,8 @@ int rockchip_gem_mmap(struct file *filp, struct vm_area_struct *vma)
}

struct rockchip_gem_object *
rockchip_gem_create_object(struct drm_device *drm, unsigned int size)
rockchip_gem_create_object(struct drm_device *drm, unsigned int size,
bool alloc_kmap)
{
struct rockchip_gem_object *rk_obj;
struct drm_gem_object *obj;
Expand All @@ -119,7 +123,7 @@ struct rockchip_gem_object *

drm_gem_private_object_init(drm, obj, size);

ret = rockchip_gem_alloc_buf(rk_obj);
ret = rockchip_gem_alloc_buf(rk_obj, alloc_kmap);
if (ret)
goto err_free_rk_obj;

Expand Down Expand Up @@ -163,7 +167,7 @@ rockchip_gem_create_with_handle(struct drm_file *file_priv,
struct drm_gem_object *obj;
int ret;

rk_obj = rockchip_gem_create_object(drm, size);
rk_obj = rockchip_gem_create_object(drm, size, false);
if (IS_ERR(rk_obj))
return ERR_CAST(rk_obj);

Expand Down Expand Up @@ -282,6 +286,9 @@ void *rockchip_gem_prime_vmap(struct drm_gem_object *obj)
{
struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj);

if (dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, &rk_obj->dma_attrs))
return NULL;

return rk_obj->kvaddr;
}

Expand Down
3 changes: 2 additions & 1 deletion drivers/gpu/drm/rockchip/rockchip_drm_gem.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ int rockchip_gem_mmap_buf(struct drm_gem_object *obj,
struct vm_area_struct *vma);

struct rockchip_gem_object *
rockchip_gem_create_object(struct drm_device *drm, unsigned int size);
rockchip_gem_create_object(struct drm_device *drm, unsigned int size,
bool alloc_kmap);

void rockchip_gem_free_object(struct drm_gem_object *obj);

Expand Down

0 comments on commit f76c83b

Please sign in to comment.