Skip to content

Commit

Permalink
drm/rockchip: Add GEM create ioctl support
Browse files Browse the repository at this point in the history
Rockchip Socs have GPU, we need allocate GPU accelerated buffers.
So add special ioctls GEM_CREATE to support
accelerated buffers.

Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Tested-by: Daniel Kurtz <djkurtz@chromium.org>
  • Loading branch information
Mark Yao authored and mmind committed Apr 16, 2015
1 parent 20b9ac9 commit 92e4c51
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/gpu/drm/rockchip/rockchip_drm_drv.c
Expand Up @@ -24,6 +24,8 @@
#include <linux/of_graph.h>
#include <linux/component.h>

#include <drm/rockchip_drm.h>

#include "rockchip_drm_drv.h"
#include "rockchip_drm_fb.h"
#include "rockchip_drm_fbdev.h"
Expand Down Expand Up @@ -253,6 +255,11 @@ void rockchip_drm_lastclose(struct drm_device *dev)
drm_fb_helper_restore_fbdev_mode_unlocked(&priv->fbdev_helper);
}

static const struct drm_ioctl_desc rockchip_ioctls[] = {
DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_CREATE, rockchip_gem_create_ioctl,
DRM_UNLOCKED | DRM_AUTH),
};

static const struct file_operations rockchip_drm_driver_fops = {
.owner = THIS_MODULE,
.open = drm_open,
Expand Down Expand Up @@ -292,6 +299,8 @@ static struct drm_driver rockchip_drm_driver = {
.gem_prime_vmap = rockchip_gem_prime_vmap,
.gem_prime_vunmap = rockchip_gem_prime_vunmap,
.gem_prime_mmap = rockchip_gem_mmap_buf,
.ioctls = rockchip_ioctls,
.num_ioctls = ARRAY_SIZE(rockchip_ioctls),
.fops = &rockchip_drm_driver_fops,
.name = DRIVER_NAME,
.desc = DRIVER_DESC,
Expand Down
12 changes: 12 additions & 0 deletions drivers/gpu/drm/rockchip/rockchip_drm_gem.c
Expand Up @@ -16,6 +16,7 @@
#include <drm/drmP.h>
#include <drm/drm_gem.h>
#include <drm/drm_vma_manager.h>
#include <drm/rockchip_drm.h>

#include <linux/dma-attrs.h>

Expand Down Expand Up @@ -253,6 +254,17 @@ int rockchip_gem_dumb_create(struct drm_file *file_priv,
return PTR_ERR_OR_ZERO(rk_obj);
}

int rockchip_gem_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_rockchip_gem_create *args = data;
struct rockchip_gem_object *rk_obj;

rk_obj = rockchip_gem_create_with_handle(file_priv, dev, args->size,
&args->handle);
return PTR_ERR_OR_ZERO(rk_obj);
}

/*
* Allocate a sg_table for this GEM object.
* Note: Both the table's contents, and the sg_table itself must be freed by
Expand Down
12 changes: 12 additions & 0 deletions drivers/gpu/drm/rockchip/rockchip_drm_gem.h
Expand Up @@ -52,4 +52,16 @@ int rockchip_gem_dumb_create(struct drm_file *file_priv,
int rockchip_gem_dumb_map_offset(struct drm_file *file_priv,
struct drm_device *dev, uint32_t handle,
uint64_t *offset);
/*
* request gem object creation and buffer allocation as the size
* that it is calculated with framebuffer information such as width,
* height and bpp.
*/
int rockchip_gem_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv);

/* get buffer offset to map to user space. */
int rockchip_gem_map_offset_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv);

#endif /* _ROCKCHIP_DRM_GEM_H */
57 changes: 57 additions & 0 deletions include/uapi/drm/rockchip_drm.h
@@ -0,0 +1,57 @@
/*
*
* Copyright (c) Fuzhou Rockchip Electronics Co.Ltd
* Authors:
* Mark Yao <yzq@rock-chips.com>
*
* base on exynos_drm.h
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/

#ifndef _UAPI_ROCKCHIP_DRM_H
#define _UAPI_ROCKCHIP_DRM_H

#include <drm/drm.h>

/**
* User-desired buffer creation information structure.
*
* @size: user-desired memory allocation size.
* @flags: user request for setting memory type or cache attributes.
* @handle: returned a handle to created gem object.
* - this handle will be set by gem module of kernel side.
*/
struct drm_rockchip_gem_create {
uint64_t size;
uint32_t flags;
uint32_t handle;
};

/**
* A structure for getting buffer offset.
*
* @handle: a pointer to gem object created.
* @pad: just padding to be 64-bit aligned.
* @offset: relatived offset value of the memory region allocated.
* - this value should be set by user.
*/
struct drm_rockchip_gem_map_off {
uint32_t handle;
uint32_t pad;
uint64_t offset;
};

#define DRM_ROCKCHIP_GEM_CREATE 0x00
#define DRM_ROCKCHIP_GEM_MAP_OFFSET 0x01

#define DRM_IOCTL_ROCKCHIP_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + \
DRM_ROCKCHIP_GEM_CREATE, struct drm_rockchip_gem_create)

#define DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET DRM_IOWR(DRM_COMMAND_BASE + \
DRM_ROCKCHIP_GEM_MAP_OFFSET, struct drm_rockchip_gem_map_off)

#endif /* _UAPI_ROCKCHIP_DRM_H */

0 comments on commit 92e4c51

Please sign in to comment.