2012-05-17 19:06:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Samsung Electronics Co.Ltd
|
|
|
|
* Authors: Joonyoung Shim <jy0922.shim@samsung.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundationr
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/workqueue.h>
|
2012-11-04 12:53:24 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/dma-attrs.h>
|
2013-02-06 13:29:44 +08:00
|
|
|
#include <linux/of.h>
|
2012-05-17 19:06:32 +08:00
|
|
|
|
2012-10-03 01:01:07 +08:00
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/exynos_drm.h>
|
2012-05-17 19:06:32 +08:00
|
|
|
#include "exynos_drm_drv.h"
|
2013-08-13 07:46:40 +08:00
|
|
|
#include "exynos_drm_g2d.h"
|
2012-05-17 19:06:32 +08:00
|
|
|
#include "exynos_drm_gem.h"
|
2012-11-04 12:53:24 +08:00
|
|
|
#include "exynos_drm_iommu.h"
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
#define G2D_HW_MAJOR_VER 4
|
|
|
|
#define G2D_HW_MINOR_VER 1
|
|
|
|
|
|
|
|
/* vaild register range set from user: 0x0104 ~ 0x0880 */
|
|
|
|
#define G2D_VALID_START 0x0104
|
|
|
|
#define G2D_VALID_END 0x0880
|
|
|
|
|
|
|
|
/* general registers */
|
|
|
|
#define G2D_SOFT_RESET 0x0000
|
|
|
|
#define G2D_INTEN 0x0004
|
|
|
|
#define G2D_INTC_PEND 0x000C
|
|
|
|
#define G2D_DMA_SFR_BASE_ADDR 0x0080
|
|
|
|
#define G2D_DMA_COMMAND 0x0084
|
|
|
|
#define G2D_DMA_STATUS 0x008C
|
|
|
|
#define G2D_DMA_HOLD_CMD 0x0090
|
|
|
|
|
|
|
|
/* command registers */
|
|
|
|
#define G2D_BITBLT_START 0x0100
|
|
|
|
|
|
|
|
/* registers for base address */
|
|
|
|
#define G2D_SRC_BASE_ADDR 0x0304
|
2016-05-25 20:42:56 +08:00
|
|
|
#define G2D_SRC_STRIDE 0x0308
|
2013-03-11 20:17:52 +08:00
|
|
|
#define G2D_SRC_COLOR_MODE 0x030C
|
|
|
|
#define G2D_SRC_LEFT_TOP 0x0310
|
|
|
|
#define G2D_SRC_RIGHT_BOTTOM 0x0314
|
2012-05-17 19:06:32 +08:00
|
|
|
#define G2D_SRC_PLANE2_BASE_ADDR 0x0318
|
|
|
|
#define G2D_DST_BASE_ADDR 0x0404
|
2016-05-25 20:42:56 +08:00
|
|
|
#define G2D_DST_STRIDE 0x0408
|
2013-03-11 20:17:52 +08:00
|
|
|
#define G2D_DST_COLOR_MODE 0x040C
|
|
|
|
#define G2D_DST_LEFT_TOP 0x0410
|
|
|
|
#define G2D_DST_RIGHT_BOTTOM 0x0414
|
2012-05-17 19:06:32 +08:00
|
|
|
#define G2D_DST_PLANE2_BASE_ADDR 0x0418
|
|
|
|
#define G2D_PAT_BASE_ADDR 0x0500
|
|
|
|
#define G2D_MSK_BASE_ADDR 0x0520
|
|
|
|
|
|
|
|
/* G2D_SOFT_RESET */
|
|
|
|
#define G2D_SFRCLEAR (1 << 1)
|
|
|
|
#define G2D_R (1 << 0)
|
|
|
|
|
|
|
|
/* G2D_INTEN */
|
|
|
|
#define G2D_INTEN_ACF (1 << 3)
|
|
|
|
#define G2D_INTEN_UCF (1 << 2)
|
|
|
|
#define G2D_INTEN_GCF (1 << 1)
|
|
|
|
#define G2D_INTEN_SCF (1 << 0)
|
|
|
|
|
|
|
|
/* G2D_INTC_PEND */
|
|
|
|
#define G2D_INTP_ACMD_FIN (1 << 3)
|
|
|
|
#define G2D_INTP_UCMD_FIN (1 << 2)
|
|
|
|
#define G2D_INTP_GCMD_FIN (1 << 1)
|
|
|
|
#define G2D_INTP_SCMD_FIN (1 << 0)
|
|
|
|
|
|
|
|
/* G2D_DMA_COMMAND */
|
|
|
|
#define G2D_DMA_HALT (1 << 2)
|
|
|
|
#define G2D_DMA_CONTINUE (1 << 1)
|
|
|
|
#define G2D_DMA_START (1 << 0)
|
|
|
|
|
|
|
|
/* G2D_DMA_STATUS */
|
|
|
|
#define G2D_DMA_LIST_DONE_COUNT (0xFF << 17)
|
|
|
|
#define G2D_DMA_BITBLT_DONE_COUNT (0xFFFF << 1)
|
|
|
|
#define G2D_DMA_DONE (1 << 0)
|
|
|
|
#define G2D_DMA_LIST_DONE_COUNT_OFFSET 17
|
|
|
|
|
|
|
|
/* G2D_DMA_HOLD_CMD */
|
2013-03-13 15:44:37 +08:00
|
|
|
#define G2D_USER_HOLD (1 << 2)
|
2012-05-17 19:06:32 +08:00
|
|
|
#define G2D_LIST_HOLD (1 << 1)
|
|
|
|
#define G2D_BITBLT_HOLD (1 << 0)
|
|
|
|
|
|
|
|
/* G2D_BITBLT_START */
|
|
|
|
#define G2D_START_CASESEL (1 << 2)
|
|
|
|
#define G2D_START_NHOLT (1 << 1)
|
|
|
|
#define G2D_START_BITBLT (1 << 0)
|
|
|
|
|
2013-03-11 20:17:52 +08:00
|
|
|
/* buffer color format */
|
|
|
|
#define G2D_FMT_XRGB8888 0
|
|
|
|
#define G2D_FMT_ARGB8888 1
|
|
|
|
#define G2D_FMT_RGB565 2
|
|
|
|
#define G2D_FMT_XRGB1555 3
|
|
|
|
#define G2D_FMT_ARGB1555 4
|
|
|
|
#define G2D_FMT_XRGB4444 5
|
|
|
|
#define G2D_FMT_ARGB4444 6
|
|
|
|
#define G2D_FMT_PACKED_RGB888 7
|
|
|
|
#define G2D_FMT_A8 11
|
|
|
|
#define G2D_FMT_L8 12
|
|
|
|
|
|
|
|
/* buffer valid length */
|
|
|
|
#define G2D_LEN_MIN 1
|
|
|
|
#define G2D_LEN_MAX 8000
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
#define G2D_CMDLIST_SIZE (PAGE_SIZE / 4)
|
|
|
|
#define G2D_CMDLIST_NUM 64
|
|
|
|
#define G2D_CMDLIST_POOL_SIZE (G2D_CMDLIST_SIZE * G2D_CMDLIST_NUM)
|
|
|
|
#define G2D_CMDLIST_DATA_NUM (G2D_CMDLIST_SIZE / sizeof(u32) - 2)
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
/* maximum buffer pool size of userptr is 64MB as default */
|
|
|
|
#define MAX_POOL (64 * 1024 * 1024)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BUF_TYPE_GEM = 1,
|
|
|
|
BUF_TYPE_USERPTR,
|
|
|
|
};
|
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
enum g2d_reg_type {
|
|
|
|
REG_TYPE_NONE = -1,
|
|
|
|
REG_TYPE_SRC,
|
|
|
|
REG_TYPE_SRC_PLANE2,
|
|
|
|
REG_TYPE_DST,
|
|
|
|
REG_TYPE_DST_PLANE2,
|
|
|
|
REG_TYPE_PAT,
|
|
|
|
REG_TYPE_MSK,
|
|
|
|
MAX_REG_TYPE_NR
|
|
|
|
};
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
/* cmdlist data structure */
|
|
|
|
struct g2d_cmdlist {
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
u32 head;
|
|
|
|
unsigned long data[G2D_CMDLIST_DATA_NUM];
|
|
|
|
u32 last; /* last data offset */
|
2012-05-17 19:06:32 +08:00
|
|
|
};
|
|
|
|
|
2013-03-11 20:17:52 +08:00
|
|
|
/*
|
|
|
|
* A structure of buffer description
|
|
|
|
*
|
|
|
|
* @format: color format
|
2015-08-18 06:51:24 +08:00
|
|
|
* @stride: buffer stride/pitch in bytes
|
2013-03-11 20:17:52 +08:00
|
|
|
* @left_x: the x coordinates of left top corner
|
|
|
|
* @top_y: the y coordinates of left top corner
|
|
|
|
* @right_x: the x coordinates of right bottom corner
|
|
|
|
* @bottom_y: the y coordinates of right bottom corner
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct g2d_buf_desc {
|
|
|
|
unsigned int format;
|
2015-08-18 06:51:24 +08:00
|
|
|
unsigned int stride;
|
2013-03-11 20:17:52 +08:00
|
|
|
unsigned int left_x;
|
|
|
|
unsigned int top_y;
|
|
|
|
unsigned int right_x;
|
|
|
|
unsigned int bottom_y;
|
|
|
|
};
|
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
/*
|
|
|
|
* A structure of buffer information
|
|
|
|
*
|
|
|
|
* @map_nr: manages the number of mapped buffers
|
|
|
|
* @reg_types: stores regitster type in the order of requested command
|
|
|
|
* @handles: stores buffer handle in its reg_type position
|
|
|
|
* @types: stores buffer type in its reg_type position
|
2013-03-11 20:17:52 +08:00
|
|
|
* @descs: stores buffer description in its reg_type position
|
2013-03-13 16:10:08 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct g2d_buf_info {
|
|
|
|
unsigned int map_nr;
|
|
|
|
enum g2d_reg_type reg_types[MAX_REG_TYPE_NR];
|
|
|
|
unsigned long handles[MAX_REG_TYPE_NR];
|
|
|
|
unsigned int types[MAX_REG_TYPE_NR];
|
2013-03-11 20:17:52 +08:00
|
|
|
struct g2d_buf_desc descs[MAX_REG_TYPE_NR];
|
2013-03-13 16:10:08 +08:00
|
|
|
};
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
struct drm_exynos_pending_g2d_event {
|
|
|
|
struct drm_pending_event base;
|
|
|
|
struct drm_exynos_g2d_event event;
|
|
|
|
};
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
struct g2d_cmdlist_userptr {
|
|
|
|
struct list_head list;
|
|
|
|
dma_addr_t dma_addr;
|
|
|
|
unsigned long userptr;
|
|
|
|
unsigned long size;
|
2015-07-20 16:03:35 +08:00
|
|
|
struct frame_vector *vec;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
struct sg_table *sgt;
|
|
|
|
atomic_t refcount;
|
|
|
|
bool in_pool;
|
|
|
|
bool out_of_list;
|
|
|
|
};
|
2012-05-17 19:06:32 +08:00
|
|
|
struct g2d_cmdlist_node {
|
|
|
|
struct list_head list;
|
|
|
|
struct g2d_cmdlist *cmdlist;
|
|
|
|
dma_addr_t dma_addr;
|
2013-03-13 16:10:08 +08:00
|
|
|
struct g2d_buf_info buf_info;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
struct drm_exynos_pending_g2d_event *event;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct g2d_runqueue_node {
|
|
|
|
struct list_head list;
|
|
|
|
struct list_head run_cmdlist;
|
|
|
|
struct list_head event_list;
|
2012-11-04 12:53:24 +08:00
|
|
|
struct drm_file *filp;
|
2012-09-11 09:45:36 +08:00
|
|
|
pid_t pid;
|
2012-05-17 19:06:32 +08:00
|
|
|
struct completion complete;
|
|
|
|
int async;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct g2d_data {
|
|
|
|
struct device *dev;
|
|
|
|
struct clk *gate_clk;
|
|
|
|
void __iomem *regs;
|
|
|
|
int irq;
|
|
|
|
struct workqueue_struct *g2d_workq;
|
|
|
|
struct work_struct runqueue_work;
|
|
|
|
struct exynos_drm_subdrv subdrv;
|
|
|
|
bool suspended;
|
|
|
|
|
|
|
|
/* cmdlist */
|
|
|
|
struct g2d_cmdlist_node *cmdlist_node;
|
|
|
|
struct list_head free_cmdlist;
|
|
|
|
struct mutex cmdlist_mutex;
|
|
|
|
dma_addr_t cmdlist_pool;
|
|
|
|
void *cmdlist_pool_virt;
|
2012-11-04 12:53:24 +08:00
|
|
|
struct dma_attrs cmdlist_dma_attrs;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
/* runqueue*/
|
|
|
|
struct g2d_runqueue_node *runqueue_node;
|
|
|
|
struct list_head runqueue;
|
|
|
|
struct mutex runqueue_mutex;
|
|
|
|
struct kmem_cache *runqueue_slab;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
|
|
|
unsigned long current_pool;
|
|
|
|
unsigned long max_pool;
|
2012-05-17 19:06:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int g2d_init_cmdlist(struct g2d_data *g2d)
|
|
|
|
{
|
|
|
|
struct device *dev = g2d->dev;
|
|
|
|
struct g2d_cmdlist_node *node = g2d->cmdlist_node;
|
2012-11-04 12:53:24 +08:00
|
|
|
struct exynos_drm_subdrv *subdrv = &g2d->subdrv;
|
2012-05-17 19:06:32 +08:00
|
|
|
int nr;
|
|
|
|
int ret;
|
2013-03-13 16:10:08 +08:00
|
|
|
struct g2d_buf_info *buf_info;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
2012-11-04 12:53:24 +08:00
|
|
|
init_dma_attrs(&g2d->cmdlist_dma_attrs);
|
|
|
|
dma_set_attr(DMA_ATTR_WRITE_COMBINE, &g2d->cmdlist_dma_attrs);
|
|
|
|
|
2016-02-29 16:50:53 +08:00
|
|
|
g2d->cmdlist_pool_virt = dma_alloc_attrs(to_dma_dev(subdrv->drm_dev),
|
2012-11-04 12:53:24 +08:00
|
|
|
G2D_CMDLIST_POOL_SIZE,
|
|
|
|
&g2d->cmdlist_pool, GFP_KERNEL,
|
|
|
|
&g2d->cmdlist_dma_attrs);
|
2012-05-17 19:06:32 +08:00
|
|
|
if (!g2d->cmdlist_pool_virt) {
|
|
|
|
dev_err(dev, "failed to allocate dma memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2012-09-27 18:26:03 +08:00
|
|
|
node = kcalloc(G2D_CMDLIST_NUM, sizeof(*node), GFP_KERNEL);
|
2012-05-17 19:06:32 +08:00
|
|
|
if (!node) {
|
|
|
|
dev_err(dev, "failed to allocate memory\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nr = 0; nr < G2D_CMDLIST_NUM; nr++) {
|
2013-03-13 16:10:08 +08:00
|
|
|
unsigned int i;
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
node[nr].cmdlist =
|
|
|
|
g2d->cmdlist_pool_virt + nr * G2D_CMDLIST_SIZE;
|
|
|
|
node[nr].dma_addr =
|
|
|
|
g2d->cmdlist_pool + nr * G2D_CMDLIST_SIZE;
|
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
buf_info = &node[nr].buf_info;
|
|
|
|
for (i = 0; i < MAX_REG_TYPE_NR; i++)
|
|
|
|
buf_info->reg_types[i] = REG_TYPE_NONE;
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
list_add_tail(&node[nr].list, &g2d->free_cmdlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2016-02-29 16:50:53 +08:00
|
|
|
dma_free_attrs(to_dma_dev(subdrv->drm_dev), G2D_CMDLIST_POOL_SIZE,
|
2012-11-04 12:53:24 +08:00
|
|
|
g2d->cmdlist_pool_virt,
|
|
|
|
g2d->cmdlist_pool, &g2d->cmdlist_dma_attrs);
|
2012-05-17 19:06:32 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_fini_cmdlist(struct g2d_data *g2d)
|
|
|
|
{
|
2012-11-04 12:53:24 +08:00
|
|
|
struct exynos_drm_subdrv *subdrv = &g2d->subdrv;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
kfree(g2d->cmdlist_node);
|
2014-11-07 19:31:08 +08:00
|
|
|
|
|
|
|
if (g2d->cmdlist_pool_virt && g2d->cmdlist_pool) {
|
2016-02-29 16:50:53 +08:00
|
|
|
dma_free_attrs(to_dma_dev(subdrv->drm_dev),
|
|
|
|
G2D_CMDLIST_POOL_SIZE,
|
2014-11-07 19:31:08 +08:00
|
|
|
g2d->cmdlist_pool_virt,
|
|
|
|
g2d->cmdlist_pool, &g2d->cmdlist_dma_attrs);
|
|
|
|
}
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct g2d_cmdlist_node *g2d_get_cmdlist(struct g2d_data *g2d)
|
|
|
|
{
|
|
|
|
struct device *dev = g2d->dev;
|
|
|
|
struct g2d_cmdlist_node *node;
|
|
|
|
|
|
|
|
mutex_lock(&g2d->cmdlist_mutex);
|
|
|
|
if (list_empty(&g2d->free_cmdlist)) {
|
|
|
|
dev_err(dev, "there is no free cmdlist\n");
|
|
|
|
mutex_unlock(&g2d->cmdlist_mutex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = list_first_entry(&g2d->free_cmdlist, struct g2d_cmdlist_node,
|
|
|
|
list);
|
|
|
|
list_del_init(&node->list);
|
|
|
|
mutex_unlock(&g2d->cmdlist_mutex);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_put_cmdlist(struct g2d_data *g2d, struct g2d_cmdlist_node *node)
|
|
|
|
{
|
|
|
|
mutex_lock(&g2d->cmdlist_mutex);
|
|
|
|
list_move_tail(&node->list, &g2d->free_cmdlist);
|
|
|
|
mutex_unlock(&g2d->cmdlist_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_add_cmdlist_to_inuse(struct exynos_drm_g2d_private *g2d_priv,
|
|
|
|
struct g2d_cmdlist_node *node)
|
|
|
|
{
|
|
|
|
struct g2d_cmdlist_node *lnode;
|
|
|
|
|
|
|
|
if (list_empty(&g2d_priv->inuse_cmdlist))
|
|
|
|
goto add_to_list;
|
|
|
|
|
|
|
|
/* this links to base address of new cmdlist */
|
|
|
|
lnode = list_entry(g2d_priv->inuse_cmdlist.prev,
|
|
|
|
struct g2d_cmdlist_node, list);
|
|
|
|
lnode->cmdlist->data[lnode->cmdlist->last] = node->dma_addr;
|
|
|
|
|
|
|
|
add_to_list:
|
|
|
|
list_add_tail(&node->list, &g2d_priv->inuse_cmdlist);
|
|
|
|
|
|
|
|
if (node->event)
|
|
|
|
list_add_tail(&node->event->base.link, &g2d_priv->event_list);
|
|
|
|
}
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
static void g2d_userptr_put_dma_addr(struct drm_device *drm_dev,
|
|
|
|
unsigned long obj,
|
|
|
|
bool force)
|
|
|
|
{
|
|
|
|
struct g2d_cmdlist_userptr *g2d_userptr =
|
|
|
|
(struct g2d_cmdlist_userptr *)obj;
|
2015-07-20 16:03:35 +08:00
|
|
|
struct page **pages;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (force)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
atomic_dec(&g2d_userptr->refcount);
|
|
|
|
|
|
|
|
if (atomic_read(&g2d_userptr->refcount) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g2d_userptr->in_pool)
|
|
|
|
return;
|
|
|
|
|
|
|
|
out:
|
2016-04-22 15:34:07 +08:00
|
|
|
dma_unmap_sg(to_dma_dev(drm_dev), g2d_userptr->sgt->sgl,
|
|
|
|
g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL);
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
2015-07-20 16:03:35 +08:00
|
|
|
pages = frame_vector_pages(g2d_userptr->vec);
|
|
|
|
if (!IS_ERR(pages)) {
|
|
|
|
int i;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
2015-07-20 16:03:35 +08:00
|
|
|
for (i = 0; i < frame_vector_count(g2d_userptr->vec); i++)
|
|
|
|
set_page_dirty_lock(pages[i]);
|
|
|
|
}
|
|
|
|
put_vaddr_frames(g2d_userptr->vec);
|
|
|
|
frame_vector_destroy(g2d_userptr->vec);
|
2013-11-21 11:09:51 +08:00
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
if (!g2d_userptr->out_of_list)
|
|
|
|
list_del_init(&g2d_userptr->list);
|
|
|
|
|
|
|
|
sg_free_table(g2d_userptr->sgt);
|
|
|
|
kfree(g2d_userptr->sgt);
|
2012-11-23 11:41:59 +08:00
|
|
|
kfree(g2d_userptr);
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
|
|
|
|
2013-01-14 14:59:09 +08:00
|
|
|
static dma_addr_t *g2d_userptr_get_dma_addr(struct drm_device *drm_dev,
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
unsigned long userptr,
|
|
|
|
unsigned long size,
|
|
|
|
struct drm_file *filp,
|
|
|
|
unsigned long *obj)
|
|
|
|
{
|
|
|
|
struct drm_exynos_file_private *file_priv = filp->driver_priv;
|
|
|
|
struct exynos_drm_g2d_private *g2d_priv = file_priv->g2d_priv;
|
|
|
|
struct g2d_cmdlist_userptr *g2d_userptr;
|
|
|
|
struct g2d_data *g2d;
|
|
|
|
struct sg_table *sgt;
|
|
|
|
unsigned long start, end;
|
|
|
|
unsigned int npages, offset;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!size) {
|
|
|
|
DRM_ERROR("invalid userptr size.\n");
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
g2d = dev_get_drvdata(g2d_priv->dev);
|
|
|
|
|
|
|
|
/* check if userptr already exists in userptr_list. */
|
|
|
|
list_for_each_entry(g2d_userptr, &g2d_priv->userptr_list, list) {
|
|
|
|
if (g2d_userptr->userptr == userptr) {
|
|
|
|
/*
|
|
|
|
* also check size because there could be same address
|
|
|
|
* and different size.
|
|
|
|
*/
|
|
|
|
if (g2d_userptr->size == size) {
|
|
|
|
atomic_inc(&g2d_userptr->refcount);
|
|
|
|
*obj = (unsigned long)g2d_userptr;
|
|
|
|
|
|
|
|
return &g2d_userptr->dma_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* at this moment, maybe g2d dma is accessing this
|
|
|
|
* g2d_userptr memory region so just remove this
|
|
|
|
* g2d_userptr object from userptr_list not to be
|
|
|
|
* referred again and also except it the userptr
|
|
|
|
* pool to be released after the dma access completion.
|
|
|
|
*/
|
|
|
|
g2d_userptr->out_of_list = true;
|
|
|
|
g2d_userptr->in_pool = false;
|
|
|
|
list_del_init(&g2d_userptr->list);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g2d_userptr = kzalloc(sizeof(*g2d_userptr), GFP_KERNEL);
|
2013-08-19 18:04:55 +08:00
|
|
|
if (!g2d_userptr)
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
atomic_set(&g2d_userptr->refcount, 1);
|
2015-07-20 16:03:35 +08:00
|
|
|
g2d_userptr->size = size;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
|
|
|
start = userptr & PAGE_MASK;
|
|
|
|
offset = userptr & ~PAGE_MASK;
|
|
|
|
end = PAGE_ALIGN(userptr + size);
|
|
|
|
npages = (end - start) >> PAGE_SHIFT;
|
2015-07-20 16:03:35 +08:00
|
|
|
g2d_userptr->vec = frame_vector_create(npages);
|
|
|
|
if (!g2d_userptr->vec) {
|
2013-07-03 16:09:21 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_free;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
|
|
|
|
2015-07-20 16:03:35 +08:00
|
|
|
ret = get_vaddr_frames(start, npages, true, true, g2d_userptr->vec);
|
|
|
|
if (ret != npages) {
|
|
|
|
DRM_ERROR("failed to get user pages from userptr.\n");
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_destroy_framevec;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
ret = -EFAULT;
|
2015-07-20 16:03:35 +08:00
|
|
|
goto err_put_framevec;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
2015-07-20 16:03:35 +08:00
|
|
|
if (frame_vector_to_pages(g2d_userptr->vec) < 0) {
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
ret = -EFAULT;
|
2015-07-20 16:03:35 +08:00
|
|
|
goto err_put_framevec;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
|
|
|
|
2013-01-25 17:15:42 +08:00
|
|
|
sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
if (!sgt) {
|
|
|
|
ret = -ENOMEM;
|
2015-07-20 16:03:35 +08:00
|
|
|
goto err_put_framevec;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
|
|
|
|
2015-07-20 16:03:35 +08:00
|
|
|
ret = sg_alloc_table_from_pages(sgt,
|
|
|
|
frame_vector_pages(g2d_userptr->vec),
|
|
|
|
npages, offset, size, GFP_KERNEL);
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
DRM_ERROR("failed to get sgt from pages.\n");
|
|
|
|
goto err_free_sgt;
|
|
|
|
}
|
|
|
|
|
|
|
|
g2d_userptr->sgt = sgt;
|
|
|
|
|
2016-04-22 15:34:07 +08:00
|
|
|
if (!dma_map_sg(to_dma_dev(drm_dev), sgt->sgl, sgt->nents,
|
|
|
|
DMA_BIDIRECTIONAL)) {
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
DRM_ERROR("failed to map sgt with dma region.\n");
|
2016-04-22 15:34:07 +08:00
|
|
|
ret = -ENOMEM;
|
2013-03-11 18:48:05 +08:00
|
|
|
goto err_sg_free_table;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g2d_userptr->dma_addr = sgt->sgl[0].dma_address;
|
|
|
|
g2d_userptr->userptr = userptr;
|
|
|
|
|
|
|
|
list_add_tail(&g2d_userptr->list, &g2d_priv->userptr_list);
|
|
|
|
|
|
|
|
if (g2d->current_pool + (npages << PAGE_SHIFT) < g2d->max_pool) {
|
|
|
|
g2d->current_pool += npages << PAGE_SHIFT;
|
|
|
|
g2d_userptr->in_pool = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = (unsigned long)g2d_userptr;
|
|
|
|
|
|
|
|
return &g2d_userptr->dma_addr;
|
|
|
|
|
2013-03-11 18:48:05 +08:00
|
|
|
err_sg_free_table:
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
sg_free_table(sgt);
|
2013-03-11 18:48:05 +08:00
|
|
|
|
|
|
|
err_free_sgt:
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
kfree(sgt);
|
|
|
|
|
2015-07-20 16:03:35 +08:00
|
|
|
err_put_framevec:
|
|
|
|
put_vaddr_frames(g2d_userptr->vec);
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
2015-07-20 16:03:35 +08:00
|
|
|
err_destroy_framevec:
|
|
|
|
frame_vector_destroy(g2d_userptr->vec);
|
2013-07-03 16:09:21 +08:00
|
|
|
|
|
|
|
err_free:
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
kfree(g2d_userptr);
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_userptr_free_all(struct drm_device *drm_dev,
|
|
|
|
struct g2d_data *g2d,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
struct drm_exynos_file_private *file_priv = filp->driver_priv;
|
|
|
|
struct exynos_drm_g2d_private *g2d_priv = file_priv->g2d_priv;
|
|
|
|
struct g2d_cmdlist_userptr *g2d_userptr, *n;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(g2d_userptr, n, &g2d_priv->userptr_list, list)
|
|
|
|
if (g2d_userptr->in_pool)
|
|
|
|
g2d_userptr_put_dma_addr(drm_dev,
|
|
|
|
(unsigned long)g2d_userptr,
|
|
|
|
true);
|
|
|
|
|
|
|
|
g2d->current_pool = 0;
|
|
|
|
}
|
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
static enum g2d_reg_type g2d_get_reg_type(int reg_offset)
|
|
|
|
{
|
|
|
|
enum g2d_reg_type reg_type;
|
|
|
|
|
|
|
|
switch (reg_offset) {
|
|
|
|
case G2D_SRC_BASE_ADDR:
|
2016-05-25 20:42:56 +08:00
|
|
|
case G2D_SRC_STRIDE:
|
2013-03-11 20:17:52 +08:00
|
|
|
case G2D_SRC_COLOR_MODE:
|
|
|
|
case G2D_SRC_LEFT_TOP:
|
|
|
|
case G2D_SRC_RIGHT_BOTTOM:
|
2013-03-13 16:10:08 +08:00
|
|
|
reg_type = REG_TYPE_SRC;
|
|
|
|
break;
|
|
|
|
case G2D_SRC_PLANE2_BASE_ADDR:
|
|
|
|
reg_type = REG_TYPE_SRC_PLANE2;
|
|
|
|
break;
|
|
|
|
case G2D_DST_BASE_ADDR:
|
2016-05-25 20:42:56 +08:00
|
|
|
case G2D_DST_STRIDE:
|
2013-03-11 20:17:52 +08:00
|
|
|
case G2D_DST_COLOR_MODE:
|
|
|
|
case G2D_DST_LEFT_TOP:
|
|
|
|
case G2D_DST_RIGHT_BOTTOM:
|
2013-03-13 16:10:08 +08:00
|
|
|
reg_type = REG_TYPE_DST;
|
|
|
|
break;
|
|
|
|
case G2D_DST_PLANE2_BASE_ADDR:
|
|
|
|
reg_type = REG_TYPE_DST_PLANE2;
|
|
|
|
break;
|
|
|
|
case G2D_PAT_BASE_ADDR:
|
|
|
|
reg_type = REG_TYPE_PAT;
|
|
|
|
break;
|
|
|
|
case G2D_MSK_BASE_ADDR:
|
|
|
|
reg_type = REG_TYPE_MSK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
reg_type = REG_TYPE_NONE;
|
|
|
|
DRM_ERROR("Unknown register offset![%d]\n", reg_offset);
|
|
|
|
break;
|
2014-01-16 12:30:22 +08:00
|
|
|
}
|
2013-03-13 16:10:08 +08:00
|
|
|
|
|
|
|
return reg_type;
|
|
|
|
}
|
|
|
|
|
2013-03-11 20:17:52 +08:00
|
|
|
static unsigned long g2d_get_buf_bpp(unsigned int format)
|
|
|
|
{
|
|
|
|
unsigned long bpp;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case G2D_FMT_XRGB8888:
|
|
|
|
case G2D_FMT_ARGB8888:
|
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
case G2D_FMT_RGB565:
|
|
|
|
case G2D_FMT_XRGB1555:
|
|
|
|
case G2D_FMT_ARGB1555:
|
|
|
|
case G2D_FMT_XRGB4444:
|
|
|
|
case G2D_FMT_ARGB4444:
|
|
|
|
bpp = 2;
|
|
|
|
break;
|
|
|
|
case G2D_FMT_PACKED_RGB888:
|
|
|
|
bpp = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bpp = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool g2d_check_buf_desc_is_valid(struct g2d_buf_desc *buf_desc,
|
|
|
|
enum g2d_reg_type reg_type,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
2015-08-18 06:51:24 +08:00
|
|
|
int width, height;
|
|
|
|
unsigned long bpp, last_pos;
|
2013-03-11 20:17:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check source and destination buffers only.
|
|
|
|
* so the others are always valid.
|
|
|
|
*/
|
|
|
|
if (reg_type != REG_TYPE_SRC && reg_type != REG_TYPE_DST)
|
|
|
|
return true;
|
|
|
|
|
2015-08-18 06:51:24 +08:00
|
|
|
/* This check also makes sure that right_x > left_x. */
|
|
|
|
width = (int)buf_desc->right_x - (int)buf_desc->left_x;
|
2013-03-11 20:17:52 +08:00
|
|
|
if (width < G2D_LEN_MIN || width > G2D_LEN_MAX) {
|
2015-08-18 06:51:24 +08:00
|
|
|
DRM_ERROR("width[%d] is out of range!\n", width);
|
2013-03-11 20:17:52 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-18 06:51:24 +08:00
|
|
|
/* This check also makes sure that bottom_y > top_y. */
|
|
|
|
height = (int)buf_desc->bottom_y - (int)buf_desc->top_y;
|
2013-03-11 20:17:52 +08:00
|
|
|
if (height < G2D_LEN_MIN || height > G2D_LEN_MAX) {
|
2015-08-18 06:51:24 +08:00
|
|
|
DRM_ERROR("height[%d] is out of range!\n", height);
|
2013-03-11 20:17:52 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-18 06:51:24 +08:00
|
|
|
bpp = g2d_get_buf_bpp(buf_desc->format);
|
|
|
|
|
|
|
|
/* Compute the position of the last byte that the engine accesses. */
|
|
|
|
last_pos = ((unsigned long)buf_desc->bottom_y - 1) *
|
|
|
|
(unsigned long)buf_desc->stride +
|
|
|
|
(unsigned long)buf_desc->right_x * bpp - 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since right_x > left_x and bottom_y > top_y we already know
|
|
|
|
* that the first_pos < last_pos (first_pos being the position
|
|
|
|
* of the first byte the engine accesses), it just remains to
|
|
|
|
* check if last_pos is smaller then the buffer size.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (last_pos >= size) {
|
|
|
|
DRM_ERROR("last engine access position [%lu] "
|
|
|
|
"is out of range [%lu]!\n", last_pos, size);
|
2013-03-11 20:17:52 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-04 12:53:24 +08:00
|
|
|
static int g2d_map_cmdlist_gem(struct g2d_data *g2d,
|
|
|
|
struct g2d_cmdlist_node *node,
|
|
|
|
struct drm_device *drm_dev,
|
|
|
|
struct drm_file *file)
|
2012-05-17 19:06:32 +08:00
|
|
|
{
|
|
|
|
struct g2d_cmdlist *cmdlist = node->cmdlist;
|
2013-03-13 16:10:08 +08:00
|
|
|
struct g2d_buf_info *buf_info = &node->buf_info;
|
2012-05-17 19:06:32 +08:00
|
|
|
int offset;
|
2013-03-13 16:10:08 +08:00
|
|
|
int ret;
|
2012-05-17 19:06:32 +08:00
|
|
|
int i;
|
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
for (i = 0; i < buf_info->map_nr; i++) {
|
2013-03-11 20:17:52 +08:00
|
|
|
struct g2d_buf_desc *buf_desc;
|
2013-03-13 16:10:08 +08:00
|
|
|
enum g2d_reg_type reg_type;
|
|
|
|
int reg_pos;
|
2012-11-04 12:53:24 +08:00
|
|
|
unsigned long handle;
|
|
|
|
dma_addr_t *addr;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
reg_pos = cmdlist->last - 2 * (i + 1);
|
|
|
|
|
|
|
|
offset = cmdlist->data[reg_pos];
|
|
|
|
handle = cmdlist->data[reg_pos + 1];
|
|
|
|
|
|
|
|
reg_type = g2d_get_reg_type(offset);
|
|
|
|
if (reg_type == REG_TYPE_NONE) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
|
|
|
}
|
2012-05-17 19:06:32 +08:00
|
|
|
|
2013-03-11 20:17:52 +08:00
|
|
|
buf_desc = &buf_info->descs[reg_type];
|
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
if (buf_info->types[reg_type] == BUF_TYPE_GEM) {
|
2013-03-11 20:17:52 +08:00
|
|
|
unsigned long size;
|
|
|
|
|
|
|
|
size = exynos_drm_gem_get_size(drm_dev, handle, file);
|
|
|
|
if (!size) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g2d_check_buf_desc_is_valid(buf_desc, reg_type,
|
|
|
|
size)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
addr = exynos_drm_gem_get_dma_addr(drm_dev, handle,
|
|
|
|
file);
|
|
|
|
if (IS_ERR(addr)) {
|
2013-03-13 16:10:08 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct drm_exynos_g2d_userptr g2d_userptr;
|
|
|
|
|
|
|
|
if (copy_from_user(&g2d_userptr, (void __user *)handle,
|
|
|
|
sizeof(struct drm_exynos_g2d_userptr))) {
|
2013-03-13 16:10:08 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
|
|
|
|
2013-03-11 20:17:52 +08:00
|
|
|
if (!g2d_check_buf_desc_is_valid(buf_desc, reg_type,
|
|
|
|
g2d_userptr.size)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
addr = g2d_userptr_get_dma_addr(drm_dev,
|
|
|
|
g2d_userptr.userptr,
|
|
|
|
g2d_userptr.size,
|
|
|
|
file,
|
|
|
|
&handle);
|
|
|
|
if (IS_ERR(addr)) {
|
2013-03-13 16:10:08 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
}
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
cmdlist->data[reg_pos + 1] = *addr;
|
|
|
|
buf_info->reg_types[i] = reg_type;
|
|
|
|
buf_info->handles[reg_type] = handle;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-03-13 16:10:08 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
buf_info->map_nr = i;
|
|
|
|
return ret;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
2012-11-04 12:53:24 +08:00
|
|
|
static void g2d_unmap_cmdlist_gem(struct g2d_data *g2d,
|
|
|
|
struct g2d_cmdlist_node *node,
|
|
|
|
struct drm_file *filp)
|
2012-05-17 19:06:32 +08:00
|
|
|
{
|
2012-11-04 12:53:24 +08:00
|
|
|
struct exynos_drm_subdrv *subdrv = &g2d->subdrv;
|
2013-03-13 16:10:08 +08:00
|
|
|
struct g2d_buf_info *buf_info = &node->buf_info;
|
2012-11-04 12:53:24 +08:00
|
|
|
int i;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
for (i = 0; i < buf_info->map_nr; i++) {
|
2013-03-11 20:17:52 +08:00
|
|
|
struct g2d_buf_desc *buf_desc;
|
2013-03-13 16:10:08 +08:00
|
|
|
enum g2d_reg_type reg_type;
|
|
|
|
unsigned long handle;
|
|
|
|
|
|
|
|
reg_type = buf_info->reg_types[i];
|
2012-11-04 12:53:24 +08:00
|
|
|
|
2013-03-11 20:17:52 +08:00
|
|
|
buf_desc = &buf_info->descs[reg_type];
|
2013-03-13 16:10:08 +08:00
|
|
|
handle = buf_info->handles[reg_type];
|
|
|
|
|
|
|
|
if (buf_info->types[reg_type] == BUF_TYPE_GEM)
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
exynos_drm_gem_put_dma_addr(subdrv->drm_dev, handle,
|
|
|
|
filp);
|
|
|
|
else
|
|
|
|
g2d_userptr_put_dma_addr(subdrv->drm_dev, handle,
|
|
|
|
false);
|
2012-05-17 19:06:32 +08:00
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
buf_info->reg_types[i] = REG_TYPE_NONE;
|
|
|
|
buf_info->handles[reg_type] = 0;
|
|
|
|
buf_info->types[reg_type] = 0;
|
2013-03-11 20:17:52 +08:00
|
|
|
memset(buf_desc, 0x00, sizeof(*buf_desc));
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
2012-11-04 12:53:24 +08:00
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
buf_info->map_nr = 0;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_dma_start(struct g2d_data *g2d,
|
|
|
|
struct g2d_runqueue_node *runqueue_node)
|
|
|
|
{
|
|
|
|
struct g2d_cmdlist_node *node =
|
|
|
|
list_first_entry(&runqueue_node->run_cmdlist,
|
|
|
|
struct g2d_cmdlist_node, list);
|
2013-07-24 12:40:12 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pm_runtime_get_sync(g2d->dev);
|
2013-07-24 14:44:30 +08:00
|
|
|
if (ret < 0)
|
2013-07-24 12:40:12 +08:00
|
|
|
return;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
writel_relaxed(node->dma_addr, g2d->regs + G2D_DMA_SFR_BASE_ADDR);
|
|
|
|
writel_relaxed(G2D_DMA_START, g2d->regs + G2D_DMA_COMMAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct g2d_runqueue_node *g2d_get_runqueue_node(struct g2d_data *g2d)
|
|
|
|
{
|
|
|
|
struct g2d_runqueue_node *runqueue_node;
|
|
|
|
|
|
|
|
if (list_empty(&g2d->runqueue))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
runqueue_node = list_first_entry(&g2d->runqueue,
|
|
|
|
struct g2d_runqueue_node, list);
|
|
|
|
list_del_init(&runqueue_node->list);
|
|
|
|
return runqueue_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_free_runqueue_node(struct g2d_data *g2d,
|
|
|
|
struct g2d_runqueue_node *runqueue_node)
|
|
|
|
{
|
2012-11-04 12:53:24 +08:00
|
|
|
struct g2d_cmdlist_node *node;
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
if (!runqueue_node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mutex_lock(&g2d->cmdlist_mutex);
|
2012-11-04 12:53:24 +08:00
|
|
|
/*
|
|
|
|
* commands in run_cmdlist have been completed so unmap all gem
|
|
|
|
* objects in each command node so that they are unreferenced.
|
|
|
|
*/
|
|
|
|
list_for_each_entry(node, &runqueue_node->run_cmdlist, list)
|
|
|
|
g2d_unmap_cmdlist_gem(g2d, node, runqueue_node->filp);
|
2012-05-17 19:06:32 +08:00
|
|
|
list_splice_tail_init(&runqueue_node->run_cmdlist, &g2d->free_cmdlist);
|
|
|
|
mutex_unlock(&g2d->cmdlist_mutex);
|
|
|
|
|
|
|
|
kmem_cache_free(g2d->runqueue_slab, runqueue_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_exec_runqueue(struct g2d_data *g2d)
|
|
|
|
{
|
|
|
|
g2d->runqueue_node = g2d_get_runqueue_node(g2d);
|
|
|
|
if (g2d->runqueue_node)
|
|
|
|
g2d_dma_start(g2d, g2d->runqueue_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_runqueue_worker(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct g2d_data *g2d = container_of(work, struct g2d_data,
|
|
|
|
runqueue_work);
|
|
|
|
|
|
|
|
mutex_lock(&g2d->runqueue_mutex);
|
|
|
|
pm_runtime_put_sync(g2d->dev);
|
|
|
|
|
|
|
|
complete(&g2d->runqueue_node->complete);
|
|
|
|
if (g2d->runqueue_node->async)
|
|
|
|
g2d_free_runqueue_node(g2d, g2d->runqueue_node);
|
|
|
|
|
|
|
|
if (g2d->suspended)
|
|
|
|
g2d->runqueue_node = NULL;
|
|
|
|
else
|
|
|
|
g2d_exec_runqueue(g2d);
|
|
|
|
mutex_unlock(&g2d->runqueue_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_finish_event(struct g2d_data *g2d, u32 cmdlist_no)
|
|
|
|
{
|
|
|
|
struct drm_device *drm_dev = g2d->subdrv.drm_dev;
|
|
|
|
struct g2d_runqueue_node *runqueue_node = g2d->runqueue_node;
|
|
|
|
struct drm_exynos_pending_g2d_event *e;
|
|
|
|
struct timeval now;
|
|
|
|
|
|
|
|
if (list_empty(&runqueue_node->event_list))
|
|
|
|
return;
|
|
|
|
|
|
|
|
e = list_first_entry(&runqueue_node->event_list,
|
|
|
|
struct drm_exynos_pending_g2d_event, base.link);
|
|
|
|
|
|
|
|
do_gettimeofday(&now);
|
|
|
|
e->event.tv_sec = now.tv_sec;
|
|
|
|
e->event.tv_usec = now.tv_usec;
|
|
|
|
e->event.cmdlist_no = cmdlist_no;
|
|
|
|
|
2016-01-12 05:40:59 +08:00
|
|
|
drm_send_event(drm_dev, &e->base);
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t g2d_irq_handler(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct g2d_data *g2d = dev_id;
|
|
|
|
u32 pending;
|
|
|
|
|
|
|
|
pending = readl_relaxed(g2d->regs + G2D_INTC_PEND);
|
|
|
|
if (pending)
|
|
|
|
writel_relaxed(pending, g2d->regs + G2D_INTC_PEND);
|
|
|
|
|
|
|
|
if (pending & G2D_INTP_GCMD_FIN) {
|
|
|
|
u32 cmdlist_no = readl_relaxed(g2d->regs + G2D_DMA_STATUS);
|
|
|
|
|
|
|
|
cmdlist_no = (cmdlist_no & G2D_DMA_LIST_DONE_COUNT) >>
|
|
|
|
G2D_DMA_LIST_DONE_COUNT_OFFSET;
|
|
|
|
|
|
|
|
g2d_finish_event(g2d, cmdlist_no);
|
|
|
|
|
|
|
|
writel_relaxed(0, g2d->regs + G2D_DMA_HOLD_CMD);
|
|
|
|
if (!(pending & G2D_INTP_ACMD_FIN)) {
|
|
|
|
writel_relaxed(G2D_DMA_CONTINUE,
|
|
|
|
g2d->regs + G2D_DMA_COMMAND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pending & G2D_INTP_ACMD_FIN)
|
|
|
|
queue_work(g2d->g2d_workq, &g2d->runqueue_work);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
static int g2d_check_reg_offset(struct device *dev,
|
|
|
|
struct g2d_cmdlist_node *node,
|
2012-05-17 19:06:32 +08:00
|
|
|
int nr, bool for_addr)
|
|
|
|
{
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
struct g2d_cmdlist *cmdlist = node->cmdlist;
|
2012-05-17 19:06:32 +08:00
|
|
|
int reg_offset;
|
|
|
|
int index;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nr; i++) {
|
2013-03-13 16:10:08 +08:00
|
|
|
struct g2d_buf_info *buf_info = &node->buf_info;
|
2013-03-11 20:17:52 +08:00
|
|
|
struct g2d_buf_desc *buf_desc;
|
2013-03-13 16:10:08 +08:00
|
|
|
enum g2d_reg_type reg_type;
|
2013-03-11 20:17:52 +08:00
|
|
|
unsigned long value;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
index = cmdlist->last - 2 * (i + 1);
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
reg_offset = cmdlist->data[index] & ~0xfffff000;
|
|
|
|
if (reg_offset < G2D_VALID_START || reg_offset > G2D_VALID_END)
|
|
|
|
goto err;
|
|
|
|
if (reg_offset % 4)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
switch (reg_offset) {
|
|
|
|
case G2D_SRC_BASE_ADDR:
|
|
|
|
case G2D_SRC_PLANE2_BASE_ADDR:
|
|
|
|
case G2D_DST_BASE_ADDR:
|
|
|
|
case G2D_DST_PLANE2_BASE_ADDR:
|
|
|
|
case G2D_PAT_BASE_ADDR:
|
|
|
|
case G2D_MSK_BASE_ADDR:
|
|
|
|
if (!for_addr)
|
|
|
|
goto err;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
reg_type = g2d_get_reg_type(reg_offset);
|
|
|
|
|
|
|
|
/* check userptr buffer type. */
|
|
|
|
if ((cmdlist->data[index] & ~0x7fffffff) >> 31) {
|
|
|
|
buf_info->types[reg_type] = BUF_TYPE_USERPTR;
|
|
|
|
cmdlist->data[index] &= ~G2D_BUF_USERPTR;
|
|
|
|
} else
|
|
|
|
buf_info->types[reg_type] = BUF_TYPE_GEM;
|
2012-05-17 19:06:32 +08:00
|
|
|
break;
|
2016-05-25 20:42:56 +08:00
|
|
|
case G2D_SRC_STRIDE:
|
|
|
|
case G2D_DST_STRIDE:
|
2015-08-18 06:51:24 +08:00
|
|
|
if (for_addr)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
reg_type = g2d_get_reg_type(reg_offset);
|
|
|
|
|
|
|
|
buf_desc = &buf_info->descs[reg_type];
|
|
|
|
buf_desc->stride = cmdlist->data[index + 1];
|
|
|
|
break;
|
2013-03-11 20:17:52 +08:00
|
|
|
case G2D_SRC_COLOR_MODE:
|
|
|
|
case G2D_DST_COLOR_MODE:
|
|
|
|
if (for_addr)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
reg_type = g2d_get_reg_type(reg_offset);
|
|
|
|
|
|
|
|
buf_desc = &buf_info->descs[reg_type];
|
|
|
|
value = cmdlist->data[index + 1];
|
|
|
|
|
|
|
|
buf_desc->format = value & 0xf;
|
|
|
|
break;
|
|
|
|
case G2D_SRC_LEFT_TOP:
|
|
|
|
case G2D_DST_LEFT_TOP:
|
|
|
|
if (for_addr)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
reg_type = g2d_get_reg_type(reg_offset);
|
|
|
|
|
|
|
|
buf_desc = &buf_info->descs[reg_type];
|
|
|
|
value = cmdlist->data[index + 1];
|
|
|
|
|
|
|
|
buf_desc->left_x = value & 0x1fff;
|
|
|
|
buf_desc->top_y = (value & 0x1fff0000) >> 16;
|
|
|
|
break;
|
|
|
|
case G2D_SRC_RIGHT_BOTTOM:
|
|
|
|
case G2D_DST_RIGHT_BOTTOM:
|
|
|
|
if (for_addr)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
reg_type = g2d_get_reg_type(reg_offset);
|
|
|
|
|
|
|
|
buf_desc = &buf_info->descs[reg_type];
|
|
|
|
value = cmdlist->data[index + 1];
|
|
|
|
|
|
|
|
buf_desc->right_x = value & 0x1fff;
|
|
|
|
buf_desc->bottom_y = (value & 0x1fff0000) >> 16;
|
|
|
|
break;
|
2012-05-17 19:06:32 +08:00
|
|
|
default:
|
|
|
|
if (for_addr)
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
dev_err(dev, "Bad register offset: 0x%lx\n", cmdlist->data[index]);
|
2012-05-17 19:06:32 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ioctl functions */
|
|
|
|
int exynos_g2d_get_ver_ioctl(struct drm_device *drm_dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
2014-07-23 22:57:13 +08:00
|
|
|
struct drm_exynos_file_private *file_priv = file->driver_priv;
|
|
|
|
struct exynos_drm_g2d_private *g2d_priv = file_priv->g2d_priv;
|
|
|
|
struct device *dev;
|
|
|
|
struct g2d_data *g2d;
|
2012-05-17 19:06:32 +08:00
|
|
|
struct drm_exynos_g2d_get_ver *ver = data;
|
|
|
|
|
2014-07-23 22:57:13 +08:00
|
|
|
if (!g2d_priv)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
dev = g2d_priv->dev;
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
g2d = dev_get_drvdata(dev);
|
|
|
|
if (!g2d)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
ver->major = G2D_HW_MAJOR_VER;
|
|
|
|
ver->minor = G2D_HW_MINOR_VER;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int exynos_g2d_set_cmdlist_ioctl(struct drm_device *drm_dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_exynos_file_private *file_priv = file->driver_priv;
|
|
|
|
struct exynos_drm_g2d_private *g2d_priv = file_priv->g2d_priv;
|
2014-07-23 22:57:12 +08:00
|
|
|
struct device *dev;
|
2012-05-17 19:06:32 +08:00
|
|
|
struct g2d_data *g2d;
|
|
|
|
struct drm_exynos_g2d_set_cmdlist *req = data;
|
|
|
|
struct drm_exynos_g2d_cmd *cmd;
|
|
|
|
struct drm_exynos_pending_g2d_event *e;
|
|
|
|
struct g2d_cmdlist_node *node;
|
|
|
|
struct g2d_cmdlist *cmdlist;
|
|
|
|
int size;
|
|
|
|
int ret;
|
|
|
|
|
2014-07-23 22:57:12 +08:00
|
|
|
if (!g2d_priv)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
dev = g2d_priv->dev;
|
2012-05-17 19:06:32 +08:00
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
g2d = dev_get_drvdata(dev);
|
|
|
|
if (!g2d)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
node = g2d_get_cmdlist(g2d);
|
|
|
|
if (!node)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
node->event = NULL;
|
|
|
|
|
|
|
|
if (req->event_type != G2D_EVENT_NOT) {
|
|
|
|
e = kzalloc(sizeof(*node->event), GFP_KERNEL);
|
|
|
|
if (!e) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
e->event.base.type = DRM_EXYNOS_G2D_EVENT;
|
|
|
|
e->event.base.length = sizeof(e->event);
|
|
|
|
e->event.user_data = req->user_data;
|
2016-01-12 05:40:57 +08:00
|
|
|
|
|
|
|
ret = drm_event_reserve_init(drm_dev, file, &e->base, &e->event.base);
|
|
|
|
if (ret) {
|
|
|
|
kfree(e);
|
|
|
|
goto err;
|
|
|
|
}
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
node->event = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdlist = node->cmdlist;
|
|
|
|
|
|
|
|
cmdlist->last = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If don't clear SFR registers, the cmdlist is affected by register
|
|
|
|
* values of previous cmdlist. G2D hw executes SFR clear command and
|
|
|
|
* a next command at the same time then the next command is ignored and
|
|
|
|
* is executed rightly from next next command, so needs a dummy command
|
|
|
|
* to next command of SFR clear command.
|
|
|
|
*/
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_SOFT_RESET;
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_SFRCLEAR;
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_SRC_BASE_ADDR;
|
|
|
|
cmdlist->data[cmdlist->last++] = 0;
|
|
|
|
|
2013-03-13 15:44:37 +08:00
|
|
|
/*
|
|
|
|
* 'LIST_HOLD' command should be set to the DMA_HOLD_CMD_REG
|
|
|
|
* and GCF bit should be set to INTEN register if user wants
|
|
|
|
* G2D interrupt event once current command list execution is
|
|
|
|
* finished.
|
|
|
|
* Otherwise only ACF bit should be set to INTEN register so
|
2013-10-24 15:02:57 +08:00
|
|
|
* that one interrupt is occurred after all command lists
|
2013-03-13 15:44:37 +08:00
|
|
|
* have been completed.
|
|
|
|
*/
|
2012-05-17 19:06:32 +08:00
|
|
|
if (node->event) {
|
2013-03-13 15:44:37 +08:00
|
|
|
cmdlist->data[cmdlist->last++] = G2D_INTEN;
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_INTEN_ACF | G2D_INTEN_GCF;
|
2012-05-17 19:06:32 +08:00
|
|
|
cmdlist->data[cmdlist->last++] = G2D_DMA_HOLD_CMD;
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_LIST_HOLD;
|
2013-03-13 15:44:37 +08:00
|
|
|
} else {
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_INTEN;
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_INTEN_ACF;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check size of cmdlist: last 2 is about G2D_BITBLT_START */
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
size = cmdlist->last + req->cmd_nr * 2 + req->cmd_buf_nr * 2 + 2;
|
2012-05-17 19:06:32 +08:00
|
|
|
if (size > G2D_CMDLIST_DATA_NUM) {
|
|
|
|
dev_err(dev, "cmdlist size is too big\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_free_event;
|
|
|
|
}
|
|
|
|
|
2016-02-03 20:42:47 +08:00
|
|
|
cmd = (struct drm_exynos_g2d_cmd *)(unsigned long)req->cmd;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
if (copy_from_user(cmdlist->data + cmdlist->last,
|
|
|
|
(void __user *)cmd,
|
|
|
|
sizeof(*cmd) * req->cmd_nr)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err_free_event;
|
|
|
|
}
|
|
|
|
cmdlist->last += req->cmd_nr * 2;
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
ret = g2d_check_reg_offset(dev, node, req->cmd_nr, false);
|
2012-05-17 19:06:32 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto err_free_event;
|
|
|
|
|
2013-03-13 16:10:08 +08:00
|
|
|
node->buf_info.map_nr = req->cmd_buf_nr;
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
if (req->cmd_buf_nr) {
|
|
|
|
struct drm_exynos_g2d_cmd *cmd_buf;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
2016-02-03 20:42:47 +08:00
|
|
|
cmd_buf = (struct drm_exynos_g2d_cmd *)
|
|
|
|
(unsigned long)req->cmd_buf;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
if (copy_from_user(cmdlist->data + cmdlist->last,
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
(void __user *)cmd_buf,
|
|
|
|
sizeof(*cmd_buf) * req->cmd_buf_nr)) {
|
2012-05-17 19:06:32 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto err_free_event;
|
|
|
|
}
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
cmdlist->last += req->cmd_buf_nr * 2;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
ret = g2d_check_reg_offset(dev, node, req->cmd_buf_nr, true);
|
2012-05-17 19:06:32 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto err_free_event;
|
|
|
|
|
2012-11-04 12:53:24 +08:00
|
|
|
ret = g2d_map_cmdlist_gem(g2d, node, drm_dev, file);
|
2012-05-17 19:06:32 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto err_unmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_BITBLT_START;
|
|
|
|
cmdlist->data[cmdlist->last++] = G2D_START_BITBLT;
|
|
|
|
|
|
|
|
/* head */
|
|
|
|
cmdlist->head = cmdlist->last / 2;
|
|
|
|
|
|
|
|
/* tail */
|
|
|
|
cmdlist->data[cmdlist->last] = 0;
|
|
|
|
|
|
|
|
g2d_add_cmdlist_to_inuse(g2d_priv, node);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_unmap:
|
2012-11-04 12:53:24 +08:00
|
|
|
g2d_unmap_cmdlist_gem(g2d, node, file);
|
2012-05-17 19:06:32 +08:00
|
|
|
err_free_event:
|
2016-01-12 05:40:57 +08:00
|
|
|
if (node->event)
|
|
|
|
drm_event_cancel_free(drm_dev, &node->event->base);
|
2012-05-17 19:06:32 +08:00
|
|
|
err:
|
|
|
|
g2d_put_cmdlist(g2d, node);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int exynos_g2d_exec_ioctl(struct drm_device *drm_dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_exynos_file_private *file_priv = file->driver_priv;
|
|
|
|
struct exynos_drm_g2d_private *g2d_priv = file_priv->g2d_priv;
|
2014-07-23 22:57:12 +08:00
|
|
|
struct device *dev;
|
2012-05-17 19:06:32 +08:00
|
|
|
struct g2d_data *g2d;
|
|
|
|
struct drm_exynos_g2d_exec *req = data;
|
|
|
|
struct g2d_runqueue_node *runqueue_node;
|
|
|
|
struct list_head *run_cmdlist;
|
|
|
|
struct list_head *event_list;
|
|
|
|
|
2014-07-23 22:57:12 +08:00
|
|
|
if (!g2d_priv)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
dev = g2d_priv->dev;
|
2012-05-17 19:06:32 +08:00
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
g2d = dev_get_drvdata(dev);
|
|
|
|
if (!g2d)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
runqueue_node = kmem_cache_alloc(g2d->runqueue_slab, GFP_KERNEL);
|
|
|
|
if (!runqueue_node) {
|
|
|
|
dev_err(dev, "failed to allocate memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
run_cmdlist = &runqueue_node->run_cmdlist;
|
|
|
|
event_list = &runqueue_node->event_list;
|
|
|
|
INIT_LIST_HEAD(run_cmdlist);
|
|
|
|
INIT_LIST_HEAD(event_list);
|
|
|
|
init_completion(&runqueue_node->complete);
|
|
|
|
runqueue_node->async = req->async;
|
|
|
|
|
|
|
|
list_splice_init(&g2d_priv->inuse_cmdlist, run_cmdlist);
|
|
|
|
list_splice_init(&g2d_priv->event_list, event_list);
|
|
|
|
|
|
|
|
if (list_empty(run_cmdlist)) {
|
|
|
|
dev_err(dev, "there is no inuse cmdlist\n");
|
|
|
|
kmem_cache_free(g2d->runqueue_slab, runqueue_node);
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_lock(&g2d->runqueue_mutex);
|
2012-09-11 09:45:36 +08:00
|
|
|
runqueue_node->pid = current->pid;
|
2012-11-04 12:53:24 +08:00
|
|
|
runqueue_node->filp = file;
|
2012-05-17 19:06:32 +08:00
|
|
|
list_add_tail(&runqueue_node->list, &g2d->runqueue);
|
|
|
|
if (!g2d->runqueue_node)
|
|
|
|
g2d_exec_runqueue(g2d);
|
|
|
|
mutex_unlock(&g2d->runqueue_mutex);
|
|
|
|
|
|
|
|
if (runqueue_node->async)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
wait_for_completion(&runqueue_node->complete);
|
|
|
|
g2d_free_runqueue_node(g2d, runqueue_node);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-04 12:53:24 +08:00
|
|
|
static int g2d_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
|
|
|
|
{
|
|
|
|
struct g2d_data *g2d;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
g2d = dev_get_drvdata(dev);
|
|
|
|
if (!g2d)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* allocate dma-aware cmdlist buffer. */
|
|
|
|
ret = g2d_init_cmdlist(g2d);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "cmdlist init failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_iommu_attach_device(drm_dev, dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "failed to enable iommu.\n");
|
|
|
|
g2d_fini_cmdlist(g2d);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
|
|
|
|
{
|
|
|
|
drm_iommu_detach_device(drm_dev, dev);
|
|
|
|
}
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
static int g2d_open(struct drm_device *drm_dev, struct device *dev,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_exynos_file_private *file_priv = file->driver_priv;
|
|
|
|
struct exynos_drm_g2d_private *g2d_priv;
|
|
|
|
|
|
|
|
g2d_priv = kzalloc(sizeof(*g2d_priv), GFP_KERNEL);
|
2013-08-19 18:04:55 +08:00
|
|
|
if (!g2d_priv)
|
2012-05-17 19:06:32 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
g2d_priv->dev = dev;
|
|
|
|
file_priv->g2d_priv = g2d_priv;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&g2d_priv->inuse_cmdlist);
|
|
|
|
INIT_LIST_HEAD(&g2d_priv->event_list);
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
INIT_LIST_HEAD(&g2d_priv->userptr_list);
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void g2d_close(struct drm_device *drm_dev, struct device *dev,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_exynos_file_private *file_priv = file->driver_priv;
|
|
|
|
struct exynos_drm_g2d_private *g2d_priv = file_priv->g2d_priv;
|
|
|
|
struct g2d_data *g2d;
|
|
|
|
struct g2d_cmdlist_node *node, *n;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g2d = dev_get_drvdata(dev);
|
|
|
|
if (!g2d)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mutex_lock(&g2d->cmdlist_mutex);
|
2012-11-04 12:53:24 +08:00
|
|
|
list_for_each_entry_safe(node, n, &g2d_priv->inuse_cmdlist, list) {
|
|
|
|
/*
|
|
|
|
* unmap all gem objects not completed.
|
|
|
|
*
|
|
|
|
* P.S. if current process was terminated forcely then
|
|
|
|
* there may be some commands in inuse_cmdlist so unmap
|
|
|
|
* them.
|
|
|
|
*/
|
|
|
|
g2d_unmap_cmdlist_gem(g2d, node, file);
|
2012-05-17 19:06:32 +08:00
|
|
|
list_move_tail(&node->list, &g2d->free_cmdlist);
|
2012-11-04 12:53:24 +08:00
|
|
|
}
|
2012-05-17 19:06:32 +08:00
|
|
|
mutex_unlock(&g2d->cmdlist_mutex);
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
/* release all g2d_userptr in pool. */
|
|
|
|
g2d_userptr_free_all(drm_dev, g2d, file);
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
kfree(file_priv->g2d_priv);
|
|
|
|
}
|
|
|
|
|
2012-12-22 07:09:25 +08:00
|
|
|
static int g2d_probe(struct platform_device *pdev)
|
2012-05-17 19:06:32 +08:00
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct resource *res;
|
|
|
|
struct g2d_data *g2d;
|
|
|
|
struct exynos_drm_subdrv *subdrv;
|
|
|
|
int ret;
|
|
|
|
|
2013-05-22 20:14:14 +08:00
|
|
|
g2d = devm_kzalloc(dev, sizeof(*g2d), GFP_KERNEL);
|
2013-08-19 18:04:55 +08:00
|
|
|
if (!g2d)
|
2012-05-17 19:06:32 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
g2d->runqueue_slab = kmem_cache_create("g2d_runqueue_slab",
|
|
|
|
sizeof(struct g2d_runqueue_node), 0, 0, NULL);
|
2012-08-06 14:46:20 +08:00
|
|
|
if (!g2d->runqueue_slab)
|
|
|
|
return -ENOMEM;
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
g2d->dev = dev;
|
|
|
|
|
|
|
|
g2d->g2d_workq = create_singlethread_workqueue("g2d");
|
|
|
|
if (!g2d->g2d_workq) {
|
|
|
|
dev_err(dev, "failed to create workqueue\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_destroy_slab;
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_WORK(&g2d->runqueue_work, g2d_runqueue_worker);
|
|
|
|
INIT_LIST_HEAD(&g2d->free_cmdlist);
|
|
|
|
INIT_LIST_HEAD(&g2d->runqueue);
|
|
|
|
|
|
|
|
mutex_init(&g2d->cmdlist_mutex);
|
|
|
|
mutex_init(&g2d->runqueue_mutex);
|
|
|
|
|
2012-11-23 11:41:58 +08:00
|
|
|
g2d->gate_clk = devm_clk_get(dev, "fimg2d");
|
2012-05-17 19:06:32 +08:00
|
|
|
if (IS_ERR(g2d->gate_clk)) {
|
|
|
|
dev_err(dev, "failed to get gate clock\n");
|
|
|
|
ret = PTR_ERR(g2d->gate_clk);
|
2012-11-04 12:53:24 +08:00
|
|
|
goto err_destroy_workqueue;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pm_runtime_enable(dev);
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
|
2013-05-22 20:14:14 +08:00
|
|
|
g2d->regs = devm_ioremap_resource(dev, res);
|
2013-01-21 18:09:02 +08:00
|
|
|
if (IS_ERR(g2d->regs)) {
|
|
|
|
ret = PTR_ERR(g2d->regs);
|
2012-08-06 14:46:20 +08:00
|
|
|
goto err_put_clk;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g2d->irq = platform_get_irq(pdev, 0);
|
|
|
|
if (g2d->irq < 0) {
|
|
|
|
dev_err(dev, "failed to get irq\n");
|
|
|
|
ret = g2d->irq;
|
2012-08-06 14:46:20 +08:00
|
|
|
goto err_put_clk;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
2013-05-22 20:14:14 +08:00
|
|
|
ret = devm_request_irq(dev, g2d->irq, g2d_irq_handler, 0,
|
2012-08-06 14:46:20 +08:00
|
|
|
"drm_g2d", g2d);
|
2012-05-17 19:06:32 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "irq request failed\n");
|
2012-08-06 14:46:20 +08:00
|
|
|
goto err_put_clk;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
drm/exynos: add userptr feature for g2d module
This patch adds userptr feautre for G2D module.
The userptr means user space address allocated by malloc().
And the purpose of this feature is to make G2D's dma able
to access the user space region.
To user this feature, user should flag G2D_BUF_USRPTR to
offset variable of struct drm_exynos_g2d_cmd and fill
struct drm_exynos_g2d_userptr with user space address
and size for it and then should set a pointer to
drm_exynos_g2d_userptr object to data variable of struct
drm_exynos_g2d_cmd. The last bit of offset variable is used
to check if the cmdlist's buffer type is userptr or not.
If userptr, the g2d driver gets user space address and size
and then gets pages through get_user_pages().
(another case is counted as gem handle)
Below is sample codes:
static void set_cmd(struct drm_exynos_g2d_cmd *cmd,
unsigned long offset, unsigned long data)
{
cmd->offset = offset;
cmd->data = data;
}
static int solid_fill_test(int x, int y, unsigned long userptr)
{
struct drm_exynos_g2d_cmd cmd_gem[5];
struct drm_exynos_g2d_userptr g2d_userptr;
unsigned int gem_nr = 0;
...
g2d_userptr.userptr = userptr;
g2d_userptr.size = x * y * 4;
set_cmd(&cmd_gem[gem_nr++], DST_BASE_ADDR_REG |
G2D_BUF_USERPTR,
(unsigned long)&g2d_userptr);
...
}
int main(int argc, char **argv)
{
unsigned long addr;
...
addr = malloc(x * y * 4);
...
solid_fill_test(x, y, addr);
...
}
And next, the pages are mapped with iommu table and the device
address is set to cmdlist so that G2D's dma can access it.
As you may know, the pages from get_user_pages() are pinned.
In other words, they CAN NOT be migrated and also swapped out.
So the dma access would be safe.
But the use of userptr feature has performance overhead so
this patch also has memory pool to the userptr feature.
Please, assume that user sends cmdlist filled with userptr
and size every time to g2d driver, and the get_user_pages
funcion will be called every time.
The memory pool has maximum 64MB size and the userptr that
user had ever sent, is holded in the memory pool.
This meaning is that if the userptr from user is same as one
in the memory pool, device address to the userptr in the memory
pool is set to cmdlist.
And last, the pages from get_user_pages() will be freed once
user calls free() and the dma access is completed. Actually,
get_user_pages() takes 2 reference counts if the user process
has never accessed user region allocated by malloc(). Then, if
the user calls free(), the page reference count becomes 1 and
becomes 0 with put_page() call. And the reverse holds as well.
This means how the pages backed are used by dma and freed.
This patch is based on "drm/exynos: add iommu support for g2d",
https://patchwork.kernel.org/patch/1629481/
Signed-off-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04 21:48:52 +08:00
|
|
|
g2d->max_pool = MAX_POOL;
|
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
platform_set_drvdata(pdev, g2d);
|
|
|
|
|
|
|
|
subdrv = &g2d->subdrv;
|
|
|
|
subdrv->dev = dev;
|
2012-11-04 12:53:24 +08:00
|
|
|
subdrv->probe = g2d_subdrv_probe;
|
|
|
|
subdrv->remove = g2d_subdrv_remove;
|
2012-05-17 19:06:32 +08:00
|
|
|
subdrv->open = g2d_open;
|
|
|
|
subdrv->close = g2d_close;
|
|
|
|
|
|
|
|
ret = exynos_drm_subdrv_register(subdrv);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "failed to register drm g2d device\n");
|
2012-08-06 14:46:20 +08:00
|
|
|
goto err_put_clk;
|
2012-05-17 19:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(dev, "The exynos g2d(ver %d.%d) successfully probed\n",
|
|
|
|
G2D_HW_MAJOR_VER, G2D_HW_MINOR_VER);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_put_clk:
|
|
|
|
pm_runtime_disable(dev);
|
|
|
|
err_destroy_workqueue:
|
|
|
|
destroy_workqueue(g2d->g2d_workq);
|
|
|
|
err_destroy_slab:
|
|
|
|
kmem_cache_destroy(g2d->runqueue_slab);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-22 07:09:25 +08:00
|
|
|
static int g2d_remove(struct platform_device *pdev)
|
2012-05-17 19:06:32 +08:00
|
|
|
{
|
|
|
|
struct g2d_data *g2d = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
cancel_work_sync(&g2d->runqueue_work);
|
|
|
|
exynos_drm_subdrv_unregister(&g2d->subdrv);
|
|
|
|
|
|
|
|
while (g2d->runqueue_node) {
|
|
|
|
g2d_free_runqueue_node(g2d, g2d->runqueue_node);
|
|
|
|
g2d->runqueue_node = g2d_get_runqueue_node(g2d);
|
|
|
|
}
|
|
|
|
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
|
|
|
|
g2d_fini_cmdlist(g2d);
|
|
|
|
destroy_workqueue(g2d->g2d_workq);
|
|
|
|
kmem_cache_destroy(g2d->runqueue_slab);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int g2d_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct g2d_data *g2d = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
mutex_lock(&g2d->runqueue_mutex);
|
|
|
|
g2d->suspended = true;
|
|
|
|
mutex_unlock(&g2d->runqueue_mutex);
|
|
|
|
|
|
|
|
while (g2d->runqueue_node)
|
|
|
|
/* FIXME: good range? */
|
|
|
|
usleep_range(500, 1000);
|
|
|
|
|
2012-08-21 05:51:24 +08:00
|
|
|
flush_work(&g2d->runqueue_work);
|
2012-05-17 19:06:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int g2d_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct g2d_data *g2d = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
g2d->suspended = false;
|
|
|
|
g2d_exec_runqueue(g2d);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-04 08:04:55 +08:00
|
|
|
#ifdef CONFIG_PM
|
2013-07-24 14:44:30 +08:00
|
|
|
static int g2d_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct g2d_data *g2d = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_disable_unprepare(g2d->gate_clk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int g2d_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct g2d_data *g2d = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(g2d->gate_clk);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_warn(dev, "failed to enable clock.\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct dev_pm_ops g2d_pm_ops = {
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(g2d_suspend, g2d_resume)
|
|
|
|
SET_RUNTIME_PM_OPS(g2d_runtime_suspend, g2d_runtime_resume, NULL)
|
|
|
|
};
|
2012-05-17 19:06:32 +08:00
|
|
|
|
2013-02-06 13:29:44 +08:00
|
|
|
static const struct of_device_id exynos_g2d_match[] = {
|
|
|
|
{ .compatible = "samsung,exynos5250-g2d" },
|
2014-07-20 04:53:03 +08:00
|
|
|
{ .compatible = "samsung,exynos4212-g2d" },
|
2013-02-06 13:29:44 +08:00
|
|
|
{},
|
|
|
|
};
|
2014-07-30 10:28:31 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, exynos_g2d_match);
|
2013-02-06 13:29:44 +08:00
|
|
|
|
2012-05-17 19:06:32 +08:00
|
|
|
struct platform_driver g2d_driver = {
|
|
|
|
.probe = g2d_probe,
|
2012-12-22 07:09:25 +08:00
|
|
|
.remove = g2d_remove,
|
2012-05-17 19:06:32 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "s5p-g2d",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.pm = &g2d_pm_ops,
|
2013-08-28 13:17:56 +08:00
|
|
|
.of_match_table = exynos_g2d_match,
|
2012-05-17 19:06:32 +08:00
|
|
|
},
|
|
|
|
};
|