public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
From: Frank Binns <frank.binns@imgtec.com>
To: Philipp Zabel <p.zabel@pengutronix.de>, dri-devel@lists.freedesktop.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, Paul Bolle <pebolle@tiscali.nl>,
	Nicolas Boichat <drinkcat@chromium.org>,
	Jitao Shi <jitao.shi@mediatek.com>,
	Pawel Moll <pawel.moll@arm.com>, Jie Qiu <jie.qiu@mediatek.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Cawa Cheng <cawa.cheng@mediatek.com>,
	Tomasz Figa <tfiga@chromium.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	linux-mediatek@lists.infradead.org, kernel@pengutronix.de,
	Kumar Gala <galak@codeaurora.org>, YT Shen <yt.shen@mediatek.com>,
	Yingjoe Chen <yingjoe.chen@mediatek.com>
Subject: Re: [PATCH v9 14/14] drm/mediatek: Add interface to allocate Mediatek GEM buffer.
Date: Tue, 12 Jan 2016 15:47:58 +0000	[thread overview]
Message-ID: <5695202E.1090603@imgtec.com> (raw)
In-Reply-To: <1452611750-16283-15-git-send-email-p.zabel@pengutronix.de>

Hi Philipp,

Comments below.

On 12/01/16 15:15, Philipp Zabel wrote:
> From: CK Hu <ck.hu@mediatek.com>
>
> Add an interface to allocate Mediatek GEM buffers, allow the IOCTLs
> to be used by render nodes.
> This patch also sets the RENDER driver feature.
>
> Signed-off-by: CK Hu <ck.hu@mediatek.com>
> Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 +++++++-
>  drivers/gpu/drm/mediatek/mtk_drm_gem.c | 39 ++++++++++++++++++++++
>  drivers/gpu/drm/mediatek/mtk_drm_gem.h | 12 +++++++
>  include/uapi/drm/mediatek_drm.h        | 59 ++++++++++++++++++++++++++++++++++
>  4 files changed, 122 insertions(+), 1 deletion(-)
>  create mode 100644 include/uapi/drm/mediatek_drm.h
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index fdb27e9..1f776a9 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -22,6 +22,7 @@
>  #include <linux/of_address.h>
>  #include <linux/of_platform.h>
>  #include <linux/pm_runtime.h>
> +#include <drm/mediatek_drm.h>
>  
>  #include "mtk_cec.h"
>  #include "mtk_drm_crtc.h"
> @@ -222,6 +223,14 @@ static const struct vm_operations_struct mtk_drm_gem_vm_ops = {
>  	.close = drm_gem_vm_close,
>  };
>  
> +static const struct drm_ioctl_desc mtk_ioctls[] = {
> +	DRM_IOCTL_DEF_DRV(MTK_GEM_CREATE, mtk_gem_create_ioctl,
> +			  DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
> +	DRM_IOCTL_DEF_DRV(MTK_GEM_MAP_OFFSET,
> +			  mtk_gem_map_offset_ioctl,
> +			  DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
> +};
> +
>  static const struct file_operations mtk_drm_fops = {
>  	.owner = THIS_MODULE,
>  	.open = drm_open,
> @@ -237,7 +246,7 @@ static const struct file_operations mtk_drm_fops = {
>  
>  static struct drm_driver mtk_drm_driver = {
>  	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
> -			   DRIVER_ATOMIC,
> +			   DRIVER_ATOMIC | DRIVER_RENDER,
>  	.unload = mtk_drm_unload,
>  	.set_busid = drm_platform_set_busid,
>  
> @@ -257,6 +266,8 @@ static struct drm_driver mtk_drm_driver = {
>  	.gem_prime_import = drm_gem_prime_import,
>  	.gem_prime_get_sg_table = mtk_gem_prime_get_sg_table,
>  	.gem_prime_mmap = mtk_drm_gem_mmap_buf,
> +	.ioctls = mtk_ioctls,
> +	.num_ioctls = ARRAY_SIZE(mtk_ioctls),
>  	.fops = &mtk_drm_fops,
>  
>  	.name = DRIVER_NAME,
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> index 96cc980..f726d55 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
> @@ -13,6 +13,7 @@
>  
>  #include <drm/drmP.h>
>  #include <drm/drm_gem.h>
> +#include <drm/mediatek_drm.h>
>  
>  #include "mtk_drm_gem.h"
>  
> @@ -225,3 +226,41 @@ struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj)
>  
>  	return sgt;
>  }
> +
> +int mtk_gem_map_offset_ioctl(struct drm_device *drm, void *data,
> +			     struct drm_file *file_priv)
> +{
> +	struct drm_mtk_gem_map_off *args = data;
> +
You should validate args->pad here.

> +	return mtk_drm_gem_dumb_map_offset(file_priv, drm, args->handle,
> +					   &args->offset);
> +}
> +
> +int mtk_gem_create_ioctl(struct drm_device *dev, void *data,
> +			 struct drm_file *file_priv)
> +{
> +	struct mtk_drm_gem_obj *mtk_gem;
> +	struct drm_mtk_gem_create *args = data;
> +	int ret;
> +
You should validate args->flags here.

> +	mtk_gem = mtk_drm_gem_create(dev, args->size, false);
> +	if (IS_ERR(mtk_gem))
> +		return PTR_ERR(mtk_gem);
> +
> +	/*
> +	 * allocate a id of idr table where the obj is registered
> +	 * and handle has the id what user can see.
> +	 */
This comment doesn't seem that useful.

> +	ret = drm_gem_handle_create(file_priv, &mtk_gem->base, &args->handle);
> +	if (ret)
> +		goto err_handle_create;
> +
> +	/* drop reference from allocate - handle holds it now. */
> +	drm_gem_object_unreference_unlocked(&mtk_gem->base);
> +
> +	return 0;
> +
> +err_handle_create:
> +	mtk_drm_gem_free_object(&mtk_gem->base);
> +	return ret;
> +}
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.h b/drivers/gpu/drm/mediatek/mtk_drm_gem.h
> index 9bdeeb3..28b8fa7 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.h
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.h
> @@ -52,4 +52,16 @@ int mtk_drm_gem_mmap_buf(struct drm_gem_object *obj,
>  		struct vm_area_struct *vma);
>  struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj);
>  
> +/*
> + * request gem object creation and buffer allocation as the size
> + * that it is calculated with framebuffer information such as width,
> + * height and bpp.
> + */
> +int mtk_gem_create_ioctl(struct drm_device *dev, void *data,
> +		struct drm_file *file_priv);
> +
> +/* get buffer offset to map to user space. */
> +int mtk_gem_map_offset_ioctl(struct drm_device *dev, void *data,
> +		struct drm_file *file_priv);
> +
>  #endif
> diff --git a/include/uapi/drm/mediatek_drm.h b/include/uapi/drm/mediatek_drm.h
> new file mode 100644
> index 0000000..19ea357
> --- /dev/null
> +++ b/include/uapi/drm/mediatek_drm.h
> @@ -0,0 +1,59 @@
> +/*
> + * Copyright (c) 2015 MediaTek Inc.
> + *
> + * 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 Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +
> +#ifndef _UAPI_MEDIATEK_DRM_H
> +#define _UAPI_MEDIATEK_DRM_H
> +
> +#include <drm/drm.h>
> +
> +/**
> + * User-desired buffer creation information structure.
> + *
> + * @size: user-desired memory allocation size.
> + *	- this size value would be page-aligned internally.
> + * @flags: user request for setting memory type or cache attributes.
> + * @handle: returned a handle to created gem object.
> + *	- this handle will be set by gem module of kernel side.
> + */
> +struct drm_mtk_gem_create {
> +	uint64_t size;
> +	uint32_t flags;
> +	uint32_t handle;
> +};
These should be __u32 and friends according to the kernel CodingStyle doc.

> +
> +/**
> + * A structure for getting buffer offset.
> + *
> + * @handle: a pointer to gem object created.
> + * @pad: just padding to be 64-bit aligned.
> + * @offset: relatived offset value of the memory region allocated.
> + *     - this value should be set by user.
relatived -> relative?

Also, the 'offset' documentation doesn't seem right as this will be set
by the kernel?

> + */
> +struct drm_mtk_gem_map_off {
> +	uint32_t handle;
> +	uint32_t pad;
> +	uint64_t offset;
> +};
These should also be __u32 and friends.

> +
> +#define DRM_MTK_GEM_CREATE		0x00
> +#define DRM_MTK_GEM_MAP_OFFSET		0x01
> +
> +#define DRM_IOCTL_MTK_GEM_CREATE	DRM_IOWR(DRM_COMMAND_BASE + \
> +		DRM_MTK_GEM_CREATE, struct drm_mtk_gem_create)
> +
> +#define DRM_IOCTL_MTK_GEM_MAP_OFFSET	DRM_IOWR(DRM_COMMAND_BASE + \
> +		DRM_MTK_GEM_MAP_OFFSET, struct drm_mtk_gem_map_off)
> +
> +
> +#endif /* _UAPI_MEDIATEK_DRM_H */

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2016-01-12 15:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 15:15 [PATCH v9 00/14] MT8173 DRM support Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 01/14] dt-bindings: drm/mediatek: Add Mediatek display subsystem dts binding Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 02/14] drm/mediatek: Add DRM Driver for Mediatek SoC MT8173 Philipp Zabel
2016-01-20 22:23   ` Daniel Kurtz
2016-02-03 14:31     ` Philipp Zabel
2016-02-02 17:09   ` Daniel Kurtz
2016-02-02 17:12   ` Daniel Kurtz
2016-02-03 14:31     ` Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 03/14] drm/mediatek: Add DSI sub driver Philipp Zabel
2016-02-02 13:32   ` Daniel Kurtz
2016-02-03 11:01     ` Philipp Zabel
     [not found]       ` <1454497304.3867.1.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-02-04  6:37         ` CK Hu
2016-02-04 12:24           ` Daniel Kurtz
2016-02-04 12:48           ` Philipp Zabel
     [not found]             ` <1454590099.3356.22.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-02-05  9:06               ` CK Hu
2016-01-12 15:15 ` [PATCH v9 04/14] drm/mediatek: Add DPI " Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 05/14] dt-bindings: drm/mediatek: Add Mediatek HDMI dts binding Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 06/14] drm/mediatek: Add HDMI support Philipp Zabel
     [not found] ` <1452611750-16283-1-git-send-email-p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-01-12 15:15   ` [PATCH v9 07/14] drm/mediatek: enable hdmi output control bit Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 08/14] arm64: dts: mt8173: Add display subsystem related nodes Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 09/14] arm64: dts: mt8173: Add HDMI " Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 10/14] clk: mediatek: make dpi0_sel propagate rate changes Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 11/14] clk: mediatek: Add hdmi_ref HDMI PHY PLL reference clock output Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 12/14] dt-bindings: hdmi-connector: add DDC I2C bus phandle documentation Philipp Zabel
2016-01-12 15:15 ` [PATCH v9 13/14] clk: mediatek: remove hdmitx_dig_cts from TOP clocks Philipp Zabel
2016-02-25 23:09   ` Stephen Boyd
2016-01-12 15:15 ` [PATCH v9 14/14] drm/mediatek: Add interface to allocate Mediatek GEM buffer Philipp Zabel
2016-01-12 15:47   ` Frank Binns [this message]
2016-01-12 22:02   ` Rob Herring
2016-01-12 22:40     ` Daniel Vetter
2016-01-13 11:42       ` Philipp Zabel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5695202E.1090603@imgtec.com \
    --to=frank.binns@imgtec.com \
    --cc=cawa.cheng@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=drinkcat@chromium.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=jie.qiu@mediatek.com \
    --cc=jitao.shi@mediatek.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mturquette@baylibre.com \
    --cc=p.zabel@pengutronix.de \
    --cc=pawel.moll@arm.com \
    --cc=pebolle@tiscali.nl \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@codeaurora.org \
    --cc=tfiga@chromium.org \
    --cc=yingjoe.chen@mediatek.com \
    --cc=yt.shen@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox