Skip to content

Commit 03ab237

Browse files
Jamsheethcristibirsan
authored andcommitted
drm: atmel-hlcdc: Add IOCTL to export the phy addr of gem
Added an IOCTL that exports the physical address of buffer to user space, so the vdec in userspace can perform DMA operations. Signed-off-by: Mohamed Jamsheeth Hajanajubudeen <mohamedjamsheeth.hajanajubudeen@atmel.com>
1 parent 5fec19a commit 03ab237

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/pm_runtime.h>
2727

2828
#include "atmel_hlcdc_dc.h"
29+
#include <drm/atmel_drm.h>
2930

3031
#define ATMEL_HLCDC_LAYER_IRQS_OFFSET 8
3132

@@ -740,6 +741,41 @@ static void atmel_hlcdc_dc_irq_uninstall(struct drm_device *dev)
740741

741742
DEFINE_DRM_GEM_CMA_FOPS(fops);
742743

744+
/*
745+
ioctl to export the physical address of GEM to user space for
746+
video decoder
747+
*/
748+
int atmel_drm_gem_get_ioctl(struct drm_device *drm, void *data,
749+
struct drm_file *file_priv)
750+
{
751+
struct drm_gem_object *gem_obj;
752+
struct drm_gem_cma_object *cma_obj;
753+
struct drm_mode_map_dumb *args = data;
754+
755+
mutex_lock(&drm->struct_mutex);
756+
757+
gem_obj = drm_gem_object_lookup(file_priv, args->handle);
758+
if (!gem_obj) {
759+
dev_err(drm->dev, "failed to lookup gem object\n");
760+
mutex_unlock(&drm->struct_mutex);
761+
return -EINVAL;
762+
}
763+
764+
cma_obj = to_drm_gem_cma_obj(gem_obj);
765+
args->offset = (__u64)cma_obj->paddr;
766+
767+
drm_gem_object_unreference(gem_obj);
768+
769+
mutex_unlock(&drm->struct_mutex);
770+
771+
return 0;
772+
}
773+
static const struct drm_ioctl_desc atmel_ioctls[] = {
774+
DRM_IOCTL_DEF_DRV(ATMEL_GEM_GET, atmel_drm_gem_get_ioctl,
775+
DRM_CONTROL_ALLOW|DRM_UNLOCKED),
776+
};
777+
778+
743779
static struct drm_driver atmel_hlcdc_dc_driver = {
744780
.driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM |
745781
DRIVER_MODESET | DRIVER_PRIME |
@@ -761,6 +797,8 @@ static struct drm_driver atmel_hlcdc_dc_driver = {
761797
.gem_prime_vunmap = drm_gem_cma_prime_vunmap,
762798
.gem_prime_mmap = drm_gem_cma_prime_mmap,
763799
.dumb_create = drm_gem_cma_dumb_create,
800+
.ioctls = atmel_ioctls,
801+
.num_ioctls= ARRAY_SIZE(atmel_ioctls),
764802
.fops = &fops,
765803
.name = "atmel-hlcdc",
766804
.desc = "Atmel HLCD Controller DRM",

include/uapi/drm/atmel_drm.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2014 Atmel
3+
*
4+
* Author: Mohamed Jamsheeth <mohamedjamsheeth.hajanajubudeen@atmel.com>
5+
*
6+
* This program is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 as published by
8+
* the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13+
* more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along with
16+
* this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef _UAPI_ATMEL_DRM_H_
20+
#define _UAPI_ATMEL_DRM_H_
21+
22+
#include <drm/drm.h>
23+
24+
#define DRM_ATMEL_GEM_GET 0x00
25+
26+
#define DRM_IOCTL_ATMEL_GEM_GET DRM_IOWR(DRM_COMMAND_BASE + \
27+
DRM_ATMEL_GEM_GET, struct drm_mode_map_dumb)
28+
29+
#endif /* _UAPI_ATMEL_DRM_H_ */

0 commit comments

Comments
 (0)