Skip to content

Commit cccb1eb

Browse files
SandeepSMcristibirsan
authored andcommitted
DRM: atmel_hlcdc_dc: Add gem get ioctl
Add ioctl to export GEM physical address to user space for video decoder. Signed-off-by: Sandeep Sheriker Mallikarjun <sandeepsheriker.mallikarjun@microchip.com>
1 parent 913046c commit cccb1eb

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

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

Lines changed: 40 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

@@ -738,8 +739,45 @@ static void atmel_hlcdc_dc_irq_uninstall(struct drm_device *dev)
738739
regmap_read(dc->hlcdc->regmap, ATMEL_HLCDC_ISR, &isr);
739740
}
740741

742+
743+
741744
DEFINE_DRM_GEM_CMA_FOPS(fops);
742745

746+
/*
747+
ioctl to export the physical address of GEM to user space for
748+
video decoder
749+
*/
750+
int atmel_drm_gem_get_ioctl(struct drm_device *drm, void *data,
751+
struct drm_file *file_priv)
752+
{
753+
struct drm_gem_object *gem_obj;
754+
struct drm_gem_cma_object *cma_obj;
755+
struct drm_mode_map_dumb *args = data;
756+
757+
mutex_lock(&drm->struct_mutex);
758+
759+
gem_obj = drm_gem_object_lookup(file_priv, args->handle);
760+
if (!gem_obj) {
761+
dev_err(drm->dev, "failed to lookup gem object\n");
762+
mutex_unlock(&drm->struct_mutex);
763+
return -EINVAL;
764+
}
765+
766+
cma_obj = to_drm_gem_cma_obj(gem_obj);
767+
args->offset = (__u64)cma_obj->paddr;
768+
769+
drm_gem_object_unreference(gem_obj);
770+
771+
mutex_unlock(&drm->struct_mutex);
772+
773+
return 0;
774+
}
775+
static const struct drm_ioctl_desc atmel_ioctls[] = {
776+
DRM_IOCTL_DEF_DRV(ATMEL_GEM_GET, atmel_drm_gem_get_ioctl,
777+
DRM_CONTROL_ALLOW|DRM_UNLOCKED),
778+
};
779+
780+
743781
static struct drm_driver atmel_hlcdc_dc_driver = {
744782
.driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM |
745783
DRIVER_MODESET | DRIVER_PRIME |
@@ -761,6 +799,8 @@ static struct drm_driver atmel_hlcdc_dc_driver = {
761799
.gem_prime_vunmap = drm_gem_cma_prime_vunmap,
762800
.gem_prime_mmap = drm_gem_cma_prime_mmap,
763801
.dumb_create = drm_gem_cma_dumb_create,
802+
.ioctls = atmel_ioctls,
803+
.num_ioctls= ARRAY_SIZE(atmel_ioctls),
764804
.fops = &fops,
765805
.name = "atmel-hlcdc",
766806
.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)