linux/drivers/gpu/drm/exynos
Inki Dae 2a3098ff6c 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-12-04 14:46:01 +09:00
..
exynos_ddc.c Merge branch 'exynos-drm-next' of git://git.infradead.org/users/kmpark/linux-samsung into drm-next 2012-10-07 21:06:33 +10:00
exynos_drm_buf.c drm/exynos: add iommu support for exynos drm framework 2012-11-29 03:30:35 -08:00
exynos_drm_buf.h drm/exynos: update gem and buffer framework. 2012-03-20 09:40:21 +00:00
exynos_drm_connector.c drm/exynos: fix display on issue 2012-10-31 06:11:29 -07:00
exynos_drm_connector.h drm/exynos: fix display power call issue. 2012-10-04 10:06:01 +09:00
exynos_drm_core.c Merge branch 'exynos-drm-next' of git://git.infradead.org/users/kmpark/linux-samsung into drm-next 2012-10-07 21:06:33 +10:00
exynos_drm_crtc.c drm/exynos: hold event_lock while accessing pageflip_event_list 2012-11-29 03:30:33 -08:00
exynos_drm_crtc.h drm/exynos: update overlay via plane from crtc 2012-07-27 11:13:53 +09:00
exynos_drm_dmabuf.c drm/exynos: remove unnecessary sg_alloc_table call 2012-12-04 14:46:00 +09:00
exynos_drm_dmabuf.h drm/exynos: added drm prime feature. 2012-05-08 18:46:32 +09:00
exynos_drm_drv.c drm/exynos: add iommu support for exynos drm framework 2012-11-29 03:30:35 -08:00
exynos_drm_drv.h drm/exynos: add userptr feature for g2d module 2012-12-04 14:46:01 +09:00
exynos_drm_encoder.c drm/exynos: Fix potential NULL pointer dereference in exynos_drm_encoder.c 2012-11-29 03:30:33 -08:00
exynos_drm_encoder.h drm/exynos: add plane enable/disable 2012-07-27 11:13:54 +09:00
exynos_drm_fb.c drm/exynos: add iommu support for exynos drm framework 2012-11-29 03:30:35 -08:00
exynos_drm_fb.h drm/exynos: check NV12M format specific to Exynos properly 2012-10-04 10:06:00 +09:00
exynos_drm_fbdev.c drm/exynos: fix linux framebuffer address setting. 2012-11-29 03:30:33 -08:00
exynos_drm_fbdev.h
exynos_drm_fimd.c drm/exynos: add iommu support to fimd driver 2012-11-29 03:30:35 -08:00
exynos_drm_g2d.c drm/exynos: add userptr feature for g2d module 2012-12-04 14:46:01 +09:00
exynos_drm_g2d.h drm/exynos: add G2D driver 2012-05-17 20:14:48 +09:00
exynos_drm_gem.c drm/exynos: add userptr feature for g2d module 2012-12-04 14:46:01 +09:00
exynos_drm_gem.h drm/exynos: add userptr feature for g2d module 2012-12-04 14:46:01 +09:00
exynos_drm_hdmi.c drm/exynos: add iommu support for hdmi driver 2012-12-04 14:45:53 +09:00
exynos_drm_hdmi.h drm/exynos: add iommu support for hdmi driver 2012-12-04 14:45:53 +09:00
exynos_drm_iommu.c drm/exynos: add iommu support for exynos drm framework 2012-11-29 03:30:35 -08:00
exynos_drm_iommu.h drm/exynos: add iommu support for exynos drm framework 2012-11-29 03:30:35 -08:00
exynos_drm_plane.c drm/exynos: remove unnecessary code. 2012-11-29 03:30:33 -08:00
exynos_drm_plane.h drm/exynos: add plane enable/disable 2012-07-27 11:13:54 +09:00
exynos_drm_vidi.c drm/exynos: fix lockdep for event_lock wrt. vbl_time_lock 2012-11-29 03:30:34 -08:00
exynos_drm_vidi.h drm/exynos: added virtual display driver. 2012-03-21 10:15:49 +00:00
exynos_hdmi.c drm/exynos: add iommu support for hdmi driver 2012-12-04 14:45:53 +09:00
exynos_hdmi.h drm/exynos: cleanup exynos_hdmi.h 2012-03-20 09:41:45 +00:00
exynos_hdmiphy.c Merge branch 'exynos-drm-next' of git://git.infradead.org/users/kmpark/linux-samsung into drm-next 2012-10-07 21:06:33 +10:00
exynos_mixer.c drm/exynos: add iommu support for hdmi driver 2012-12-04 14:45:53 +09:00
Kconfig drm/exynos: add iommu support for exynos drm framework 2012-11-29 03:30:35 -08:00
Makefile drm/exynos: add iommu support for exynos drm framework 2012-11-29 03:30:35 -08:00
regs-hdmi.h drm/exynos: enable dvi mode for dvi monitor 2012-05-17 20:14:25 +09:00
regs-mixer.h drm: exynos: hdmi: add support for exynos5 mixer 2012-10-05 19:15:10 +09:00
regs-vp.h drm/exynos: added hdmi display support 2011-12-29 11:21:42 +09:00