Skip to contentSkip to conversation

DRM: add DRM Driver for Samsung SoC EXYNOS4210.

PATCH Superseded Inki Dae 7 participants 24 messages Sep 9, 2011 – Sep 22, 2011 Page 1 of 2

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Inki Dae

author
#0 lore raw

PATCH v4 1/1 DRM: add DRM Driver for Samsung SoC EXYNOS4210.

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:
v1: < https://lwn.net/Articles/454380/ >
v2: < http://www.spinics.net/lists/kernel/msg1224275.html >
v3: < http://www.gossamer-threads.com/lists/linux/kernel/1423684 >

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework can regiter only one irq handler this patch supports mutiple irq for Samsung SoC.

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead of drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

samsung_drm.h would contain only public information for userspace ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---
 drivers/gpu/drm/Kconfig                         |    2 +
 drivers/gpu/drm/Makefile                        |    1 +
 drivers/gpu/drm/samsung/Kconfig                 |   18 +
 drivers/gpu/drm/samsung/Makefile                |   11 +
 drivers/gpu/drm/samsung/samsung_drm_buf.c       |  109 ++++
 drivers/gpu/drm/samsung/samsung_drm_buf.h       |   50 ++
 drivers/gpu/drm/samsung/samsung_drm_connector.c |  257 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_connector.h |   34 ++
 drivers/gpu/drm/samsung/samsung_drm_core.c      |  213 ++++++++
 drivers/gpu/drm/samsung/samsung_drm_crtc.c      |  329 ++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_crtc.h      |   38 ++
 drivers/gpu/drm/samsung/samsung_drm_drv.c       |  215 ++++++++
 drivers/gpu/drm/samsung/samsung_drm_drv.h       |  194 +++++++
 drivers/gpu/drm/samsung/samsung_drm_encoder.c   |  261 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_encoder.h   |   45 ++
 drivers/gpu/drm/samsung/samsung_drm_fb.c        |  262 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_fb.h        |   47 ++
 drivers/gpu/drm/samsung/samsung_drm_fbdev.c     |  409 ++++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_fbdev.h     |   37 ++
 drivers/gpu/drm/samsung/samsung_drm_fimd.c      |  643 +++++++++++++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_gem.c       |  492 +++++++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_gem.h       |   98 ++++
 include/drm/samsung_drm.h                       |  103 ++++
 23 files changed, 3868 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/samsung/Kconfig
 create mode 100644 drivers/gpu/drm/samsung/Makefile
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_buf.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_buf.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_connector.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_connector.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_core.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_crtc.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_crtc.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_drv.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_drv.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_encoder.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_encoder.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fb.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fb.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fbdev.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fbdev.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fimd.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_gem.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_gem.h
 create mode 100644 include/drm/samsung_drm.h
drivers/gpu/drm/Kconfig +2 -0
index b493663..ce6d3ec 100644
@@ -158,3 +158,5 @@ config DRM_SAVAGE
 	help
 	  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
 	  chipset. If M is selected the module will be called savage.
+
+source "drivers/gpu/drm/samsung/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 89cf05a..0c6e773 100644
@@ -35,4 +35,5 @@ obj-$(CONFIG_DRM_SAVAGE)+= savage/
 obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
 obj-$(CONFIG_DRM_VIA)	+=via/
 obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
+obj-$(CONFIG_DRM_SAMSUNG) +=samsung/
 obj-y			+= i2c/
drivers/gpu/drm/samsung/Kconfig new file +18 -0
new file mode 100644
index 0000000..34cedda
@@ -0,0 +1,18 @@
+config DRM_SAMSUNG
+	tristate "DRM Support for Samsung SoC EXYNOS Series"
+	depends on DRM && PLAT_SAMSUNG
+	select DRM_KMS_HELPER
+	select FB_CFB_FILLRECT
+	select FB_CFB_COPYAREA
+	select FB_CFB_IMAGEBLIT
+	select VT_HW_CONSOLE_BINDING if FRAMEBUFFER_CONSOLE
+	help
+	  Choose this option if you have a Samsung SoC EXYNOS chipset.
+	  If M is selected the module will be called samsungdrm.
+
+config DRM_SAMSUNG_FIMD
+	tristate "Samsung DRM FIMD"
+	depends on DRM_SAMSUNG
+	help
+	  Choose this option if you want to use Samsung FIMD for DRM.
+	  If M is selected, the module will be called samsung_drm_fimd
drivers/gpu/drm/samsung/Makefile new file +11 -0
new file mode 100644
index 0000000..70f89f3
@@ -0,0 +1,11 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/samsung
+samsungdrm-y := samsung_drm_drv.o samsung_drm_encoder.o samsung_drm_connector.o \
+		samsung_drm_crtc.o samsung_drm_fbdev.o samsung_drm_fb.o \
+		samsung_drm_buf.o samsung_drm_gem.o samsung_drm_core.o
+
+obj-$(CONFIG_DRM_SAMSUNG) += samsungdrm.o
+obj-$(CONFIG_DRM_SAMSUNG_FIMD) += samsung_drm_fimd.o
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +109 -0

109 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_buf.h new file +50 -0

50 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_connector.c new file +257 -0

257 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_connector.h new file +34 -0
new file mode 100644
index 0000000..638d2b3
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_CONNECTOR_H_
+#define _SAMSUNG_DRM_CONNECTOR_H_
+
+struct drm_connector *samsung_drm_connector_create(struct drm_device *dev,
+						   struct drm_encoder *encoder);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_core.c new file +213 -0

213 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +329 -0

329 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +38 -0
new file mode 100644
index 0000000..c6998e1
@@ -0,0 +1,38 @@
+/* samsung_drm_crtc.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_CRTC_H_
+#define _SAMSUNG_DRM_CRTC_H_
+
+struct samsung_drm_overlay *get_samsung_drm_overlay(struct drm_device *dev,
+		struct drm_crtc *crtc);
+int samsung_drm_crtc_create(struct drm_device *dev, unsigned int nr);
+int samsung_drm_crtc_enable_vblank(struct drm_device *dev, int crtc);
+void samsung_drm_crtc_disable_vblank(struct drm_device *dev, int crtc);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +215 -0

215 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_drv.h new file +194 -0

194 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +261 -0

261 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +45 -0

45 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_fb.c new file +262 -0

262 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_fb.h new file +47 -0

47 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +409 -0

409 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +37 -0
new file mode 100644
index 0000000..3ef4e0d
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_FBDEV_H_
+#define _SAMSUNG_DRM_FBDEV_H_
+
+int samsung_drm_fbdev_init(struct drm_device *dev);
+int samsung_drm_fbdev_reinit(struct drm_device *dev);
+void samsung_drm_fbdev_fini(struct drm_device *dev);
+void samsung_drm_fbdev_restore_mode(struct drm_device *dev);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +643 -0

461 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_gem.c new file +492 -0

492 lines not on this page · raw message

drivers/gpu/drm/samsung/samsung_drm_gem.h new file +98 -0

98 lines not on this page · raw message

include/drm/samsung_drm.h new file +103 -0

103 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.0.4

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 94 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:

v1:<  https://lwn.net/Articles/454380/>
v2:<  http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<  http://www.gossamer-threads.com/lists/linux/kernel/1423684>

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework can regiter only one irq handler this patch supports mutiple irq for Samsung SoC.

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead of drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

samsung_drm.h would contain only public information for userspace ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---

drivers/gpu/drm/samsung/samsung_drm_drv.c line 130

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +3 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+			DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other device drivers to see an OOM, or only DRM?

The old DRI model basically allowed any authorized DRI client to exhaust video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily exhaust resources (DMA memory) used by other device drivers causing them to fail.

/Thomas

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +6 -0
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MAP_OFFSET,
+			samsung_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
+				DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MMAP,
+			samsung_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
+};
#2 lore raw
Quoted 111 lines · Thomas Hellstrom
Quoted 92 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:
v1:<  https://lwn.net/Articles/454380/>
v2:<  http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<  http://www.gossamer-threads.com/lists/linux/kernel/1423684>

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

    this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

    FIMD and HDMI have their own irq handler but DRM Framework can regiter only one irq handler this patch supports mutiple irq for Samsung SoC.

DRM: Consider modularization.

    each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

    crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
    created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

    is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
    this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead of drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

    samsung_drm.h would contain only public information for userspace ioctl interface.

DRM: code refactoring to gem modules.
    buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

    samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

Quoted 7 lines

---

+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+                       DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other device drivers to see an OOM, or only DRM?

Quoted 7 lines

The old DRI model basically allowed any authorized DRI client to exhaust video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily exhaust resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

In the samsung driver case, he is only allocating scanout memory from CMA, so the limit will be the CMA region size.. beyond that you can't get physically contiguous memory. So I think this driver is safe.

In the omap driver case, I'm also allowing allocation of shmem backed buffers. So perhaps I need a threshold of how many buffers can have pages attached. Offhand, I'd have to think about how to handle that..
have any of the other UMA gfx drivers dealt with this yet?

BR,
-R

Quoted 20 lines

/Thomas

Quoted 9 lines

+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MAP_OFFSET,
+                       samsung_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
+                               DRM_AUTH),
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MMAP,
+                       samsung_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
+};

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 118 lines · Rob Clark
Quoted 116 lines · Thomas Hellstrom
Quoted 95 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:

v1:<    https://lwn.net/Articles/454380/>
v2:<    http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<    http://www.gossamer-threads.com/lists/linux/kernel/1423684>

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework can regiter only one irq handler this patch supports mutiple irq for Samsung SoC.

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead of drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

samsung_drm.h would contain only public information for userspace ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---

(quoted diff) +2 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE,
Quoted 4 lines

samsung_drm_gem_create_ioctl,
+ DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other device drivers to see an OOM, or only DRM?

The old DRI model basically allowed any authorized DRI client to exhaust video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

Quoted 6 lines
Quoted 3 lines

I don't think an authorized DRI client should be able to easily exhaust resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 4 lines

In the samsung driver case, he is only allocating scanout memory from CMA, so the limit will be the CMA region size.. beyond that you can't get physically contiguous memory. So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should be a concern, but what compromized application *might* do that is a concern.

Quoted 5 lines

In the omap driver case, I'm also allowing allocation of shmem backed buffers. So perhaps I need a threshold of how many buffers can have pages attached. Offhand, I'd have to think about how to handle that..
have any of the other UMA gfx drivers dealt with this yet?

I think shmem pages are more well behaved since they are allocated out of the page cache. When the page cache is exhausted, the kernel resorts to shrinkers to claim more memory, but the structures backing the shmem buffers use pinned memory and may exhaust available kmalloc memory, unless, as you say, their number is somehow limited. I'm not sure whether the shmem subsystem actually does this already...

I don't know how / if the Intel driver implements this. The ttm-aware drivers does some simple accounting of system memory used for graphics purposes, and limits it to a preset percentage of available system memory, and that percentage is adjustable using a sysfs entry. This requires, however, that the drivers register all long-lived data structures created as a result of a user-space call with the accounting system.

/Thomas

Quoted 31 lines

BR,
-R

Quoted 22 lines

/Thomas

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +5 -0
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MAP_OFFSET,
+                       samsung_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
+                               DRM_AUTH),
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MMAP,
+                       samsung_drm_gem_mmap_ioctl, DRM_UNLOCKED |

DRM_AUTH),
+};

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

#4 lore raw
Quoted 124 lines · Thomas Hellstrom
Quoted 118 lines · Rob Clark
Quoted 117 lines · Thomas Hellstrom
Quoted 98 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:

v1:<    https://lwn.net/Articles/454380/>
v2:<    http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<    http://www.gossamer-threads.com/lists/linux/kernel/1423684>

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework can
regiter
only one irq handler this patch supports mutiple irq for
Samsung SoC.

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler
instead of
drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

samsung_drm.h would contain only public information for userspace ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---

(quoted diff) +2 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE,
Quoted 3 lines

samsung_drm_gem_create_ioctl,
+ DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other device drivers to see an OOM, or only DRM?

The old DRI model basically allowed any authorized DRI client to exhaust video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

Quoted 4 lines
Quoted 2 lines

I don't think an authorized DRI client should be able to easily exhaust resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Quoted 7 lines

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 3 lines

In the samsung driver case, he is only allocating scanout memory from CMA, so the limit will be the CMA region size.. beyond that you can't get physically contiguous memory. So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should be a concern, but what compromized application *might* do that is a concern.

Hmm. I might have missed your point here. If the buffer allocation ioctl only allows allocating CMA memory, then I agree the driver fits the old DRI security model, as long as no other devices on the platform will ever use CMA.

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

This is to avoid the possibility that future drivers that need CMA will be vulnerable to DOS-attacks from ill-behaved DRI clients.

/Thomas

author
#5 lore raw

Hi Thomas.

Quoted 8 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:[email protected]]
Sent: Monday, September 12, 2011 3:32 PM
To: Rob Clark
Cc: Inki Dae; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 85 lines
Quoted 84 lines · Thomas Hellstrom
Quoted 83 lines · Rob Clark
Quoted 81 lines · Thomas Hellstrom
Quoted 80 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments
enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has
its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:

v1:<    https://lwn.net/Articles/454380/>
v2:<    http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<    http://www.gossamer-threads.com/lists/linux/kernel/1423684>

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework can
regiter
only one irq handler this patch supports mutiple irq for
Samsung SoC.

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler
instead of
drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

samsung_drm.h would contain only public information for

userspace

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 21 lines

ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---

(quoted diff) +2 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE,
Quoted 3 lines

samsung_drm_gem_create_ioctl,
+ DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that
tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other
device drivers to see an OOM, or only DRM?

Quoted 23 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The old DRI model basically allowed any authorized DRI client to exhaust
video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily

exhaust

Quoted 15 lines
Quoted 4 lines
Quoted 2 lines

resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 3 lines

In the samsung driver case, he is only allocating scanout memory from CMA, so the limit will be the CMA region size.. beyond that you can't get physically contiguous memory. So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should be a concern, but what compromized application *might* do that is a

concern.

Quoted 10 lines

Hmm. I might have missed your point here. If the buffer allocation ioctl only allows allocating CMA memory, then I agree the driver fits the old DRI security model, as long as no other devices on the platform will ever use CMA.

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

CMA could reserve memory region for a specific driver so DRM Client could request memory allocation from only the region.

Quoted 3 lines

This is to avoid the possibility that future drivers that need CMA will be vulnerable to DOS-attacks from ill-behaved DRI clients.

Thomas, if any application has root authority for ill-purpose then isn't it possible to be vulnerable to DOS-attacks? I think DRM_AUTH means root authority. I know DRM Framework gives any root application DRM_AUTH authority for compatibility.

Quoted 2 lines

/Thomas

#6 lore raw
Quoted 170 lines · Inki Dae

Hi Thomas.

Quoted 8 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:[email protected]]
Sent: Monday, September 12, 2011 3:32 PM
To: Rob Clark
Cc: Inki Dae; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 85 lines
Quoted 84 lines · Thomas Hellstrom
Quoted 83 lines · Rob Clark
Quoted 81 lines · Thomas Hellstrom
Quoted 80 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments
enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has
its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:
v1:<    https://lwn.net/Articles/454380/>
v2:<    http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<    http://www.gossamer-threads.com/lists/linux/kernel/1423684>

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

     this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

     FIMD and HDMI have their own irq handler but DRM Framework can regiter
     only one irq handler this patch supports mutiple irq for Samsung SoC.

DRM: Consider modularization.

     each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

     crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
     created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

     is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
     this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead of
     drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

     samsung_drm.h would contain only public information for

userspace

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 17 lines

     ioctl interface.

DRM: code refactoring to gem modules.
     buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

     samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

Quoted 7 lines

---

+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+                       DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that
tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other
device drivers to see an OOM, or only DRM?

Quoted 23 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The old DRI model basically allowed any authorized DRI client to exhaust
video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily

exhaust

Quoted 15 lines
Quoted 4 lines
Quoted 2 lines

resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 3 lines

In the samsung driver case, he is only allocating scanout memory from CMA, so the limit will be the CMA region size.. beyond that you can't get physically contiguous memory.  So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should be a concern, but what compromized application *might* do that is a

concern.

Quoted 10 lines

Hmm. I might have missed your point here. If the buffer allocation ioctl only allows allocating CMA memory, then I agree the driver fits the old DRI security model, as long as no other devices on the platform will ever use CMA.

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

CMA could reserve memory region for a specific driver so DRM Client could request memory allocation from only the region.

Quoted 8 lines
Quoted 3 lines

This is to avoid the possibility that future drivers that need CMA will be vulnerable to DOS-attacks from ill-behaved DRI clients.

Thomas, if any application has root authority for ill-purpose then isn't it possible to be vulnerable to DOS-attacks? I think DRM_AUTH means root authority. I know DRM Framework gives any root application DRM_AUTH authority for compatibility.

DRM_AUTH just means that the client has authenticated w/ X11 (meaning that it has permission to connect to x server)..

But I think that since memory allocation is limited to the size of the CMA region, that this puts a reasonable cap of the memory that can be allocated by the client. If this is a problem, it certainly isn't the worst problem. You could still limit via file permissions the users that can open the DRM device file, so it is really no worse than other devices like v4l2..

BR,
-R

Quoted 5 lines
Quoted 2 lines

/Thomas

author
#7 lore raw
Quoted 196 lines

-----Original Message-----
From: Rob Clark [mailto:[email protected]]
Sent: Wednesday, September 14, 2011 11:26 AM
To: Inki Dae
Cc: Thomas Hellstrom; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 16 lines · Inki Dae

Hi Thomas.

Quoted 14 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:[email protected]]
Sent: Monday, September 12, 2011 3:32 PM
To: Rob Clark
Cc: Inki Dae; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 5 lines · Thomas Hellstrom
Quoted 4 lines · Rob Clark
Quoted 2 lines · Thomas Hellstrom
Quoted 1 line · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now

enables

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments
enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has
its own lowlevel codes.

We used GEM framework for buffer management and DMA

APIs(dma_alloc_*)

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:
v1:<    https://lwn.net/Articles/454380/>
v2:<    http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<    http://www.gossamer-

threads.com/lists/linux/kernel/1423684>

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

     this feature maps user address space to physical memory

region

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

     once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP

ioctl.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

     FIMD and HDMI have their own irq handler but DRM Framework

can

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines

regiter
     only one irq handler this patch supports mutiple irq for Samsung SoC.

DRM: Consider modularization.

     each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

     crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
     created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

     is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
     this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead of
     drm framework's one.

Quoted 61 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

     samsung_drm.h would contain only public information for

userspace

Quoted 54 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 17 lines

     ioctl interface.

DRM: code refactoring to gem modules.
     buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

     samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

Quoted 7 lines

---

+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+                       DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that
tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other
device drivers to see an OOM, or only DRM?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The old DRI model basically allowed any authorized DRI client to exhaust
video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily

exhaust

Quoted 10 lines
Quoted 4 lines
Quoted 2 lines

resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 1 line

In the samsung driver case, he is only allocating scanout memory

from

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

CMA, so the limit will be the CMA region size.. beyond that you

can't

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

get physically contiguous memory.  So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should

be

Quoted 4 lines
Quoted 1 line
Quoted 1 line

a concern, but what compromized application *might* do that is a

concern.

Quoted 2 lines

Hmm. I might have missed your point here. If the buffer allocation

ioctl

Quoted 10 lines
Quoted 8 lines

only allows allocating CMA memory, then I agree the driver fits the old DRI security model, as long as no other devices on the platform will ever use CMA.

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

CMA could reserve memory region for a specific driver so DRM Client

could

Quoted 6 lines

request memory allocation from only the region.

Quoted 3 lines

This is to avoid the possibility that future drivers that need CMA will be vulnerable to DOS-attacks from ill-behaved DRI clients.

Quoted 9 lines
Quoted 1 line

Thomas, if any application has root authority for ill-purpose then isn't

it

Quoted 3 lines

possible to be vulnerable to DOS-attacks? I think DRM_AUTH means root authority. I know DRM Framework gives any root application DRM_AUTH authority for compatibility.

DRM_AUTH just means that the client has authenticated w/ X11 (meaning that it has permission to connect to x server)..

Yes, I understood so. but see drm_open_helper() of drm_fops.c file please. in this function, you can see a line below.
/* for compatibility root is always authenticated */ priv->authenticated = capable(CAP_SYS_ADMIN)

I think the code above says that any application with root permission is authenticated.

Quoted 16 lines

But I think that since memory allocation is limited to the size of the CMA region, that this puts a reasonable cap of the memory that can be allocated by the client. If this is a problem, it certainly isn't the worst problem. You could still limit via file permissions the users that can open the DRM device file, so it is really no worse than other devices like v4l2..

BR,
-R

Quoted 5 lines
Quoted 2 lines

/Thomas

#8 lore raw
Quoted 243 lines · Inki Dae
Quoted 233 lines

-----Original Message-----
From: Rob Clark [mailto:robdclark at gmail.com]
Sent: Wednesday, September 14, 2011 11:26 AM
To: Inki Dae
Cc: Thomas Hellstrom; kyungmin.park at samsung.com; sw0312.kim at samsung.com; linux-arm-kernel at lists.infradead.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 22 lines · Inki Dae

Hi Thomas.

Quoted 19 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:thomas at shipmail.org]
Sent: Monday, September 12, 2011 3:32 PM
To: Rob Clark
Cc: Inki Dae; kyungmin.park at samsung.com; sw0312.kim at samsung.com; linux- arm-kernel at lists.infradead.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 9 lines · Thomas Hellstrom
Quoted 7 lines · Rob Clark
Quoted 4 lines · Thomas Hellstrom
Quoted 2 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now

enables

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments
enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has
its own lowlevel codes.

We used GEM framework for buffer management and DMA

APIs(dma_alloc_*)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:

v1:<      https://lwn.net/Articles/454380/>
v2:<      http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<      http://www.gossamer-

threads.com/lists/linux/kernel/1423684>

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory

region

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP

ioctl.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework

can

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines

regiter
only one irq handler this patch supports mutiple irq for
Samsung SoC.

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler
instead of
drm framework's one.

Quoted 69 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

samsung_drm.h would contain only public information for

userspace

Quoted 60 lines
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 21 lines

ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---

(quoted diff) +2 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE,
Quoted 4 lines

samsung_drm_gem_create_ioctl,
+ DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that
tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other
device drivers to see an OOM, or only DRM?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The old DRI model basically allowed any authorized DRI client to exhaust
video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily

exhaust

Quoted 13 lines
Quoted 6 lines
Quoted 3 lines

resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 2 lines

In the samsung driver case, he is only allocating scanout memory

from

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CMA, so the limit will be the CMA region size.. beyond that you

can't

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

get physically contiguous memory. So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should

be

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

a concern, but what compromized application *might* do that is a

concern.

Quoted 2 lines

Hmm. I might have missed your point here. If the buffer allocation

ioctl

Quoted 11 lines
Quoted 9 lines

only allows allocating CMA memory, then I agree the driver fits the old DRI security model, as long as no other devices on the platform will ever use CMA.

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

CMA could reserve memory region for a specific driver so DRM Client

could

Quoted 9 lines

request memory allocation from only the region.

Quoted 4 lines

This is to avoid the possibility that future drivers that need CMA will be vulnerable to DOS-attacks from ill-behaved DRI clients.

Thomas, if any application has root authority for ill-purpose then isn't

Quoted 10 lines

it

Quoted 4 lines

possible to be vulnerable to DOS-attacks? I think DRM_AUTH means root authority. I know DRM Framework gives any root application DRM_AUTH authority for compatibility.

DRM_AUTH just means that the client has authenticated w/ X11 (meaning that it has permission to connect to x server)..

Quoted 9 lines

Yes, I understood so. but see drm_open_helper() of drm_fops.c file please. in this function, you can see a line below.
/* for compatibility root is always authenticated */ priv->authenticated = capable(CAP_SYS_ADMIN)

I think the code above says that any application with root permission is authenticated.

Yes, that is true. A root client may be assumed to have AUTH permissions, but the inverse does not hold, meaning that an AUTH client may *not* be assumed to have root permissions. I think there is a ROOT_ONLY ioctl flag for that.

The problem I'm seeing compared to other drivers is the following:

Imagine for example that you have a disc driver that allocates temporary memory out of the same DMA pool as the DRM driver.

Now you have a video player that is a DRM client. It contains a security flaw and is compromized by somebody trying to play a specially crafted video stream. The video player starts to allocate gem buffers until it receives an -ENOMEM. Then it stops allocating and does nothing.

Now the system tries an important disc access (paging for example). This fails, because the video player has exhausted all DMA memory and the disc driver fails to allocate.

The system is dead.

The point is:

If there is a chance that other drivers will use the same DMA/CMA pool as the DRM driver, DRM must leave enough DMA/CMA memory for those drivers to work.

The difference compared to other drm drivers:

There are other drm drivers that work the same way, with a static allocator. For example "via" and "sis". But those drivers completely claim the resources they are using. Nobody else is expected to use VRAM / AGP.

In the Samsung case, it's not clear to me whether the DMA/CMA pool *can* be shared with other devices.
If it is, IMHO you must implement an allocation limit in DRM, if not, the driver should probably be safe.

Thanks,
Thomas

Quoted 20 lines
Quoted 19 lines

But I think that since memory allocation is limited to the size of the CMA region, that this puts a reasonable cap of the memory that can be allocated by the client. If this is a problem, it certainly isn't the worst problem. You could still limit via file permissions the users that can open the DRM device file, so it is really no worse than other devices like v4l2..

BR,
-R

Quoted 6 lines
Quoted 3 lines

/Thomas

#9 lore raw
Quoted 149 lines · Thomas Hellstrom
Quoted 120 lines
Quoted 110 lines
Quoted 40 lines
Quoted 40 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 7 lines

+static struct drm_ioctl_desc samsung_ioctls[] = {
+ ? ? ? DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+ ? ? ? ? ? ? ? ? ? ? ? DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that
tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other
device drivers to see an OOM, or only DRM?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The old DRI model basically allowed any authorized DRI client to exhaust
video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily

exhaust

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 3 lines

In the samsung driver case, he is only allocating scanout memory

from

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

CMA, so the limit will be the CMA region size.. beyond that you

can't

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

get physically contiguous memory. ?So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should

be

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

a concern, but what compromized application *might* do that is a

concern.

Quoted 3 lines

Hmm. I might have missed your point here. If the buffer allocation

ioctl

Quoted 5 lines
Quoted 5 lines

only allows allocating CMA memory, then I agree the driver fits the old DRI security model, as long as no other devices on the platform will ever use CMA.

Quoted 8 lines
Quoted 5 lines

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

CMA could reserve memory region for a specific driver so DRM Client

could

Quoted 5 lines

request memory allocation from only the region.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

This is to avoid the possibility that future drivers that need CMA will be vulnerable to DOS-attacks from ill-behaved DRI clients.

Thomas, if any application has root authority for ill-purpose then isn't

it

Quoted 1 line
Quoted 9 lines
Quoted 4 lines

possible to be vulnerable to DOS-attacks? I think DRM_AUTH means root authority. I know DRM Framework gives any root application DRM_AUTH authority for compatibility.

DRM_AUTH just means that the client has authenticated w/ X11 (meaning that it has permission to connect to x server)..

Quoted 9 lines

Yes, I understood so. but see drm_open_helper() of drm_fops.c file please. in this function, you can see a line below.
/* for compatibility root is always authenticated */ priv->authenticated = capable(CAP_SYS_ADMIN)

I think the code above says that any application with root permission is authenticated.

Yes, that is true. A root client may be assumed to have AUTH permissions, but the inverse does not hold, meaning that an AUTH client may *not* be assumed to have root permissions. I think there is a ROOT_ONLY ioctl flag for that.

The problem I'm seeing compared to other drivers is the following:

Imagine for example that you have a disc driver that allocates temporary memory out of the same DMA pool as the DRM driver.

Now you have a video player that is a DRM client. It contains a security flaw and is compromized by somebody trying to play a specially crafted video stream. The video player starts to allocate gem buffers until it receives an -ENOMEM. Then it stops allocating and does nothing.

Now the system tries an important disc access (paging for example). This fails, because the video player has exhausted all DMA memory and the disc driver fails to allocate.

Quoted 7 lines

The system is dead.

The point is:

If there is a chance that other drivers will use the same DMA/CMA pool as the DRM driver, DRM must leave enough DMA/CMA memory for those drivers to work.

ah, ok, I get your point

Quoted 10 lines

The difference compared to other drm drivers:

There are other drm drivers that work the same way, with a static allocator. For example "via" and "sis". But those drivers completely claim the resources they are using. Nobody else is expected to use VRAM / AGP.

In the Samsung case, it's not clear to me whether the DMA/CMA pool *can* be shared with other devices.
If it is, IMHO you must implement an allocation limit in DRM, if not, the driver should probably be safe.

It is possible to create a device private CMA pool.. although OTOH it might be desirable to let some other drivers (like v4l2) use buffers from the same pool..

I'm not entirely sure what will happen w/ dma_alloc_coherent, etc, if the global CMA pool is exhausted.

Marek? I guess you know what would happen?

BR,
-R

Quoted 2 lines

Thanks,
Thomas

#10 lore raw
Quoted 167 lines · Rob Clark
Quoted 149 lines · Thomas Hellstrom
Quoted 120 lines
Quoted 110 lines
Quoted 40 lines
Quoted 40 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 7 lines

+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+                       DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that
tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other
device drivers to see an OOM, or only DRM?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The old DRI model basically allowed any authorized DRI client to exhaust
video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily

exhaust

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

resources (DMA memory) used by other device drivers causing them to fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 3 lines

In the samsung driver case, he is only allocating scanout memory

from

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

CMA, so the limit will be the CMA region size.. beyond that you

can't

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

get physically contiguous memory.  So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should

be

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

a concern, but what compromized application *might* do that is a

concern.

Quoted 3 lines

Hmm. I might have missed your point here. If the buffer allocation

ioctl

Quoted 5 lines
Quoted 5 lines

only allows allocating CMA memory, then I agree the driver fits the old DRI security model, as long as no other devices on the platform will ever use CMA.

Quoted 8 lines
Quoted 5 lines

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

CMA could reserve memory region for a specific driver so DRM Client

could

Quoted 5 lines

request memory allocation from only the region.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

This is to avoid the possibility that future drivers that need CMA will be vulnerable to DOS-attacks from ill-behaved DRI clients.

Thomas, if any application has root authority for ill-purpose then isn't

it

Quoted 1 line
Quoted 9 lines
Quoted 4 lines

possible to be vulnerable to DOS-attacks? I think DRM_AUTH means root authority. I know DRM Framework gives any root application DRM_AUTH authority for compatibility.

DRM_AUTH just means that the client has authenticated w/ X11 (meaning that it has permission to connect to x server)..

Quoted 9 lines

Yes, I understood so. but see drm_open_helper() of drm_fops.c file please. in this function, you can see a line below.
/* for compatibility root is always authenticated */ priv->authenticated = capable(CAP_SYS_ADMIN)

I think the code above says that any application with root permission is authenticated.

Yes, that is true. A root client may be assumed to have AUTH permissions, but the inverse does not hold, meaning that an AUTH client may *not* be assumed to have root permissions. I think there is a ROOT_ONLY ioctl flag for that.

The problem I'm seeing compared to other drivers is the following:

Imagine for example that you have a disc driver that allocates temporary memory out of the same DMA pool as the DRM driver.

Now you have a video player that is a DRM client. It contains a security flaw and is compromized by somebody trying to play a specially crafted video stream. The video player starts to allocate gem buffers until it receives an -ENOMEM. Then it stops allocating and does nothing.

Now the system tries an important disc access (paging for example). This fails, because the video player has exhausted all DMA memory and the disc driver fails to allocate.

Quoted 7 lines

The system is dead.

The point is:

If there is a chance that other drivers will use the same DMA/CMA pool as the DRM driver, DRM must leave enough DMA/CMA memory for those drivers to work.

ah, ok, I get your point

Quoted 6 lines

The difference compared to other drm drivers:

There are other drm drivers that work the same way, with a static allocator. For example "via" and "sis". But those drivers completely claim the resources they are using. Nobody else is expected to use VRAM / AGP.

Quoted 8 lines
Quoted 4 lines

In the Samsung case, it's not clear to me whether the DMA/CMA pool *can* be shared with other devices.
If it is, IMHO you must implement an allocation limit in DRM, if not, the driver should probably be safe.

It is possible to create a device private CMA pool..  although OTOH it might be desirable to let some other drivers (like v4l2) use buffers from the same pool..

That's the final goal. memory sharing among multimedia devices (v4l2), display(fimd, hdmi), and 3D (mali).
currently mali drivers is tightly coupled with UMP and it's hard to use the CMA. it's need to solve this issue also.

In case of multimedia drivers, it has fixed memory area as scenario and display also has similar restriction. I don't expect DRI request the more memory than CMA pool has.

Quoted 3 lines

I'm not entirely sure what will happen w/ dma_alloc_coherent, etc, if the global CMA pool is exhausted.

The primary goal of CMA is guarantee the memory for multimedia. So if other device use the multimedia CMA pool, it should release the used memory. and it's hard to release the memory. it should has display CMA pool and don't share the other multimedia devices CMA pool.

CMA can share the same CMA pool and specify the device usage which CMA pool used.

Quoted 2 lines

Marek?  I guess you know what would happen?

He will comeback when 21 Sep.

Thank you,
Kyungmin Park

#11 lore raw
In reply to Rob Clark

Hello,

Quoted 1 line · Rob Clark

On Wed, Sep 14, 2011 at 2:57 AM, Thomas Hellstrom <[email protected]> wrote:

(snipped)

Quoted 35 lines
Quoted 19 lines

Yes, that is true. A root client may be assumed to have AUTH permissions, but the inverse does not hold, meaning that an AUTH client may *not* be assumed to have root permissions. I think there is a ROOT_ONLY ioctl flag for that.

The problem I'm seeing compared to other drivers is the following:

Imagine for example that you have a disc driver that allocates temporary memory out of the same DMA pool as the DRM driver.

Now you have a video player that is a DRM client. It contains a security flaw and is compromized by somebody trying to play a specially crafted video stream. The video player starts to allocate gem buffers until it receives an -ENOMEM. Then it stops allocating and does nothing.

Now the system tries an important disc access (paging for example). This fails, because the video player has exhausted all DMA memory and the disc driver fails to allocate.

Quoted 7 lines

The system is dead.

The point is:

If there is a chance that other drivers will use the same DMA/CMA pool as the DRM driver, DRM must leave enough DMA/CMA memory for those drivers to work.

ah, ok, I get your point

Quoted 6 lines

The difference compared to other drm drivers:

There are other drm drivers that work the same way, with a static allocator. For example "via" and "sis". But those drivers completely claim the resources they are using. Nobody else is expected to use VRAM / AGP.

Quoted 8 lines
Quoted 4 lines

In the Samsung case, it's not clear to me whether the DMA/CMA pool *can* be shared with other devices.
If it is, IMHO you must implement an allocation limit in DRM, if not, the driver should probably be safe.

It is possible to create a device private CMA pool.. although OTOH it might be desirable to let some other drivers (like v4l2) use buffers from the same pool..

Creating a device private CMA pool doesn't prevent other drivers to access memory from it if there is a way to pass a buffer to them (i.e. using dma_buf method). However the driver must be able to address that memory. CMA private pools were designed mainly to resolve the problem that some weird hardware can access certain types of buffers only at particular memory address ranges which matches particular memory bank.

Quoted 4 lines

I'm not entirely sure what will happen w/ dma_alloc_coherent, etc, if the global CMA pool is exhausted.

Marek? I guess you know what would happen?

The allocation will simply fail and dma_alloc_coherent will return NULL.

Best regards

Signature · 2 lines
Marek Szyprowski
Samsung Poland R&D Center
#12 lore raw
Quoted 7 lines · Marek Szyprowski
Quoted 4 lines

I'm not entirely sure what will happen w/ dma_alloc_coherent, etc, if the global CMA pool is exhausted.

Marek? ?I guess you know what would happen?

The allocation will simply fail and dma_alloc_coherent will return NULL.

Ok, so we should probably setup device private pools so that userspace cannot allocate so much buffer memory that dma_alloc_coherent fails for other devices..

This is what I've done so far for omapdrm driver, although it is part of the other patch that adds the platform-device..

Thx

BR,
-R

author
#13 lore raw
In reply to Thomas Hellstrom

Hi, Thomas.

Quoted 8 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:thomas at shipmail.org]
Sent: Wednesday, September 14, 2011 4:57 PM
To: Inki Dae
Cc: 'Rob Clark'; kyungmin.park at samsung.com; sw0312.kim at samsung.com; linux- arm-kernel at lists.infradead.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 8 lines
Quoted 7 lines · Inki Dae
Quoted 7 lines

-----Original Message-----
From: Rob Clark [mailto:robdclark at gmail.com]
Sent: Wednesday, September 14, 2011 11:26 AM
To: Inki Dae
Cc: Thomas Hellstrom; kyungmin.park at samsung.com;

sw0312.kim at samsung.com;

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines

linux-arm-kernel at lists.infradead.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

On Tue, Sep 13, 2011 at 9:03 PM, Inki Dae<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Hi Thomas.

Quoted 5 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:thomas at shipmail.org]
Sent: Monday, September 12, 2011 3:32 PM
To: Rob Clark
Cc: Inki Dae; kyungmin.park at samsung.com; sw0312.kim at samsung.com;

Quoted 26 lines

linux-

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

arm-kernel at lists.infradead.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC

EXYNOS4210.

Quoted 22 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines · Thomas Hellstrom
Quoted 3 lines · Rob Clark
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines · Thomas Hellstrom
Quoted 2 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now

enables

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments
enough.

this patch is based on git repository below:

git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,

Quoted 24 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel

codes

Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

of s3c-fb.c are included internally and so FIMD module of this driver has
its own lowlevel codes.

We used GEM framework for buffer management and DMA

APIs(dma_alloc_*)

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous

memory(non-iommu).

Quoted 210 lines
Quoted 32 lines
Quoted 32 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Links to previous versions of the patchset:

v1:<      https://lwn.net/Articles/454380/>
v2:<      http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<      http://www.gossamer-

threads.com/lists/linux/kernel/1423684>

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory

region

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP

ioctl.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework

can

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

regiter
only one irq handler this patch supports mutiple irq for
Samsung SoC.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a

crtc

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects

and

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

would use its own request_irq() to register a irq handler
instead of
drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to

driver

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

folder.

samsung_drm.h would contain only public information for

userspace

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 21 lines

ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---

(quoted diff) +2 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE,
Quoted 4 lines

samsung_drm_gem_create_ioctl,
+ DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that
tries to repeatedly allocate huge GEM buffers...

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

What will happen when all DMA memory is exhausted? Will this cause other
device drivers to see an OOM, or only DRM?

The old DRI model basically allowed any authorized DRI client to exhaust
video ram or AGP memory, but never system memory. Newer DRI

drivers

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily

exhaust

Quoted 1 line
Quoted 1 line
Quoted 1 line

resources (DMA memory) used by other device drivers causing them

to

Quoted 26 lines
Quoted 26 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 2 lines

In the samsung driver case, he is only allocating scanout memory

from

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CMA, so the limit will be the CMA region size.. beyond that you

can't

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

get physically contiguous memory. So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should

be

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

a concern, but what compromized application *might* do that is a

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

concern.

Quoted 2 lines

Hmm. I might have missed your point here. If the buffer allocation

ioctl

Quoted 1 line
Quoted 1 line

only allows allocating CMA memory, then I agree the driver fits the

old

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

DRI security model, as long as no other devices on the platform will ever use CMA.

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

CMA could reserve memory region for a specific driver so DRM Client

could

Quoted 4 lines

request memory allocation from only the region.

Quoted 1 line

This is to avoid the possibility that future drivers that need CMA

will

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

be vulnerable to DOS-attacks from ill-behaved DRI clients.

Thomas, if any application has root authority for ill-purpose then

isn't

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

it

Quoted 4 lines

possible to be vulnerable to DOS-attacks? I think DRM_AUTH means root authority. I know DRM Framework gives any root application DRM_AUTH authority for compatibility.

Quoted 5 lines
Quoted 4 lines

DRM_AUTH just means that the client has authenticated w/ X11 (meaning that it has permission to connect to x server)..

Yes, I understood so. but see drm_open_helper() of drm_fops.c file

please.

Quoted 8 lines

in this function, you can see a line below. /* for compatibility root is always authenticated */ priv->authenticated = capable(CAP_SYS_ADMIN)

I think the code above says that any application with root permission is authenticated.

Yes, that is true. A root client may be assumed to have AUTH permissions, but the inverse does not hold, meaning that an AUTH client may *not* be assumed to have root permissions. I think there is a ROOT_ONLY ioctl flag for that.

The problem I'm seeing compared to other drivers is the following:

Imagine for example that you have a disc driver that allocates temporary memory out of the same DMA pool as the DRM driver.

Now you have a video player that is a DRM client. It contains a security flaw and is compromized by somebody trying to play a specially crafted video stream. The video player starts to allocate gem buffers until it receives an -ENOMEM. Then it stops allocating and does nothing.

Quoted 6 lines

Now the system tries an important disc access (paging for example). This fails, because the video player has exhausted all DMA memory and the disc driver fails to allocate.

The system is dead.

Ok, I understood. but in case of using CMA, DRM driver would have private memory pool which is reserved only for itself. so although the video player requested gem buffer allocation until it receives an -ENOMEM and then the system is try to access the disc, it would work fine. because the region requested by system and the region requested by DRM driver could entirely be separated. DRM driver wouldn't have implications for the system region.

Quoted 6 lines

The point is:

If there is a chance that other drivers will use the same DMA/CMA pool as the DRM driver, DRM must leave enough DMA/CMA memory for those drivers to work.

Quoted 7 lines

The difference compared to other drm drivers:

There are other drm drivers that work the same way, with a static allocator. For example "via" and "sis". But those drivers completely claim the resources they are using. Nobody else is expected to use VRAM / AGP.

I think if we use private cma region for DRM driver then it is similar to via and sis way.

Quoted 5 lines

In the Samsung case, it's not clear to me whether the DMA/CMA pool *can* be shared with other devices.
If it is, IMHO you must implement an allocation limit in DRM, if not, the driver should probably be safe.

As your saying, we would implement an allocation limit in DRM; DRM driver have private region that any other drivers can't access to this one. in fact, such limitation should be set at machine code. if this way has any problems for security also, we CAN CHANGE DRM permission anytime. :) thank you for your detailed account and that was very helpful to me.

Quoted 40 lines

Thanks,
Thomas

Quoted 20 lines
Quoted 19 lines

But I think that since memory allocation is limited to the size of the CMA region, that this puts a reasonable cap of the memory that can be allocated by the client. If this is a problem, it certainly isn't the worst problem. You could still limit via file permissions the users that can open the DRM device file, so it is really no worse than other devices like v4l2..

BR,
-R

Quoted 6 lines
Quoted 3 lines

/Thomas

#14 lore raw
Quoted 392 lines · Inki Dae

Hi, Thomas.

Quoted 8 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:thomas at shipmail.org]
Sent: Wednesday, September 14, 2011 4:57 PM
To: Inki Dae
Cc: 'Rob Clark'; kyungmin.park at samsung.com; sw0312.kim at samsung.com; linux- arm-kernel at lists.infradead.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 10 lines
Quoted 8 lines · Inki Dae
Quoted 8 lines

-----Original Message-----
From: Rob Clark [mailto:robdclark at gmail.com]
Sent: Wednesday, September 14, 2011 11:26 AM
To: Inki Dae
Cc: Thomas Hellstrom; kyungmin.park at samsung.com;

sw0312.kim at samsung.com;

Quoted 16 lines
Quoted 10 lines
Quoted 10 lines

linux-arm-kernel at lists.infradead.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 4 lines · Inki Dae

Hi Thomas.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:thomas at shipmail.org]
Sent: Monday, September 12, 2011 3:32 PM
To: Rob Clark
Cc: Inki Dae; kyungmin.park at samsung.com; sw0312.kim at samsung.com;

Quoted 35 lines

linux-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

arm-kernel at lists.infradead.org; dri-devel at lists.freedesktop.org
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC

EXYNOS4210.

Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
Quoted 10 lines · Thomas Hellstrom
Quoted 9 lines · Rob Clark
Quoted 6 lines

On Sat, Sep 10, 2011 at 9:04 AM, Thomas
Hellstrom<[email protected]> wrote:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Inki Dae
Quoted 5 lines

This patch is a DRM Driver for Samsung SoC Exynos4210 and now

enables

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments
enough.

this patch is based on git repository below:

git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,

Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel

codes

Quoted 17 lines
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

of s3c-fb.c are included internally and so FIMD module of this driver has
its own lowlevel codes.

We used GEM framework for buffer management and DMA

APIs(dma_alloc_*)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous

memory(non-iommu).

Quoted 262 lines
Quoted 39 lines
Quoted 39 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Links to previous versions of the patchset:

v1:<       https://lwn.net/Articles/454380/>
v2:<       http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<       http://www.gossamer-

threads.com/lists/linux/kernel/1423684>

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory

region

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP

ioctl.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework

can

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

regiter
only one irq handler this patch supports mutiple irq for
Samsung SoC.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a

crtc

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects

and

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

would use its own request_irq() to register a irq handler
instead of
drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to

driver

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

folder.

samsung_drm.h would contain only public information for

userspace

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 21 lines

ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---

(quoted diff) +2 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE,
Quoted 5 lines

samsung_drm_gem_create_ioctl,
+ DRM_UNLOCKED | DRM_AUTH),

Hi!

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that
tries to repeatedly allocate huge GEM buffers...

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

What will happen when all DMA memory is exhausted? Will this cause other
device drivers to see an OOM, or only DRM?

The old DRI model basically allowed any authorized DRI client to exhaust
video ram or AGP memory, but never system memory. Newer DRI

drivers

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

typically only allow DRI masters to do that.
as

I don't think an authorized DRI client should be able to easily

exhaust

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

resources (DMA memory) used by other device drivers causing them

to

Quoted 40 lines
Quoted 40 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 3 lines

fail.

I'm not entirely sure what else can be done, other than have a threshold on max MB allocatable of buffer memory..

Yes, I think that's what needs to be done, and that threshold should be low enough to keep other device drivers running in the worst allocation case.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In the samsung driver case, he is only allocating scanout memory

from

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

CMA, so the limit will be the CMA region size.. beyond that you

can't

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

get physically contiguous memory. So I think this driver is safe.

It's not really what well-behaved user-space drivers do that should

be

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

a concern, but what compromized application *might* do that is a

concern.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Hmm. I might have missed your point here. If the buffer allocation

ioctl

Quoted 2 lines
Quoted 2 lines

only allows allocating CMA memory, then I agree the driver fits the

old

Quoted 15 lines
Quoted 15 lines
Quoted 12 lines
Quoted 9 lines

DRI security model, as long as no other devices on the platform will ever use CMA.

But in that case, there really should be a way for the driver to say "Hey, all CMA memory on this system is mine", in the same way traditional video drivers can claim the VRAM PCI resource.

CMA could reserve memory region for a specific driver so DRM Client

could

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

request memory allocation from only the region.

Quoted 2 lines

This is to avoid the possibility that future drivers that need CMA

will

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

be vulnerable to DOS-attacks from ill-behaved DRI clients.

Thomas, if any application has root authority for ill-purpose then

isn't

Quoted 9 lines
Quoted 9 lines
Quoted 1 line

it

Quoted 5 lines

possible to be vulnerable to DOS-attacks? I think DRM_AUTH means root authority. I know DRM Framework gives any root application DRM_AUTH authority for compatibility.

Quoted 7 lines
Quoted 5 lines

DRM_AUTH just means that the client has authenticated w/ X11 (meaning that it has permission to connect to x server)..

Yes, I understood so. but see drm_open_helper() of drm_fops.c file

please.

Quoted 9 lines

in this function, you can see a line below. /* for compatibility root is always authenticated */ priv->authenticated = capable(CAP_SYS_ADMIN)

I think the code above says that any application with root permission is authenticated.

Yes, that is true. A root client may be assumed to have AUTH permissions, but the inverse does not hold, meaning that an AUTH client may *not* be assumed to have root permissions. I think there is a ROOT_ONLY ioctl flag for that.

The problem I'm seeing compared to other drivers is the following:

Imagine for example that you have a disc driver that allocates temporary memory out of the same DMA pool as the DRM driver.

Now you have a video player that is a DRM client. It contains a security flaw and is compromized by somebody trying to play a specially crafted video stream. The video player starts to allocate gem buffers until it receives an -ENOMEM. Then it stops allocating and does nothing.

Quoted 7 lines

Now the system tries an important disc access (paging for example). This fails, because the video player has exhausted all DMA memory and the disc driver fails to allocate.

The system is dead.

Ok, I understood. but in case of using CMA, DRM driver would have private memory pool which is reserved only for itself. so although the video player requested gem buffer allocation until it receives an -ENOMEM and then the system is try to access the disc, it would work fine. because the region requested by system and the region requested by DRM driver could entirely be separated. DRM driver wouldn't have implications for the system region.

Quoted 8 lines

The point is:

If there is a chance that other drivers will use the same DMA/CMA pool as the DRM driver, DRM must leave enough DMA/CMA memory for those drivers to work.

The difference compared to other drm drivers:

Quoted 10 lines
Quoted 6 lines

There are other drm drivers that work the same way, with a static allocator. For example "via" and "sis". But those drivers completely claim the resources they are using. Nobody else is expected to use VRAM / AGP.

I think if we use private cma region for DRM driver then it is similar to via and sis way.

In that case, I agree the driver should be OK.

...

Thanks,
Thomas

author
#15 lore raw
In reply to Thomas Hellstrom

Hi Thomas.
Sorry for being late.

Quoted 51 lines

-----Original Message-----
From: Thomas Hellstrom [mailto:[email protected]]
Sent: Saturday, September 10, 2011 11:04 PM
To: Inki Dae
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux-arm- [email protected]
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 4 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got

comments

Quoted 7 lines

enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

Quoted 7 lines

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver

has

Quoted 21 lines

its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:

v1:<  https://lwn.net/Articles/454380/>
v2:<  http://www.spinics.net/lists/kernel/msg1224275.html>
v3:<  http://www.gossamer-threads.com/lists/linux/kernel/1423684>

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

Quoted 8 lines
Quoted 6 lines

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework can

regiter

Quoted 1 line

only one irq handler this patch supports mutiple irq for Samsung

SoC.

Quoted 13 lines
Quoted 13 lines

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Quoted 8 lines
Quoted 8 lines

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead

of

Quoted 34 lines
Quoted 5 lines

drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver

folder.

Quoted 22 lines

samsung_drm.h would contain only public information for userspace ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---

drivers/gpu/drm/samsung/samsung_drm_drv.c line 130

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +3 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+			DRM_UNLOCKED | DRM_AUTH),

Hi!

Quoted 8 lines

With reference my previous security comment.

Let's say you have a compromised video player running as a DRM client, that tries to repeatedly allocate huge GEM buffers...

What will happen when all DMA memory is exhausted? Will this cause other device drivers to see an OOM, or only DRM?

Out driver allocates physically continuous memory from the region reserved by CMA or DMA Region in case of not using CMA. if all memory is exhausted at allocation moment, it just returns "Allocation fail" and then the application would be terminated.

Quoted 5 lines

The old DRI model basically allowed any authorized DRI client to exhaust video ram or AGP memory, but never system memory. Newer DRI drivers typically only allow DRI masters to do that.
as

I thought it's enough for an authorized DRI client to request memory allocation. because an authorized DRI client has root authority. I know, in case of v4l2 based device drivers, the applications can request buffer allocation through v4l2 interface, REQBUFS. and also if memory allocation is repeated, we can see any error in the near future. and I wonder why only DRM master could do that. it might be my missing points so I am happy to you give me your words?

Quoted 11 lines

I don't think an authorized DRI client should be able to easily exhaust resources (DMA memory) used by other device drivers causing them to fail.

/Thomas

drivers/gpu/drm/samsung/samsung_drm_drv.c

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +5 -0
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MAP_OFFSET,
+			samsung_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
+				DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MMAP,
+			samsung_drm_gem_mmap_ioctl, DRM_UNLOCKED |

DRM_AUTH),

Quoted 4 lines
Quoted 3 lines

+};

#16 lore raw
In reply to Inki Dae
Quoted 164 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got comments enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver has its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:
v1: < https://lwn.net/Articles/454380/ >
v2: < http://www.spinics.net/lists/kernel/msg1224275.html >
v3: < http://www.gossamer-threads.com/lists/linux/kernel/1423684 >

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework can regiter only one irq handler this patch supports mutiple irq for Samsung SoC.

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead of drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver folder.

samsung_drm.h would contain only public information for userspace ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---
 drivers/gpu/drm/Kconfig                         |    2 +
 drivers/gpu/drm/Makefile                        |    1 +
 drivers/gpu/drm/samsung/Kconfig                 |   18 +
 drivers/gpu/drm/samsung/Makefile                |   11 +
 drivers/gpu/drm/samsung/samsung_drm_buf.c       |  109 ++++
 drivers/gpu/drm/samsung/samsung_drm_buf.h       |   50 ++
 drivers/gpu/drm/samsung/samsung_drm_connector.c |  257 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_connector.h |   34 ++
 drivers/gpu/drm/samsung/samsung_drm_core.c      |  213 ++++++++
 drivers/gpu/drm/samsung/samsung_drm_crtc.c      |  329 ++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_crtc.h      |   38 ++
 drivers/gpu/drm/samsung/samsung_drm_drv.c       |  215 ++++++++
 drivers/gpu/drm/samsung/samsung_drm_drv.h       |  194 +++++++
 drivers/gpu/drm/samsung/samsung_drm_encoder.c   |  261 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_encoder.h   |   45 ++
 drivers/gpu/drm/samsung/samsung_drm_fb.c        |  262 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_fb.h        |   47 ++
 drivers/gpu/drm/samsung/samsung_drm_fbdev.c     |  409 ++++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_fbdev.h     |   37 ++
 drivers/gpu/drm/samsung/samsung_drm_fimd.c      |  643 +++++++++++++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_gem.c       |  492 +++++++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_gem.h       |   98 ++++
 include/drm/samsung_drm.h                       |  103 ++++
 23 files changed, 3868 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/samsung/Kconfig
 create mode 100644 drivers/gpu/drm/samsung/Makefile
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_buf.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_buf.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_connector.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_connector.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_core.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_crtc.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_crtc.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_drv.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_drv.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_encoder.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_encoder.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fb.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fb.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fbdev.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fbdev.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fimd.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_gem.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_gem.h
 create mode 100644 include/drm/samsung_drm.h
drivers/gpu/drm/Kconfig +2 -0
index b493663..ce6d3ec 100644
@@ -158,3 +158,5 @@ config DRM_SAVAGE
 	help
 	  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
 	  chipset. If M is selected the module will be called savage.
+
+source "drivers/gpu/drm/samsung/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 89cf05a..0c6e773 100644
@@ -35,4 +35,5 @@ obj-$(CONFIG_DRM_SAVAGE)+= savage/
 obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
 obj-$(CONFIG_DRM_VIA)	+=via/
 obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
+obj-$(CONFIG_DRM_SAMSUNG) +=samsung/
 obj-y			+= i2c/
drivers/gpu/drm/samsung/Kconfig new file +0 -0
new file mode 100644
index 0000000..34cedda

drivers/gpu/drm/samsung/Kconfig line 8

Quoted 8 lines
drivers/gpu/drm/samsung/Kconfig new file +8 -0
@@ -0,0 +1,18 @@
+config DRM_SAMSUNG
+	tristate "DRM Support for Samsung SoC EXYNOS Series"
+	depends on DRM && PLAT_SAMSUNG
+	select DRM_KMS_HELPER
+	select FB_CFB_FILLRECT
+	select FB_CFB_COPYAREA
+	select FB_CFB_IMAGEBLIT
+	select VT_HW_CONSOLE_BINDING if FRAMEBUFFER_CONSOLE

You should probably have
default n

drivers/gpu/drm/samsung/Kconfig line 15

Quoted 7 lines
drivers/gpu/drm/samsung/Kconfig new file +7 -0
+	help
+	  Choose this option if you have a Samsung SoC EXYNOS chipset.
+	  If M is selected the module will be called samsungdrm.
+
+config DRM_SAMSUNG_FIMD
+	tristate "Samsung DRM FIMD"
+	depends on DRM_SAMSUNG

And here too.

drivers/gpu/drm/samsung/Makefile line 3

Quoted 12 lines
drivers/gpu/drm/samsung/Kconfig new file +3 -0
+	help
+	  Choose this option if you want to use Samsung FIMD for DRM.
+	  If M is selected, the module will be called samsung_drm_fimd
drivers/gpu/drm/samsung/Makefile new file +3 -0
new file mode 100644
index 0000000..70f89f3
@@ -0,0 +1,11 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.

4.1.0? Really? I mean did you actually test this with 4.1.0? Or have you been using the Xorg instead?

Quoted 36 lines
drivers/gpu/drm/samsung/Makefile new file +8 -0
+
+ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/samsung
+samsungdrm-y := samsung_drm_drv.o samsung_drm_encoder.o samsung_drm_connector.o \
+		samsung_drm_crtc.o samsung_drm_fbdev.o samsung_drm_fb.o \
+		samsung_drm_buf.o samsung_drm_gem.o samsung_drm_core.o
+
+obj-$(CONFIG_DRM_SAMSUNG) += samsungdrm.o
+obj-$(CONFIG_DRM_SAMSUNG_FIMD) += samsung_drm_fimd.o
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +22 -0
new file mode 100644
index 0000000..46cc673
@@ -0,0 +1,109 @@
+/* samsung_drm_buf.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Author: Inki Dae <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

drivers/gpu/drm/samsung/samsung_drm_buf.c line 32

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +10 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_buf.h"
+
+static DEFINE_MUTEX(samsung_drm_buf_lock);

Why the prefix 'samsung_'?

Quoted 63 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +62 -0
+
+static int lowlevel_buffer_allocate(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	entry->vaddr = dma_alloc_writecombine(dev->dev, entry->size,
+			(dma_addr_t *)&entry->paddr, GFP_KERNEL);
+	if (!entry->paddr) {
+		DRM_ERROR("failed to allocate buffer.\n");
+		return -ENOMEM;
+	}
+
+	DRM_DEBUG_KMS("allocated : vaddr(0x%x), paddr(0x%x), size(0x%x)\n",
+			(unsigned int)entry->vaddr, entry->paddr, entry->size);
+
+	return 0;
+}
+
+static void lowlevel_buffer_deallocate(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry)
+{
+	DRM_DEBUG_KMS("%s.\n", __FILE__);
+
+	dma_free_writecombine(dev->dev, entry->size, entry->vaddr,
+			entry->paddr);
+
+	DRM_DEBUG_KMS("deallocated : vaddr(0x%x), paddr(0x%x), size(0x%x)\n",
+			(unsigned int)entry->vaddr, entry->paddr, entry->size);
+}
+
+static void  samsung_drm_buf_del(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry)
+{
+	DRM_DEBUG_KMS("%s.\n", __FILE__);
+
+	lowlevel_buffer_deallocate(dev, entry);
+
+	kfree(entry);
+}
+
+struct samsung_drm_buf_entry *samsung_drm_buf_create(struct drm_device *dev,
+		unsigned int size)
 
+{
+	struct samsung_drm_buf_entry *entry;
+
+	DRM_DEBUG_KMS("%s.\n", __FILE__);
+	DRM_DEBUG_KMS("desired size = 0x%x\n", size);
+
+	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+	if (!entry) {
+		DRM_ERROR("failed to allocate samsung_drm_buf_entry.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	entry->size = size;
+
+	/* allocate memory region and set it to vaddr and paddr. */
+	if (lowlevel_buffer_allocate(dev, entry) < 0) {
+		kfree(entry);
+		return ERR_PTR(-ENOMEM);
+	}

drivers/gpu/drm/samsung/samsung_drm_buf.c line 104

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +10 -0
+
+	return entry;
+}
+
+void samsung_drm_buf_destroy(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry)
+{
+	DRM_DEBUG_KMS("%s.\n", __FILE__);
+
+	samsung_drm_buf_del(dev, entry);

Why not stick the contents of samsung_drm_buf_del in here? This function looks to be the only one calling it.

Quoted 171 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +5 -0
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");
+MODULE_DESCRIPTION("Samsung SoC DRM Buffer Management Module");
+MODULE_LICENSE("GPL");
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +50 -0
new file mode 100644
index 0000000..b6d7393
@@ -0,0 +1,50 @@
+/* samsung_drm_buf.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Author: Inki Dae <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_BUF_H_
+#define _SAMSUNG_DRM_BUF_H_
+
+/**
+ * samsung drm buffer entry structure.
+ *
+ * @paddr: physical address of allocated memory.
+ * @vaddr: kernel virtual address of allocated memory.
+ * @size: size of allocated memory.
+ */
+struct samsung_drm_buf_entry {
+	dma_addr_t paddr;
+	void __iomem *vaddr;
+	unsigned int size;
+};
+
+/* allocate physical memory. */
+struct samsung_drm_buf_entry *samsung_drm_buf_create(struct drm_device *dev,
+		unsigned int size);
+
+/* remove allocated physical memory. */
+void samsung_drm_buf_destroy(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +104 -0
new file mode 100644
index 0000000..cf457c0
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_encoder.h"
+
+#define MAX_EDID 256
+#define to_samsung_connector(x)	container_of(x, struct samsung_drm_connector,\
+				drm_connector)
+
+struct samsung_drm_connector {
+	struct drm_connector	drm_connector;
+
+	/* add hardware specific callbacks or data structure. */
+};
+
+/* convert samsung_video_timings to drm_display_mode */
+static inline void
+convert_to_display_mode(struct drm_display_mode *mode,
+			struct fb_videomode *timing)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode->clock = timing->pixclock / 1000;
+
+	mode->hdisplay = timing->xres;
+	mode->hsync_start = mode->hdisplay + timing->left_margin;
+	mode->hsync_end = mode->hsync_start + timing->hsync_len;
+	mode->htotal = mode->hsync_end + timing->right_margin;
+
+	mode->vdisplay = timing->yres;
+	mode->vsync_start = mode->vdisplay + timing->upper_margin;
+	mode->vsync_end = mode->vsync_start + timing->vsync_len;
+	mode->vtotal = mode->vsync_end + timing->lower_margin;
+}
+
+/* convert drm_display_mode to samsung_video_timings */
+static inline void
+convert_to_video_timing(struct fb_videomode *timing,
+			struct drm_display_mode *mode)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	timing->pixclock = mode->clock * 1000;
+
+	timing->xres = mode->hdisplay;
+	timing->left_margin = mode->hsync_start - mode->hdisplay;
+	timing->hsync_len = mode->hsync_end - mode->hsync_start;
+	timing->right_margin = mode->htotal - mode->hsync_end;
+
+	timing->yres = mode->vdisplay;
+	timing->upper_margin = mode->vsync_start - mode->vdisplay;
+	timing->vsync_len = mode->vsync_end - mode->vsync_start;
+	timing->lower_margin = mode->vtotal - mode->vsync_end;
+}
+
+static int samsung_drm_connector_get_modes(struct drm_connector *connector)
+{
+	struct samsung_drm_manager *manager =
+				samsung_drm_get_manager(connector->encoder);
+	struct samsung_drm_display *display = manager->display;
+	unsigned int count;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (display && display->get_edid) {
+		void *edid = kzalloc(MAX_EDID, GFP_KERNEL);
+		if (!edid) {
+			DRM_ERROR("failed to allocate edid\n");
+			return 0;
+		}
+
+		display->get_edid(manager->dev, connector, edid, MAX_EDID);
+
+		drm_mode_connector_update_edid_property(connector, edid);
+		count = drm_add_edid_modes(connector, edid);
+

drivers/gpu/drm/samsung/samsung_drm_connector.c line 114

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+		kfree(connector->display_info.raw_edid);
+		connector->display_info.raw_edid = edid;
+	} else {
+		struct drm_display_mode *mode = drm_mode_create(connector->dev);
+		struct fb_videomode *timing;
+
+		if (display && display->get_timing)
+			timing = display->get_timing(manager->dev);
+		else
+			return 0;

and memory leak. The 'mode' is still allocated.

Quoted 131 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +131 -0
+
+		convert_to_display_mode(mode, timing);
+
+		mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+		drm_mode_set_name(mode);
+		drm_mode_probed_add(connector, mode);
+
+		count = 1;
+	}
+
+	return count;
+}
+
+static int samsung_drm_connector_mode_valid(struct drm_connector *connector,
+					    struct drm_display_mode *mode)
+{
+	struct samsung_drm_manager *manager =
+				samsung_drm_get_manager(connector->encoder);
+	struct samsung_drm_display *display = manager->display;
+	struct fb_videomode timing;
+	int ret = MODE_BAD;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	convert_to_video_timing(&timing, mode);
+
+	if (display && display->check_timing)
+		if (!display->check_timing(manager->dev, (void *)&timing))
+			ret = MODE_OK;
+
+	return ret;
+}
+
+struct drm_encoder *samsung_drm_best_encoder(struct drm_connector *connector)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return connector->encoder;
+}
+
+static struct drm_connector_helper_funcs samsung_connector_helper_funcs = {
+	.get_modes	= samsung_drm_connector_get_modes,
+	.mode_valid	= samsung_drm_connector_mode_valid,
+	.best_encoder	= samsung_drm_best_encoder,
+};
+
+/* get detection status of display device. */
+static enum drm_connector_status
+samsung_drm_connector_detect(struct drm_connector *connector, bool force)
+{
+	struct samsung_drm_manager *manager =
+				samsung_drm_get_manager(connector->encoder);
+	struct samsung_drm_display *display = manager->display;
+	enum drm_connector_status status = connector_status_disconnected;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (display && display->is_connected) {
+		if (display->is_connected(manager->dev))
+			status = connector_status_connected;
+		else
+			status = connector_status_disconnected;
+	}
+
+	return status;
+}
+
+static void samsung_drm_connector_destroy(struct drm_connector *connector)
+{
+	struct samsung_drm_connector *samsung_connector =
+		to_samsung_connector(connector);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	drm_sysfs_connector_remove(connector);
+	drm_connector_cleanup(connector);
+	kfree(samsung_connector);
+}
+
+static struct drm_connector_funcs samsung_connector_funcs = {
+	.dpms		= drm_helper_connector_dpms,
+	.fill_modes	= drm_helper_probe_single_connector_modes,
+	.detect		= samsung_drm_connector_detect,
+	.destroy	= samsung_drm_connector_destroy,
+};
+
+struct drm_connector *samsung_drm_connector_create(struct drm_device *dev,
+						   struct drm_encoder *encoder)
+{
+	struct samsung_drm_connector *samsung_connector;
+	struct samsung_drm_manager *manager = samsung_drm_get_manager(encoder);
+	struct drm_connector *connector;
+	int type;
+	int err;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_connector = kzalloc(sizeof(*samsung_connector), GFP_KERNEL);
+	if (!samsung_connector) {
+		DRM_ERROR("failed to allocate connector\n");
+		return NULL;
+	}
+
+	connector = &samsung_connector->drm_connector;
+
+	switch (manager->display->type) {
+	case SAMSUNG_DISPLAY_TYPE_HDMI:
+		type = DRM_MODE_CONNECTOR_HDMIA;
+		break;
+	default:
+		type = DRM_MODE_CONNECTOR_Unknown;
+		break;
+	}
+
+	drm_connector_init(dev, connector, &samsung_connector_funcs, type);
+	drm_connector_helper_add(connector, &samsung_connector_helper_funcs);
+
+	err = drm_sysfs_connector_add(connector);
+	if (err)
+		goto err_connector;
+
+	connector->encoder = encoder;
+	err = drm_mode_connector_attach_encoder(connector, encoder);
+	if (err) {
+		DRM_ERROR("failed to attach a connector to a encoder\n");
+		goto err_sysfs;
+	}
+
+	DRM_DEBUG_KMS("connector has been created\n");
+
+	return connector;

drivers/gpu/drm/samsung/samsung_drm_connector.c line 255

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+
+err_sysfs:
+	drm_sysfs_connector_remove(connector);
+err_connector:
+	drm_connector_cleanup(connector);
+	kfree(samsung_connector);
+	return NULL;
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");

Should you also include the rest of the authors?

Quoted 70 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +2 -0
+MODULE_DESCRIPTION("Samsung SoC DRM Connector Driver");
+MODULE_LICENSE("GPL");
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +34 -0
new file mode 100644
index 0000000..638d2b3
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_CONNECTOR_H_
+#define _SAMSUNG_DRM_CONNECTOR_H_
+
+struct drm_connector *samsung_drm_connector_create(struct drm_device *dev,
+						   struct drm_encoder *encoder);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_core.c new file +22 -0
new file mode 100644
index 0000000..752c94c
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Author:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,

drivers/gpu/drm/samsung/samsung_drm_core.c line 32

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "samsung_drm_drv.h"
+#include "samsung_drm_encoder.h"
+#include "samsung_drm_connector.h"
+#include "samsung_drm_fbdev.h"
+

Please explain what the mutex protects.

drivers/gpu/drm/samsung/samsung_drm_core.c line 35

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +3 -0
+static DEFINE_MUTEX(samsung_drm_mutex);
+static LIST_HEAD(samsung_drm_subdrv_list);
+static struct drm_device *drm_dev;

No locking for it? I guess there is not much sense. Would it be possible to have multiple of those - so owuld have to make this an array or list..

drivers/gpu/drm/samsung/samsung_drm_core.c line 44

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +9 -0
+
+static int samsung_drm_subdrv_probe(struct drm_device *dev,
+					struct samsung_drm_subdrv *subdrv)
+{
+	struct drm_encoder *encoder;
+	struct drm_connector *connector;
+	int ret;
+
+	if (subdrv->probe) {

You might as well decleare 'int ret' here.. since you are only using it within this code path.

Quoted 54 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +54 -0
+		ret = subdrv->probe(dev);
+		if (ret)
+			return ret;
+	}
+
+	/* all crtc is available */
+	encoder = samsung_drm_encoder_create(dev, &subdrv->manager,
+			(1 << MAX_CRTC) - 1);
+	if (!encoder) {
+		DRM_ERROR("failed to create encoder\n");
+		return -EFAULT;
+	}
+
+	connector = samsung_drm_connector_create(dev, encoder);
+	if (!connector) {
+		DRM_ERROR("failed to create connector\n");
+		encoder->funcs->destroy(encoder);
+		return -EFAULT;
+	}
+
+	subdrv->encoder = encoder;
+	subdrv->connector = connector;
+
+	return 0;
+}
+
+static void samsung_drm_subdrv_remove(struct drm_device *dev,
+				      struct samsung_drm_subdrv *subdrv)
+{
+	if (subdrv->remove)
+		subdrv->remove(dev);
+
+	if (subdrv->encoder) {
+		struct drm_encoder *encoder = subdrv->encoder;
+		encoder->funcs->destroy(encoder);
+		subdrv->encoder = NULL;
+	}
+
+	if (subdrv->connector) {
+		struct drm_connector *connector = subdrv->connector;
+		connector->funcs->destroy(connector);
+		subdrv->connector = NULL;
+	}
+}
+
+int samsung_drm_device_register(struct drm_device *dev)
+{
+	struct samsung_drm_subdrv *subdrv, *n;
+	int err;
+
+	if (!dev)
+		return -EINVAL;
+
+	if (drm_dev) {

drivers/gpu/drm/samsung/samsung_drm_core.c line 108

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+		DRM_ERROR("Already drm device were registered\n");
+		return -EBUSY;
+	}
+
+	mutex_lock(&samsung_drm_mutex);
+	list_for_each_entry_safe(subdrv, n, &samsung_drm_subdrv_list, list) {
+		err = samsung_drm_subdrv_probe(dev, subdrv);
+		if (err) {
+			DRM_ERROR("samsung drm subdrv probe failed\n");
+			list_del(&subdrv->list);

Ok, so you continue on. If that is OK and you can live with, should you remove the DRM_ERROR and just make it something less scary - as in DRM_DEBUG?

But if you need to stop processing right away, you should probably call 'break' here. Perhaps also remove all the entries from the list?

Either way - please comment what is the "right" way to deal with this.

Quoted 29 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +29 -0
+		}
+	}
+
+	drm_dev = dev;
+	mutex_unlock(&samsung_drm_mutex);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(samsung_drm_device_register);
+
+void samsung_drm_device_unregister(struct drm_device *dev)
+{
+	struct samsung_drm_subdrv *subdrv;
+
+	if (!dev || dev != drm_dev) {
+		WARN(1, "Unexpected drm device unregister!\n");
+		return;
+	}
+
+	mutex_lock(&samsung_drm_mutex);
+	list_for_each_entry(subdrv, &samsung_drm_subdrv_list, list)
+		samsung_drm_subdrv_remove(dev, subdrv);
+
+	drm_dev = NULL;
+	mutex_unlock(&samsung_drm_mutex);
+}
+EXPORT_SYMBOL_GPL(samsung_drm_device_unregister);
+
+static int samsung_drm_mode_group_reinit(struct drm_device *dev)

drivers/gpu/drm/samsung/samsung_drm_core.c line 147

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+{
+	struct drm_mode_group *group = &dev->primary->mode_group;
+	uint32_t *id_list = group->id_list;
+	int ret;
+
+	ret = drm_mode_group_init_legacy_group(dev, group);
+	if (ret < 0)
+		return ret;
+
+	kfree(id_list);

id_list = NULL ?
Just in case somebody calls _twice_ this function.

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +7 -0
+	return 0;
+}
+
+int samsung_drm_subdrv_register(struct samsung_drm_subdrv *subdrv)
+{
+	int err;
+

drivers/gpu/drm/samsung/samsung_drm_core.c line 164

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+	if (!subdrv)
+		return -EINVAL;
+
+	mutex_lock(&samsung_drm_mutex);
+	if (drm_dev) {
+		err = samsung_drm_subdrv_probe(drm_dev, subdrv);
+		if (err) {
+			DRM_ERROR("failed to probe samsung drm subdrv\n");
+			mutex_unlock(&samsung_drm_mutex);
+			return err;

You can make this, and the other two a bit cleaner by using 'goto fail'

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +13 -0
+		}
+
+		err = samsung_drm_fbdev_reinit(drm_dev);
+		if (err) {
+			DRM_ERROR("failed to reinitialize samsung drm fbdev\n");
+			samsung_drm_subdrv_remove(drm_dev, subdrv);
+			mutex_unlock(&samsung_drm_mutex);
+			return err;
+		}
+
+		err = samsung_drm_mode_group_reinit(drm_dev);
+		if (err) {
+			DRM_ERROR("failed to reinitialize mode group\n");

drivers/gpu/drm/samsung/samsung_drm_core.c line 187

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+			samsung_drm_fbdev_fini(drm_dev);
+			samsung_drm_subdrv_remove(drm_dev, subdrv);
+			mutex_unlock(&samsung_drm_mutex);
+			return err;
+		}
+	}
+
+	subdrv->drm_dev = drm_dev;
+
+	list_add_tail(&subdrv->list, &samsung_drm_subdrv_list);

fail:

drivers/gpu/drm/samsung/samsung_drm_core.c line 115

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +3 -0
+	mutex_unlock(&samsung_drm_mutex);
+
+	return 0;

.. and returning err; Naturally you would need to set err = 0 in the decleration.

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +5 -0
+}
+EXPORT_SYMBOL_GPL(samsung_drm_subdrv_register);
+
+void samsung_drm_subdrv_unregister(struct samsung_drm_subdrv *subdrv)
+{

drivers/gpu/drm/samsung/samsung_drm_core.c line 205

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+	if (!subdrv) {
+		WARN(1, "Unexpected samsung drm subdrv unregister!\n");
+		return;
+	}
+
+	mutex_lock(&samsung_drm_mutex);
+	if (drm_dev) {
+		samsung_drm_subdrv_remove(drm_dev, subdrv);
+
+		/* FIXME: error check */

You might as well do it now - before you do the next posting.

Quoted 133 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +8 -0
+		samsung_drm_fbdev_reinit(drm_dev);
+		samsung_drm_mode_group_reinit(drm_dev);
+	}
+
+	list_del(&subdrv->list);
+	mutex_unlock(&samsung_drm_mutex);
+}
+EXPORT_SYMBOL_GPL(samsung_drm_subdrv_unregister);
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +119 -0
new file mode 100644
index 0000000..5836757
@@ -0,0 +1,329 @@
+/* samsung_drm_crtc.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_fb.h"
+#include "samsung_drm_encoder.h"
+
+#define to_samsung_crtc(x)	container_of(x, struct samsung_drm_crtc,\
+				drm_crtc)
+
+/*
+ * @fb_x: horizontal position from framebuffer base
+ * @fb_y: vertical position from framebuffer base
+ * @base_x: horizontal position from screen base
+ * @base_y: vertical position from screen base
+ * @crtc_w: width of crtc
+ * @crtc_h: height of crtc
+ */
+struct samsung_drm_crtc_pos {
+	unsigned int fb_x;
+	unsigned int fb_y;
+	unsigned int base_x;
+	unsigned int base_y;
+	unsigned int crtc_w;
+	unsigned int crtc_h;
+};
+
+struct samsung_drm_crtc {
+	struct drm_crtc			drm_crtc;
+	struct samsung_drm_overlay	overlay;
+	unsigned int			pipe;
+};
+
+static void samsung_drm_overlay_update(struct samsung_drm_overlay *overlay,
+				       struct drm_framebuffer *fb,
+				       struct drm_display_mode *mode,
+				       struct samsung_drm_crtc_pos *pos)
+{
+	struct samsung_drm_buffer_info buffer_info;
+	unsigned int actual_w = pos->crtc_w;
+	unsigned int actual_h = pos->crtc_h;
+	unsigned int hw_w;
+	unsigned int hw_h;
+
+	/* update buffer address of framebuffer. */
+	samsung_drm_fb_update_buf_off(fb, pos->fb_x, pos->fb_y, &buffer_info);
+	overlay->paddr = buffer_info.paddr;
+	overlay->vaddr = buffer_info.vaddr;
+
+	hw_w = mode->hdisplay - pos->base_x;
+	hw_h = mode->vdisplay - pos->base_y;
+
+	if (actual_w > hw_w)
+		actual_w = hw_w;
+	if (actual_h > hw_h)
+		actual_h = hw_h;
+
+	overlay->offset_x = pos->base_x;
+	overlay->offset_y = pos->base_y;
+	overlay->width = actual_w;
+	overlay->height = actual_h;
+
+	DRM_DEBUG_KMS("overlay : offset_x/y(%d,%d), width/height(%d,%d)",
+			overlay->offset_x, overlay->offset_y,
+			overlay->width, overlay->height);
+
+	overlay->buf_offsize = fb->width - actual_w;
+	overlay->line_size = actual_w;
+	overlay->end_buf_off = fb->width * actual_h;
+}
+
+static int samsung_drm_crtc_update(struct drm_crtc *crtc)
+{
+	struct samsung_drm_crtc *samsung_crtc;
+	struct samsung_drm_overlay *overlay;
+	struct samsung_drm_crtc_pos pos;
+	struct drm_display_mode *mode = &crtc->mode;
+	struct drm_framebuffer *fb = crtc->fb;
+
+	if (!mode || !fb)
+		return -EINVAL;
+
+	samsung_crtc = to_samsung_crtc(crtc);
+	overlay = &samsung_crtc->overlay;
+
+	memset(&pos, 0, sizeof(struct samsung_drm_crtc_pos));
+	pos.fb_x = crtc->x;
+	pos.fb_y = crtc->y;
+	pos.crtc_w = fb->width - crtc->x;
+	pos.crtc_h = fb->height - crtc->y;
+

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 129

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +10 -0
+	samsung_drm_overlay_update(overlay, crtc->fb, mode, &pos);
+
+	return 0;
+}
+
+/* CRTC helper functions */
+static void samsung_drm_crtc_dpms(struct drm_crtc *crtc, int mode)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* TODO */

Can you describe in the comment what it is suppose to do?

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 135

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +6 -0
+}
+
+static void samsung_drm_crtc_prepare(struct drm_crtc *crtc)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* drm framework doesn't check NULL. */

Uh, ? What does that have to do with the function?

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 141

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +6 -0
+}
+
+static void samsung_drm_crtc_commit(struct drm_crtc *crtc)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* drm framework doesn't check NULL. */

Ditto

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 150

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +9 -0
+}
+
+static bool
+samsung_drm_crtc_mode_fixup(struct drm_crtc *crtc,
+			    struct drm_display_mode *mode,
+			    struct drm_display_mode *adjusted_mode)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* drm framework doesn't check NULL */

Ditto?

Quoted 140 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +140 -0
+	return true;
+}
+
+static int
+samsung_drm_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
+			  struct drm_display_mode *adjusted_mode, int x, int y,
+			  struct drm_framebuffer *old_fb)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode = adjusted_mode;
+
+	return samsung_drm_crtc_update(crtc);
+}
+
+static int samsung_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
+					  struct drm_framebuffer *old_fb)
+{
+	struct samsung_drm_crtc *samsung_crtc = to_samsung_crtc(crtc);
+	struct samsung_drm_overlay *overlay = &samsung_crtc->overlay;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	ret = samsung_drm_crtc_update(crtc);
+	if (ret)
+		return ret;
+
+	samsung_drm_fn_encoder(crtc, overlay,
+			samsung_drm_encoder_crtc_mode_set);
+	samsung_drm_fn_encoder(crtc, NULL, samsung_drm_encoder_crtc_commit);
+
+	return ret;
+}
+
+static void samsung_drm_crtc_load_lut(struct drm_crtc *crtc)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* drm framework doesn't check NULL */
+}
+
+static struct drm_crtc_helper_funcs samsung_crtc_helper_funcs = {
+	.dpms		= samsung_drm_crtc_dpms,
+	.prepare	= samsung_drm_crtc_prepare,
+	.commit		= samsung_drm_crtc_commit,
+	.mode_fixup	= samsung_drm_crtc_mode_fixup,
+	.mode_set	= samsung_drm_crtc_mode_set,
+	.mode_set_base	= samsung_drm_crtc_mode_set_base,
+	.load_lut	= samsung_drm_crtc_load_lut,
+};
+
+/* CRTC functions */
+static int samsung_drm_crtc_page_flip(struct drm_crtc *crtc,
+				      struct drm_framebuffer *fb,
+				      struct drm_pending_vblank_event *event)
+{
+	struct drm_device *dev = crtc->dev;
+	struct samsung_drm_private *dev_priv = dev->dev_private;
+	struct samsung_drm_crtc *samsung_crtc = to_samsung_crtc(crtc);
+	struct samsung_drm_overlay *overlay = &samsung_crtc->overlay;
+	struct drm_framebuffer *old_fb = crtc->fb;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mutex_lock(&dev->struct_mutex);
+
+	if (event && !dev_priv->pageflip_event) {
+		list_add_tail(&event->base.link,
+				&dev_priv->pageflip_event_list);
+
+		ret = drm_vblank_get(dev, samsung_crtc->pipe);
+		if (ret) {
+			DRM_DEBUG("failed to acquire vblank counter\n");
+			goto out;
+		}
+
+		dev_priv->pageflip_event = true;
+	}
+
+	crtc->fb = fb;
+
+	ret = samsung_drm_crtc_update(crtc);
+	if (ret) {
+		crtc->fb = old_fb;
+		if (event && dev_priv->pageflip_event) {
+			drm_vblank_put(dev, samsung_crtc->pipe);
+			dev_priv->pageflip_event = false;
+		}
+
+		goto out;
+	}
+
+	samsung_drm_fn_encoder(crtc, overlay,
+			samsung_drm_encoder_crtc_mode_set);
+	samsung_drm_fn_encoder(crtc, NULL, samsung_drm_encoder_crtc_commit);
+
+out:
+	mutex_unlock(&dev->struct_mutex);
+	return ret;
+}
+
+static void samsung_drm_crtc_destroy(struct drm_crtc *crtc)
+{
+	struct samsung_drm_crtc *samsung_crtc = to_samsung_crtc(crtc);
+	struct samsung_drm_private *private = crtc->dev->dev_private;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	private->crtc[samsung_crtc->pipe] = NULL;
+
+	drm_crtc_cleanup(crtc);
+	kfree(samsung_crtc);
+}
+
+static struct drm_crtc_funcs samsung_crtc_funcs = {
+	.set_config	= drm_crtc_helper_set_config,
+	.page_flip	= samsung_drm_crtc_page_flip,
+	.destroy	= samsung_drm_crtc_destroy,
+};
+
+struct samsung_drm_overlay *get_samsung_drm_overlay(struct drm_device *dev,
+		struct drm_crtc *crtc)
+{
+	struct samsung_drm_crtc *samsung_crtc = to_samsung_crtc(crtc);
+
+	return &samsung_crtc->overlay;
+}
+
+int samsung_drm_crtc_create(struct drm_device *dev, unsigned int nr)
+{
+	struct samsung_drm_crtc *samsung_crtc;
+	struct samsung_drm_private *private = dev->dev_private;
+	struct drm_crtc *crtc;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_crtc = kzalloc(sizeof(*samsung_crtc), GFP_KERNEL);
+	if (!samsung_crtc) {
+		DRM_ERROR("failed to allocate samsung crtc\n");

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 300

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +10 -0
+		return -ENOMEM;
+	}
+
+	samsung_crtc->pipe = nr;
+	crtc = &samsung_crtc->drm_crtc;
+
+	private->crtc[nr] = crtc;
+
+	drm_crtc_init(dev, crtc, &samsung_crtc_funcs);
+	drm_crtc_helper_add(crtc, &samsung_crtc_helper_funcs);

Who is responsible for deallocating samsung_crtc?

Quoted 163 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +29 -0
+
+	return 0;
+}
+
+int samsung_drm_crtc_enable_vblank(struct drm_device *dev, int crtc)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_drm_fn_encoder(private->crtc[crtc], &crtc,
+			samsung_drm_enable_vblank);
+
+	return 0;
+}
+
+void samsung_drm_crtc_disable_vblank(struct drm_device *dev, int crtc)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_drm_fn_encoder(private->crtc[crtc], &crtc,
+			samsung_drm_disable_vblank);
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");
+MODULE_DESCRIPTION("Samsung SoC DRM CRTC Driver");
+MODULE_LICENSE("GPL");
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +38 -0
new file mode 100644
index 0000000..c6998e1
@@ -0,0 +1,38 @@
+/* samsung_drm_crtc.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_CRTC_H_
+#define _SAMSUNG_DRM_CRTC_H_
+
+struct samsung_drm_overlay *get_samsung_drm_overlay(struct drm_device *dev,
+		struct drm_crtc *crtc);
+int samsung_drm_crtc_create(struct drm_device *dev, unsigned int nr);
+int samsung_drm_crtc_enable_vblank(struct drm_device *dev, int crtc);
+void samsung_drm_crtc_disable_vblank(struct drm_device *dev, int crtc);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +84 -0
new file mode 100644
index 0000000..6e812b3
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm.h"
+
+#include <drm/samsung_drm.h>
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_crtc.h"
+#include "samsung_drm_fbdev.h"
+#include "samsung_drm_fb.h"
+#include "samsung_drm_gem.h"
+
+#define DRIVER_NAME	"samsung-drm"
+#define DRIVER_DESC	"Samsung SoC DRM"
+#define DRIVER_DATE	"20110530"
+#define DRIVER_MAJOR	1
+#define DRIVER_MINOR	0
+
+static int samsung_drm_load(struct drm_device *dev, unsigned long flags)
+{
+	struct samsung_drm_private *private;
+	int ret;
+	int nr;
+
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	private = kzalloc(sizeof(struct samsung_drm_private), GFP_KERNEL);
+	if (!private) {
+		DRM_ERROR("failed to allocate private\n");
+		return -ENOMEM;
+	}
+
+	INIT_LIST_HEAD(&private->pageflip_event_list);
+	dev->dev_private = (void *)private;
+
+	drm_mode_config_init(dev);
+
+	samsung_drm_mode_config_init(dev);
+
+	for (nr = 0; nr < MAX_CRTC; nr++) {
+		ret = samsung_drm_crtc_create(dev, nr);
+		if (ret)
+			goto err_crtc;
+	}
+
+	ret = drm_vblank_init(dev, MAX_CRTC);
+	if (ret)
+		goto err_crtc;
+
+	ret = samsung_drm_device_register(dev);
+	if (ret)
+		goto err_vblank;
+
+	ret = samsung_drm_fbdev_init(dev);
+	if (ret) {
+		DRM_ERROR("failed to initialize drm fbdev\n");
+		goto err_drm_device;
+	}

drivers/gpu/drm/samsung/samsung_drm_drv.c line 94

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +10 -0
+
+	return 0;
+
+err_drm_device:
+	samsung_drm_device_unregister(dev);
+err_vblank:
+	drm_vblank_cleanup(dev);
+err_crtc:
+	drm_mode_config_cleanup(dev);
+	kfree(private);

You might want to do dev->dev_private = NULL just in case This drm_unload is called twice.

Quoted 178 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +121 -0
+
+	return ret;
+}
+
+static int samsung_drm_unload(struct drm_device *dev)
+{
+	samsung_drm_fbdev_fini(dev);
+	samsung_drm_device_unregister(dev);
+	drm_vblank_cleanup(dev);
+	drm_mode_config_cleanup(dev);
+	kfree(dev->dev_private);
+
+	return 0;
+}
+
+static int samsung_drm_open(struct drm_device *dev, struct drm_file *file_priv)
+{
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	return 0;
+}
+
+static void samsung_drm_lastclose(struct drm_device *dev)
+{
+	samsung_drm_fbdev_restore_mode(dev);
+}
+
+static struct vm_operations_struct samsung_drm_gem_vm_ops = {
+	.fault = samsung_drm_gem_fault,
+	.open = drm_gem_vm_open,
+	.close = drm_gem_vm_close,
+};
+
+static struct drm_ioctl_desc samsung_ioctls[] = {
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+			DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MAP_OFFSET,
+			samsung_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
+				DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MMAP,
+			samsung_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
+};
+
+static struct drm_driver samsung_drm_driver = {
+	.driver_features	= DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
+				  DRIVER_MODESET | DRIVER_GEM,
+	.load			= samsung_drm_load,
+	.unload			= samsung_drm_unload,
+	.open			= samsung_drm_open,
+	.lastclose		= samsung_drm_lastclose,
+	.get_vblank_counter	= drm_vblank_count,
+	.enable_vblank		= samsung_drm_crtc_enable_vblank,
+	.disable_vblank		= samsung_drm_crtc_disable_vblank,
+	.gem_init_object	= samsung_drm_gem_init_object,
+	.gem_free_object	= samsung_drm_gem_free_object,
+	.gem_vm_ops		= &samsung_drm_gem_vm_ops,
+	.dumb_create		= samsung_drm_gem_dumb_create,
+	.dumb_map_offset	= samsung_drm_gem_dumb_map_offset,
+	.dumb_destroy		= samsung_drm_gem_dumb_destroy,
+	.ioctls			= samsung_ioctls,
+	.fops = {
+		.owner		= THIS_MODULE,
+		.open		= drm_open,
+		.mmap		= samsung_drm_gem_mmap,
+		.poll		= drm_poll,
+		.read		= drm_read,
+		.unlocked_ioctl	= drm_ioctl,
+		.release	= drm_release,
+	},
+	.name	= DRIVER_NAME,
+	.desc	= DRIVER_DESC,
+	.date	= DRIVER_DATE,
+	.major	= DRIVER_MAJOR,
+	.minor	= DRIVER_MINOR,
+};
+
+static int samsung_drm_platform_probe(struct platform_device *pdev)
+{
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	samsung_drm_driver.num_ioctls = DRM_ARRAY_SIZE(samsung_ioctls);
+
+	return drm_platform_init(&samsung_drm_driver, pdev);
+}
+
+static int samsung_drm_platform_remove(struct platform_device *pdev)
+{
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	drm_platform_exit(&samsung_drm_driver, pdev);
+
+	return 0;
+}
+
+static struct platform_driver samsung_drm_platform_driver = {
+	.probe		= samsung_drm_platform_probe,
+	.remove		= __devexit_p(samsung_drm_platform_remove),
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= DRIVER_NAME,
+	},
+};
+
+static int __init samsung_drm_init(void)
+{
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	return platform_driver_register(&samsung_drm_platform_driver);
+}
+
+static void __exit samsung_drm_exit(void)
+{
+	platform_driver_unregister(&samsung_drm_platform_driver);
+}
+
+module_init(samsung_drm_init);
+module_exit(samsung_drm_exit);
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");
+MODULE_DESCRIPTION("Samsung SoC DRM Driver");
+MODULE_LICENSE("GPL");
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +51 -0
new file mode 100644
index 0000000..a5a49c2
@@ -0,0 +1,194 @@
+/* samsung_drm_drv.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_DRV_H_
+#define _SAMSUNG_DRM_DRV_H_
+
+#include "drm.h"
+
+#define MAX_CRTC	2
+
+struct drm_device;
+struct samsung_drm_overlay;
+struct drm_connector;
+
+enum samsung_drm_output_type {
+	SAMSUNG_DISPLAY_TYPE_NONE,
+	SAMSUNG_DISPLAY_TYPE_LCD,	/* RGB or CPU Interface. */
+	SAMSUNG_DISPLAY_TYPE_HDMI,	/* HDMI Interface. */
+};
+
+/**
+ * Samsung drm overlay ops structure.
+ *
+ * @mode_set: copy drm overlay info to hw specific overlay info.
+ * @commit: set hw specific overlay into to hw.
+ */
+struct samsung_drm_overlay_ops {

drivers/gpu/drm/samsung/samsung_drm_drv.h line 61

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+	void (*mode_set)(struct device *subdrv_dev,
+			 struct samsung_drm_overlay *overlay);
+	void (*commit)(struct device *subdrv_dev);
+	void (*disable)(struct device *subdrv_dev);
+};
+
+/**
+ * Samsung drm common overlay structure.
+ *
+ * @win_num: window number.

Not seeing that.

drivers/gpu/drm/samsung/samsung_drm_drv.h line 68

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +7 -0
+ * @offset_x: offset to x position.
+ * @offset_y: offset to y position.
+ * @pos_x: x position.
+ * @pos_y: y position.
+ * @width: window width.
+ * @height: window height.
+ * @bpp: bit per pixel.

Ditto

drivers/gpu/drm/samsung/samsung_drm_drv.h line 69

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * @paddr: physical memory address to this overlay.

That is CPU physical or bus physical (DMA)

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +4 -0
+ * @vaddr: virtual memory addresss to this overlay.
+ * @buf_off: start offset of framebuffer to be displayed.
+ * @end_buf_off: end offset of framebuffer to be displayed.
+ * @buf_offsize: this value has result from

drivers/gpu/drm/samsung/samsung_drm_drv.h line 83

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+ *			(framebuffer width - display width) * bpp.
+ * @line_size: line size to this overlay memory in bytes.
+ * @default_win: a window to be enabled.
+ * @color_key: color key on or off.
+ * @index_color: if using color key feature then this value would be used
+ *			as index color.
+ * @local_path: in case of lcd type, local path mode on or off.
+ * @transparency: transparency on or off.
+ * @activated: activated or not.
+ * @subdrv_dev: pointer to device object for subdrv device driver.

?

drivers/gpu/drm/samsung/samsung_drm_drv.h line 87

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +4 -0
+ * @ops: pointer to samsung_drm_overlay_ops.
+ *
+ * this structure is common to Samsung SoC and would be copied
+ * to hardware specific overlay info.

Uh?

drivers/gpu/drm/samsung/samsung_drm_drv.h line 94

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +7 -0
+ */
+struct samsung_drm_overlay {
+	unsigned int offset_x;
+	unsigned int offset_y;
+	unsigned int width;
+	unsigned int height;
+	unsigned int paddr;

You don't want to use 'dma_addr_t' ?

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +9 -0
+	void __iomem *vaddr;
+	unsigned int buf_off;
+	unsigned int end_buf_off;
+	unsigned int buf_offsize;
+	unsigned int line_size;
+
+	bool default_win;
+	bool color_key;
+	unsigned int index_color;

drivers/gpu/drm/samsung/samsung_drm_drv.h line 113

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+	bool local_path;
+	bool transparency;
+	bool activated;
+};
+
+/**
+ * Samsung DRM Display Structure.
+ *	- this structure is common to analog tv, digital tv and lcd panel.
+ *
+ * @dev: pointer to specific device object.

??

Quoted 32 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +32 -0
+ * @is_connected: check for that display is connected or not.
+ * @get_edid: get edid modes from display driver.
+ * @get_timing: get timing object from display driver.
+ * @check_timing: check if timing is valid or not.
+ * @power_on: display device on or off.
+ */
+struct samsung_drm_display {
+	unsigned int type;
+	bool (*is_connected)(struct device *dev);
+	int (*get_edid)(struct device *dev, struct drm_connector *connector,
+				u8 *edid, int len);
+	void *(*get_timing)(struct device *dev);
+	int (*check_timing)(struct device *dev, void *timing);
+	int (*power_on)(struct device *dev, int mode);
+};
+
+/**
+ * Samsung drm manager ops
+ *
+ * @mode_set: convert drm_display_mode to hw specific display mode and
+ *	      would be called by encoder->mode_set().
+ * @commit: set current hw specific display mode to hw.
+ * @enable_vblank: specific driver callback for enabling vblank interrupt.
+ * @disable_vblank: specific driver callback for disabling vblank interrupt.
+ */
+struct samsung_drm_manager_ops {
+	void (*mode_set)(struct device *subdrv_dev, void *mode);
+	void (*commit)(struct device *subdrv_dev);
+	int (*enable_vblank)(struct device *subdrv_dev);
+	void (*disable_vblank)(struct device *subdrv_dev);
+};
+

drivers/gpu/drm/samsung/samsung_drm_drv.h line 155

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+/**
+ * Samsung drm common manager structure.
+ *
+ * @dev: pointer to device object for subdrv device driver.
+ * @ops: ops pointer to samsung drm common framebuffer.
+ *	 ops of fimd or hdmi driver should be set to this ones.
+ */
+struct samsung_drm_manager {
+	struct device *dev;
+	int pipe;

No comment for that?

drivers/gpu/drm/samsung/samsung_drm_drv.h line 158

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+	struct samsung_drm_manager_ops *ops;
+	struct samsung_drm_overlay_ops *overlay_ops;
+	struct samsung_drm_display *display;

And you are missing the comments for these two.

drivers/gpu/drm/samsung/samsung_drm_drv.h line 45

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+};
+
+/**

I just noticed it, but the '**' is not the kerneldoc style comment. You might want to remove them from all the files.

drivers/gpu/drm/samsung/samsung_drm_drv.h line 162

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * Samsung drm private structure.

Ok, you are defining it in a public header so you should at least document what the fields mean.

If you don't want the public to use it - make another header file, helpfully called 'xxx_private.h'

drivers/gpu/drm/samsung/samsung_drm_drv.h line 173

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +11 -0
+ */
+struct samsung_drm_private {
+	struct drm_fb_helper *fb_helper;
+
+	/* for pageflip */
+	struct list_head pageflip_event_list;
+	bool pageflip_event;
+
+	struct drm_crtc *crtc[MAX_CRTC];
+
+	/* add some structures. */

Umm, which ones?

Quoted 235 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +21 -0
+};
+
+struct samsung_drm_subdrv {
+	struct list_head list;
+	struct drm_device *drm_dev;
+
+	/* driver ops */
+	int (*probe)(struct drm_device *dev);
+	void (*remove)(struct drm_device *dev);
+
+	struct samsung_drm_manager manager;
+	struct drm_encoder *encoder;
+	struct drm_connector *connector;
+};
+
+int samsung_drm_device_register(struct drm_device *dev);
+void samsung_drm_device_unregister(struct drm_device *dev);
+int samsung_drm_subdrv_register(struct samsung_drm_subdrv *drm_subdrv);
+void samsung_drm_subdrv_unregister(struct samsung_drm_subdrv *drm_subdrv);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +208 -0
new file mode 100644
index 0000000..c875968
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_crtc.h"
+#include "samsung_drm_encoder.h"
+
+#define to_samsung_encoder(x)	container_of(x, struct samsung_drm_encoder,\
+				drm_encoder)
+
+struct samsung_drm_encoder {
+	struct drm_encoder		drm_encoder;
+	struct samsung_drm_manager	*manager;
+};
+
+static void samsung_drm_encoder_dpms(struct drm_encoder *encoder, int mode)
+{
+	struct drm_device *dev = encoder->dev;
+	struct drm_connector *connector;
+	struct samsung_drm_manager *manager = samsung_drm_get_manager(encoder);
+
+	DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__, mode);
+
+	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
+		if (connector->encoder == encoder) {
+			struct samsung_drm_display *display = manager->display;
+
+			if (display && display->power_on)
+				display->power_on(manager->dev, mode);
+		}
+	}
+}
+
+static bool
+samsung_drm_encoder_mode_fixup(struct drm_encoder *encoder,
+			       struct drm_display_mode *mode,
+			       struct drm_display_mode *adjusted_mode)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return true;
+}
+
+static void samsung_drm_encoder_mode_set(struct drm_encoder *encoder,
+					 struct drm_display_mode *mode,
+					 struct drm_display_mode *adjusted_mode)
+{
+	struct drm_device *dev = encoder->dev;
+	struct drm_connector *connector;
+	struct samsung_drm_manager *manager = samsung_drm_get_manager(encoder);
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+	struct samsung_drm_overlay *overlay = get_samsung_drm_overlay(dev,
+						encoder->crtc);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode = adjusted_mode;
+
+	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
+		if (connector->encoder == encoder) {
+			if (manager_ops && manager_ops->mode_set)
+				manager_ops->mode_set(manager->dev, mode);
+
+			if (overlay_ops && overlay_ops->mode_set)
+				overlay_ops->mode_set(manager->dev, overlay);
+		}
+	}
+}
+
+static void samsung_drm_encoder_prepare(struct drm_encoder *encoder)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+}
+
+static void samsung_drm_encoder_commit(struct drm_encoder *encoder)
+{
+	struct samsung_drm_manager *manager = samsung_drm_get_manager(encoder);
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (manager_ops && manager_ops->commit)
+		manager_ops->commit(manager->dev);
+
+	if (overlay_ops && overlay_ops->commit)
+		overlay_ops->commit(manager->dev);
+}
+
+static struct drm_crtc *
+samsung_drm_encoder_get_crtc(struct drm_encoder *encoder)
+{
+	return encoder->crtc;
+}
+
+static struct drm_encoder_helper_funcs samsung_encoder_helper_funcs = {
+	.dpms		= samsung_drm_encoder_dpms,
+	.mode_fixup	= samsung_drm_encoder_mode_fixup,
+	.mode_set	= samsung_drm_encoder_mode_set,
+	.prepare	= samsung_drm_encoder_prepare,
+	.commit		= samsung_drm_encoder_commit,
+	.get_crtc	= samsung_drm_encoder_get_crtc,
+};
+
+static void samsung_drm_encoder_destroy(struct drm_encoder *encoder)
+{
+	struct samsung_drm_encoder *samsung_encoder =
+		to_samsung_encoder(encoder);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_encoder->manager->pipe = -1;
+
+	drm_encoder_cleanup(encoder);
+	encoder->dev->mode_config.num_encoder--;
+	kfree(samsung_encoder);
+}
+
+static struct drm_encoder_funcs samsung_encoder_funcs = {
+	.destroy = samsung_drm_encoder_destroy,
+};
+
+struct drm_encoder *
+samsung_drm_encoder_create(struct drm_device *dev,
+			   struct samsung_drm_manager *manager,
+			   unsigned int possible_crtcs)
+{
+	struct drm_encoder *encoder;
+	struct samsung_drm_encoder *samsung_encoder;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (!manager || !possible_crtcs)
+		return NULL;
+
+	if (!manager->dev)
+		return NULL;
+
+	samsung_encoder = kzalloc(sizeof(*samsung_encoder), GFP_KERNEL);
+	if (!samsung_encoder) {
+		DRM_ERROR("failed to allocate encoder\n");
+		return NULL;
+	}
+
+	samsung_encoder->manager = manager;
+	encoder = &samsung_encoder->drm_encoder;
+	encoder->possible_crtcs = possible_crtcs;
+
+	DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
+
+	drm_encoder_init(dev, encoder, &samsung_encoder_funcs,
+			DRM_MODE_ENCODER_TMDS);
+
+	drm_encoder_helper_add(encoder, &samsung_encoder_helper_funcs);
+
+	DRM_DEBUG_KMS("encoder has been created\n");
+
+	return encoder;
+}
+
+struct samsung_drm_manager *samsung_drm_get_manager(struct drm_encoder *encoder)
+{
+	return to_samsung_encoder(encoder)->manager;
+}
+
+void samsung_drm_fn_encoder(struct drm_crtc *crtc, void *data,
+			    void (*fn)(struct drm_encoder *, void *))
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_encoder *encoder;
+
+	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
+		if (encoder->crtc != crtc)
+			continue;
+
+		fn(encoder, data);
+	}
+}
+
+void samsung_drm_enable_vblank(struct drm_encoder *encoder, void *data)

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 218

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +10 -0
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	int crtc = *(int *)data;
+
+	if (manager->pipe == -1)
+		manager->pipe = crtc;
+
+	/* old_crtc checking needs? FIXME!!! */

Is this still pertient?

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 229

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +11 -0
+
+	if (manager_ops->enable_vblank)
+		manager_ops->enable_vblank(manager->dev);
+}
+
+void samsung_drm_disable_vblank(struct drm_encoder *encoder, void *data)
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	int crtc = *(int *)data;

You don't want to check whether data is NULL before you derefernce it?

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 218

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +5 -0
+
+	if (manager->pipe == -1)
+		manager->pipe = crtc;
+
+	/* old_crtc checking needs? FIXME!!! */

I am not really sure what it means.. It probably means something to you - but perhaps it might make sense to expand it in case somebody else wants to implement this?

Quoted 15 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +15 -0
+
+	if (manager_ops->disable_vblank)
+		manager_ops->disable_vblank(manager->dev);
+}
+
+void samsung_drm_encoder_crtc_commit(struct drm_encoder *encoder, void *data)
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+
+	overlay_ops->commit(manager->dev);
+}
+
+void samsung_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data)

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 259

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +10 -0
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+	struct samsung_drm_overlay *overlay = data;
+
+	overlay_ops->mode_set(manager->dev, overlay);
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");

You don't want to include the rest of the authors?

Quoted 104 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +2 -0
+MODULE_DESCRIPTION("Samsung SoC DRM Encoder Driver");
+MODULE_LICENSE("GPL");
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +45 -0
new file mode 100644
index 0000000..99040b2
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_ENCODER_H_
+#define _SAMSUNG_DRM_ENCODER_H_
+
+struct samsung_drm_manager;
+
+struct drm_encoder *samsung_drm_encoder_create(struct drm_device *dev,
+					       struct samsung_drm_manager *mgr,
+					       unsigned int possible_crtcs);
+struct samsung_drm_manager *
+samsung_drm_get_manager(struct drm_encoder *encoder);
+void samsung_drm_fn_encoder(struct drm_crtc *crtc, void *data,
+			    void (*fn)(struct drm_encoder *, void *));
+void samsung_drm_enable_vblank(struct drm_encoder *encoder, void *data);
+void samsung_drm_disable_vblank(struct drm_encoder *encoder, void *data);
+void samsung_drm_encoder_crtc_commit(struct drm_encoder *encoder, void *data);
+void samsung_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +45 -0
new file mode 100644
index 0000000..f087ecf
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_fb.h"
+#include "samsung_drm_buf.h"
+#include "samsung_drm_gem.h"
+
+#define to_samsung_fb(x)	container_of(x, struct samsung_drm_fb, fb)
+
+struct samsung_drm_fb {
+	struct drm_framebuffer		fb;
+	struct samsung_drm_gem_obj	*samsung_gem_obj;
+
+	unsigned int			fb_size;
+	dma_addr_t			paddr;
+	void __iomem			*vaddr;
+};

drivers/gpu/drm/samsung/samsung_drm_fb.c line 55

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +10 -0
+
+static void samsung_drm_fb_destroy(struct drm_framebuffer *fb)
+{
+	struct samsung_drm_fb *samsung_fb = to_samsung_fb(fb);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	drm_framebuffer_cleanup(fb);
+
+	/* default framebuffer has no gem object so it releases buffer. */

What is 'it' ?

drivers/gpu/drm/samsung/samsung_drm_fb.c line 60

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +5 -0
+	if (!samsung_fb->samsung_gem_obj)
+		samsung_drm_buf_destroy(fb->dev,
+				samsung_fb->samsung_gem_obj->entry);
+
+	kfree(samsung_fb);

samsung_fb = NULL;

Quoted 122 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +122 -0
+}
+
+static int samsung_drm_fb_create_handle(struct drm_framebuffer *fb,
+					struct drm_file *file_priv,
+					unsigned int *handle)
+{
+	struct samsung_drm_fb *samsung_fb = to_samsung_fb(fb);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return drm_gem_handle_create(file_priv,
+					&samsung_fb->samsung_gem_obj->base,
+					handle);
+}
+
+static int samsung_drm_fb_dirty(struct drm_framebuffer *fb,
+				struct drm_file *file_priv, unsigned flags,
+				unsigned color, struct drm_clip_rect *clips,
+				unsigned num_clips)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	/*
+	 * update framebuffer and its hardware.
+	 * - this callback would be called by user application
+	 *	with DRM_IOCTL_MODE_DIRTYFB command.
+	 *
+	 * ps. Userspace can notify the driver via this callback
+	 * that an area of the framebuffer has been changed then should
+	 * be flushed to the display hardware.
+	 */
+
+	return 0;
+}
+
+static struct drm_framebuffer_funcs samsung_drm_fb_funcs = {
+	.destroy	= samsung_drm_fb_destroy,
+	.create_handle	= samsung_drm_fb_create_handle,
+	.dirty		= samsung_drm_fb_dirty,
+};
+
+static struct drm_framebuffer *
+samsung_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev,
+		    struct drm_mode_fb_cmd *mode_cmd)
+{
+	struct samsung_drm_fb *samsung_fb;
+	struct drm_framebuffer *fb;
+	struct samsung_drm_gem_obj *samsung_gem_obj = NULL;
+	struct drm_gem_object *obj;
+	unsigned int size;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode_cmd->pitch = max(mode_cmd->pitch,
+			mode_cmd->width * (mode_cmd->bpp >> 3));
+
+	DRM_LOG_KMS("drm fb create(%dx%d)\n",
+			mode_cmd->width, mode_cmd->height);
+
+	samsung_fb = kzalloc(sizeof(*samsung_fb), GFP_KERNEL);
+	if (!samsung_fb) {
+		DRM_ERROR("failed to allocate samsung drm framebuffer.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	fb = &samsung_fb->fb;
+	ret = drm_framebuffer_init(dev, fb, &samsung_drm_fb_funcs);
+	if (ret) {
+		DRM_ERROR("failed to initialize framebuffer.\n");
+		goto err_init;
+	}
+
+	DRM_LOG_KMS("create: fb id: %d\n", fb->base.id);
+
+	size = mode_cmd->pitch * mode_cmd->height;
+
+	/*
+	 * mode_cmd->handle could be pointer to a buffer allocated by user
+	 * application using KMS library.
+	 */
+	if (!mode_cmd->handle) {
+		/*
+		 * in case that file_priv is NULL, it allocates only buffer and
+		 * this buffer would be used for default framebuffer.
+		 */
+		if (!file_priv) {
+			struct samsung_drm_buf_entry *entry;
+
+			entry = samsung_drm_buf_create(dev, size);
+			if (IS_ERR(entry)) {
+				ret = PTR_ERR(entry);
+				goto err_buf_create;
+			}
+
+			samsung_fb->vaddr = entry->vaddr;
+			samsung_fb->paddr = entry->paddr;
+
+			DRM_LOG_KMS("default fb: paddr = 0x%x, size = 0x%x\n",
+					entry->paddr, size);
+
+			goto out;
+		} else {
+			samsung_gem_obj = samsung_drm_gem_create(file_priv, dev,
+							size,
+							&mode_cmd->handle);
+			if (IS_ERR(samsung_gem_obj)) {
+				ret = PTR_ERR(samsung_gem_obj);
+				goto err_gem_create;
+			}
+		}
+	} else {
+		obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
+		if (!obj) {
+			DRM_ERROR("failed to lookup gem object.\n");
+			goto err_lookup;
+		}
+
+		samsung_gem_obj = to_samsung_gem_obj(obj);
+
+		drm_gem_object_unreference_unlocked(obj);
+	}

drivers/gpu/drm/samsung/samsung_drm_fb.c line 192

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +10 -0
+
+	/*
+	 * in case of getting samsung_gem_obj from either handle or
+	 * new creation.
+	 */
+	samsung_fb->vaddr = samsung_gem_obj->entry->vaddr;
+	samsung_fb->paddr = samsung_gem_obj->entry->paddr;
+
+	DRM_LOG_KMS("paddr = 0x%x, size = 0x%x, gem object = 0x%x\n",
+			samsung_fb->paddr, size, (u32)&samsung_gem_obj->base);

Why truncating it to be 4GB? Is it potentially possible that this could run a machine with 5GB?

drivers/gpu/drm/samsung/samsung_drm_fb.c line 204

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +12 -0
+
+out:
+	samsung_fb->samsung_gem_obj = samsung_gem_obj;
+	samsung_fb->fb_size = size;
+
+	drm_helper_mode_fill_fb_struct(fb, mode_cmd);
+
+	return fb;
+
+err_lookup:
+err_gem_create:
+err_buf_create:

Why don't you just coalesce them all together and call it:
err:

Quoted 155 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +58 -0
+	drm_framebuffer_cleanup(fb);
+
+err_init:
+	kfree(samsung_fb);
+
+	return ERR_PTR(ret);
+}
+
+struct drm_framebuffer *samsung_drm_fb_create(struct drm_device *dev,
+					      struct drm_file *file_priv,
+					      struct drm_mode_fb_cmd *mode_cmd)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return samsung_drm_fb_init(file_priv, dev, mode_cmd);
+}
+
+void samsung_drm_fb_update_buf_off(struct drm_framebuffer *fb,
+				   unsigned int x, unsigned int y,
+				   struct samsung_drm_buffer_info *info)
+{
+	struct samsung_drm_fb *samsung_fb = to_samsung_fb(fb);
+	unsigned long offset;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	offset = x * (fb->bits_per_pixel >> 3);
+	offset += y * fb->pitch;
+
+	info->base_addr = samsung_fb->paddr;
+	info->vaddr = samsung_fb->vaddr + offset;
+	info->paddr = samsung_fb->paddr + offset;
+
+	DRM_DEBUG_KMS("updated vaddr = 0x%x, paddr = 0x%x, offset = 0x%x\n",
+			(unsigned int)info->vaddr,
+			(unsigned int)info->paddr,
+			(unsigned int)offset);
+}
+
+static struct drm_mode_config_funcs samsung_drm_mode_config_funcs = {
+	.fb_create = samsung_drm_fb_create,
+};
+
+void samsung_drm_mode_config_init(struct drm_device *dev)
+{
+	dev->mode_config.min_width = 0;
+	dev->mode_config.min_height = 0;
+
+	/*
+	 * It sets max width and height as default value(4096x4096).
+	 * this value would be used to check for framebuffer size limitation
+	 * at drm_mode_addfb().
+	 */
+	dev->mode_config.max_width = 4096;
+	dev->mode_config.max_height = 4096;
+
+	dev->mode_config.funcs = &samsung_drm_mode_config_funcs;
+}
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +47 -0
new file mode 100644
index 0000000..6256089
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_FB_H_
+#define _SAMSUNG_DRM_FB_H
+
+struct samsung_drm_buffer_info {
+	unsigned long base_addr;
+	dma_addr_t paddr;
+	void __iomem *vaddr;
+};
+
+void samsung_drm_fb_update_buf_off(struct drm_framebuffer *fb,
+				   unsigned int x, unsigned int y,
+				   struct samsung_drm_buffer_info *info);
+
+struct drm_framebuffer *samsung_drm_fb_create(struct drm_device *dev,
+					      struct drm_file *filp,
+					      struct drm_mode_fb_cmd *mode_cmd);
+
+void samsung_drm_mode_config_init(struct drm_device *dev);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +38 -0
new file mode 100644
index 0000000..1c46bc6
@@ -0,0 +1,409 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc.h"
+#include "drm_fb_helper.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_fb.h"
+
+#define to_samsung_fbdev(x)	container_of(x, struct samsung_drm_fbdev,\
+				drm_fb_helper)
+

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 48

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +10 -0
+struct samsung_drm_fbdev {
+	struct drm_fb_helper	drm_fb_helper;
+	struct drm_framebuffer	*fb;
+};
+
+static inline unsigned int chan_to_field(unsigned int chan,
+					 struct fb_bitfield *bf)
+{
+	chan &= 0xffff;
+	chan >>= 16 - bf->length;

Any chance that bf->length can be bigger than 16? And cause this to return um wrong vlaues?

perhaps chan >>= (16 - max(16,bf->length));

?

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +5 -0
+
+	return chan << bf->offset;
+}
+
+static int samsung_drm_fbdev_setcolreg(unsigned regno, unsigned red,

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 63

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +10 -0
+				       unsigned green, unsigned blue,
+				       unsigned transp, struct fb_info *info)
+{
+	unsigned int val;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	switch (info->fix.visual) {
+	case FB_VISUAL_TRUECOLOR:
+		if (regno < 16) {

Not <=?

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 71

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
+			u32 *pal = info->pseudo_palette;
+
+			val = chan_to_field(red, &info->var.red);
+			val |= chan_to_field(green, &info->var.green);
+			val |= chan_to_field(blue, &info->var.blue);
+
+			pal[regno] = val;
+		}

so if regno > 16 then we still return 0. Should we return -EINVAL instead.

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 74

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +3 -0
+		break;
+	default:
+		return 1;

-EINVAL?

Quoted 69 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +69 -0
+	}
+
+	return 0;
+}
+
+static struct fb_ops samsung_drm_fb_ops = {
+	.owner		= THIS_MODULE,
+	.fb_fillrect	= cfb_fillrect,
+	.fb_copyarea	= cfb_copyarea,
+	.fb_imageblit	= cfb_imageblit,
+	.fb_check_var	= drm_fb_helper_check_var,
+	.fb_set_par	= drm_fb_helper_set_par,
+	.fb_setcolreg	= samsung_drm_fbdev_setcolreg,
+	.fb_blank	= drm_fb_helper_blank,
+	.fb_pan_display	= drm_fb_helper_pan_display,
+	.fb_setcmap	= drm_fb_helper_setcmap,
+};
+
+static void samsung_drm_fbdev_update(struct drm_fb_helper *helper,
+				     struct drm_framebuffer *fb,
+				     unsigned int fb_width,
+				     unsigned int fb_height)
+{
+	struct fb_info *fbi = helper->fbdev;
+	struct drm_device *dev = helper->dev;
+	struct samsung_drm_fbdev *samsung_fb = to_samsung_fbdev(helper);
+	struct samsung_drm_buffer_info buffer_info;
+	unsigned int size = fb_width * fb_height * (fb->bits_per_pixel >> 3);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_fb->fb = fb;
+
+	drm_fb_helper_fill_fix(fbi, fb->pitch, fb->depth);
+	drm_fb_helper_fill_var(fbi, helper, fb_width, fb_height);
+
+	samsung_drm_fb_update_buf_off(fb, fbi->var.xoffset, fbi->var.yoffset,
+			&buffer_info);
+
+	dev->mode_config.fb_base = buffer_info.base_addr;
+
+	fbi->screen_base = buffer_info.vaddr;
+	fbi->screen_size = size;
+	fbi->fix.smem_start = buffer_info.paddr;
+	fbi->fix.smem_len = size;
+}
+
+static int samsung_drm_fbdev_create(struct drm_fb_helper *helper,
+				    struct drm_fb_helper_surface_size *sizes)
+{
+	struct samsung_drm_fbdev *samsung_fbdev = to_samsung_fbdev(helper);
+	struct drm_device *dev = helper->dev;
+	struct fb_info *fbi;
+	struct drm_mode_fb_cmd mode_cmd = { 0 };
+	struct platform_device *pdev = dev->platformdev;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	DRM_DEBUG_KMS("surface width(%d), height(%d) and bpp(%d\n",
+			sizes->surface_width, sizes->surface_height,
+			sizes->surface_bpp);
+
+	mode_cmd.width = sizes->surface_width;
+	mode_cmd.height = sizes->surface_height;
+	mode_cmd.bpp = sizes->surface_bpp;
+	mode_cmd.depth = sizes->surface_depth;
+
+	mutex_lock(&dev->struct_mutex);

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 153

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +10 -0
+
+	fbi = framebuffer_alloc(0, &pdev->dev);
+	if (!fbi) {
+		DRM_ERROR("failed to allocate fb info.\n");
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	samsung_fbdev->fb = samsung_drm_fb_create(dev, NULL, &mode_cmd);
+	if (IS_ERR(samsung_fbdev->fb)) {

You probably want to do IS_ERR_OR_NULL?

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 155

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +2 -0
+		DRM_ERROR("failed to create drm dramebuffer.\n");
+		ret = PTR_ERR(samsung_fbdev->fb);

framebuffer_release ?

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 167

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +12 -0
+		goto out;
+	}
+
+	helper->fb = samsung_fbdev->fb;
+	helper->fbdev = fbi;
+
+	fbi->par = helper;
+	fbi->flags = FBINFO_FLAG_DEFAULT;
+	fbi->fbops = &samsung_drm_fb_ops;
+
+	ret = fb_alloc_cmap(&fbi->cmap, 256, 0);
+	if (ret) {

framebuffer_release ?

Or just add a new label that will make that call.

Quoted 80 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +80 -0
+		DRM_ERROR("failed to allocate cmap.\n");
+		goto out;
+	}
+
+	samsung_drm_fbdev_update(helper, helper->fb, sizes->fb_width,
+			sizes->fb_height);
+
+out:
+	mutex_unlock(&dev->struct_mutex);
+	return ret;
+}
+
+static bool
+samsung_drm_fbdev_is_samefb(struct drm_framebuffer *fb,
+			    struct drm_fb_helper_surface_size *sizes)
+{
+	if (fb->width != sizes->surface_width)
+		return false;
+	if (fb->height != sizes->surface_height)
+		return false;
+	if (fb->bits_per_pixel != sizes->surface_bpp)
+		return false;
+	if (fb->depth != sizes->surface_depth)
+		return false;
+
+	return true;
+}
+
+static int samsung_drm_fbdev_recreate(struct drm_fb_helper *helper,
+				      struct drm_fb_helper_surface_size *sizes)
+{
+	struct drm_device *dev = helper->dev;
+	struct samsung_drm_fbdev *samsung_fbdev = to_samsung_fbdev(helper);
+	struct drm_framebuffer *fb = samsung_fbdev->fb;
+	struct drm_mode_fb_cmd mode_cmd = { 0 };
+
+	if (helper->fb != fb) {
+		DRM_ERROR("drm framebuffer is different\n");
+		return -EINVAL;
+	}
+
+	if (samsung_drm_fbdev_is_samefb(fb, sizes))
+		return 0;
+
+	mode_cmd.width = sizes->surface_width;
+	mode_cmd.height = sizes->surface_height;
+	mode_cmd.bpp = sizes->surface_bpp;
+	mode_cmd.depth = sizes->surface_depth;
+
+	if (fb->funcs->destroy)
+		fb->funcs->destroy(fb);
+
+	samsung_fbdev->fb = samsung_drm_fb_create(dev, NULL, &mode_cmd);
+	if (IS_ERR(samsung_fbdev->fb)) {
+		DRM_ERROR("failed to allocate fb.\n");
+		return PTR_ERR(samsung_fbdev->fb);
+	}
+
+	helper->fb = samsung_fbdev->fb;
+	samsung_drm_fbdev_update(helper, helper->fb, sizes->fb_width,
+			sizes->fb_height);
+
+	return 0;
+}
+
+static int samsung_drm_fbdev_probe(struct drm_fb_helper *helper,
+				   struct drm_fb_helper_surface_size *sizes)
+{
+	int ret = 0;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (!helper->fb) {
+		ret = samsung_drm_fbdev_create(helper, sizes);
+		if (ret < 0) {
+			DRM_ERROR("failed to create fbdev.\n");
+			return ret;
+		}
+
+		/*

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 257

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +10 -0
+		 * fb_helper expects a value more than 1 if succeed
+		 * because register_framebuffer() should be called.
+		 */
+		ret = 1;
+	} else {
+		ret = samsung_drm_fbdev_recreate(helper, sizes);
+		if (ret < 0) {
+			DRM_ERROR("failed to reconfigure fbdev\n");
+			return ret;
+		}

No need to do the same thing you did before?

ret = 1?

Quoted 24 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +24 -0
+	}
+
+	return ret;
+}
+
+static struct drm_fb_helper_funcs samsung_drm_fb_helper_funcs = {
+	.fb_probe =	samsung_drm_fbdev_probe,
+};
+
+int samsung_drm_fbdev_init(struct drm_device *dev)
+{
+	struct samsung_drm_fbdev *fbdev;
+	struct samsung_drm_private *private = dev->dev_private;
+	struct drm_fb_helper *helper;
+	unsigned int num_crtc;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (!dev->mode_config.num_crtc || !dev->mode_config.num_connector)
+		return 0;
+
+	fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
+	if (!fbdev) {

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 291

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +10 -0
+		DRM_ERROR("failed to allocate drm fbdev.\n");
+		return -ENOMEM;
+	}
+
+	private->fb_helper = helper = &fbdev->drm_fb_helper;
+	helper->funcs = &samsung_drm_fb_helper_funcs;
+
+	num_crtc = dev->mode_config.num_crtc;
+
+	ret = drm_fb_helper_init(dev, helper, num_crtc, 4);

Is that value '4'

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 304

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +13 -0
+	if (ret < 0) {
+		DRM_ERROR("failed to initialize drm fb helper.\n");
+		goto fail;
+	}
+
+	ret = drm_fb_helper_single_add_all_connectors(helper);
+	if (ret < 0) {
+		DRM_ERROR("failed to register drm_fb_helper_connector.\n");
+		goto fail;
+
+	}
+
+	ret = drm_fb_helper_initial_config(helper, 32);

and '32' should perhaps be in #defines?

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 306

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +2 -0
+	if (ret < 0) {
+		DRM_ERROR("failed to set up hw configuration.\n");

Which I think leaks memory. The drm_fb_helper_single_add_all_connectors does a bunch of kzallocs. Should you free them here?

Quoted 17 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +17 -0
+		goto fail;
+	}
+
+	return 0;
+
+fail:
+	private->fb_helper = NULL;
+	kfree(fbdev);
+
+	return ret;
+}
+
+static void samsung_drm_fbdev_destroy(struct drm_device *dev,
+				      struct drm_fb_helper *fb_helper)
+{
+	struct drm_framebuffer *fb;
+	struct fb_info *info;

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 333

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +10 -0
+
+	/* release drm framebuffer and real buffer */
+	if (fb_helper->fb && fb_helper->fb->funcs) {
+		fb = fb_helper->fb;
+		if (fb->funcs->destroy)
+			fb->funcs->destroy(fb);
+	}
+
+	/* release linux framebuffer */
+	if (fb_helper->fbdev) {

You can declare the 'info' here.

Quoted 53 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +53 -0
+		info = fb_helper->fbdev;
+		unregister_framebuffer(info);
+		if (info->cmap.len)
+			fb_dealloc_cmap(&info->cmap);
+		framebuffer_release(info);
+	}
+
+	drm_fb_helper_fini(fb_helper);
+}
+
+void samsung_drm_fbdev_fini(struct drm_device *dev)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+	struct samsung_drm_fbdev *fbdev;
+
+	if (!private || !private->fb_helper)
+		return;
+
+	fbdev = to_samsung_fbdev(private->fb_helper);
+
+	samsung_drm_fbdev_destroy(dev, private->fb_helper);
+	kfree(fbdev);
+	private->fb_helper = NULL;
+}
+
+void samsung_drm_fbdev_restore_mode(struct drm_device *dev)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+
+	if (!private || !private->fb_helper)
+		return;
+
+	drm_fb_helper_restore_fbdev_mode(private->fb_helper);
+}
+
+int samsung_drm_fbdev_reinit(struct drm_device *dev)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+	int ret;
+
+	if (!private)
+		return -EINVAL;
+
+	if (!dev->mode_config.num_connector) {
+		samsung_drm_fbdev_fini(dev);
+		return 0;
+	}
+
+	if (private->fb_helper) {
+		struct drm_fb_helper *fb_helper = private->fb_helper;
+
+		drm_fb_helper_fini(fb_helper);
+

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 396

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +10 -0
+		ret = drm_fb_helper_init(dev, fb_helper,
+				dev->mode_config.num_crtc, 4);
+		if (ret < 0) {
+			DRM_ERROR("failed to initialize drm fb helper\n");
+			return ret;
+		}
+
+		ret = drm_fb_helper_single_add_all_connectors(fb_helper);
+		if (ret < 0) {
+			DRM_ERROR("failed to add fb helper to connectors\n");

You should free what drm_fb_helper_init allocated

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 401

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +5 -0
+			return ret;
+		}
+
+		ret = drm_fb_helper_initial_config(fb_helper, 32);
+		if (ret < 0) {

.. and free what drm_fb_helper_single_add_all_connectors allocated too.

Quoted 59 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
+			DRM_ERROR("failed to set up hw configuration.\n");
+			return ret;
+		}
+	} else
+		ret = samsung_drm_fbdev_init(dev);
+
+	return ret;
+}
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +37 -0
new file mode 100644
index 0000000..3ef4e0d
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_FBDEV_H_
+#define _SAMSUNG_DRM_FBDEV_H_
+
+int samsung_drm_fbdev_init(struct drm_device *dev);
+int samsung_drm_fbdev_reinit(struct drm_device *dev);
+void samsung_drm_fbdev_fini(struct drm_device *dev);
+void samsung_drm_fbdev_restore_mode(struct drm_device *dev);
+
+#endif
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +2 -0
new file mode 100644
index 0000000..d823e19
@@ -0,0 +1,643 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics Co.Ltd

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 12

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+ * Authors:
+ *	Joonyoung Shim <[email protected]>
+ *	Inki Dae <[email protected]>
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ *
+ */

What is 'FIMD'? Is there an explanation of what that stands for?

Quoted 14 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +14 -0
+
+/*
+ * TODO list
+ *  - Code cleanup(FIXME and TODO parts)
+ *  - Clock gating and Power management
+ *  - Writeback feature
+ */
+
+#include "drmP.h"
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 36

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+
+#include <drm/samsung_drm.h>
+#include <plat/regs-fb-v4.h>
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_fbdev.h"
+#include "samsung_drm_crtc.h"
+
+/* irq_flags bits */
+#define FIMD_VSYNC_IRQ_EN	0

Which is just one value right? 0?

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 41

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +5 -0
+
+#define VIDOSD_A(win)	(VIDOSD_BASE + 0x00 + (win) * 16)
+#define VIDOSD_B(win)	(VIDOSD_BASE + 0x04 + (win) * 16)
+#define VIDOSD_C(win)	(VIDOSD_BASE + 0x08 + (win) * 16)
+#define VIDOSD_D(win)	(VIDOSD_BASE + 0x0C + (win) * 16)

What about a comment for these very important low-level values?

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +5 -0
+
+#define VIDWx_BUF_START(win, buf)	(VIDW_BUF_START(buf) + (win) * 8)
+#define VIDWx_BUF_END(win, buf)		(VIDW_BUF_END(buf) + (win) * 8)
+#define VIDWx_BUF_SIZE(win, buf)	(VIDW_BUF_SIZE(buf) + (win) * 4)
+

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 56

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+#define WINDOWS_NR	5
+
+#define get_fimd_context(dev)	platform_get_drvdata(to_platform_device(dev))
+
+struct fimd_win_data {
+	unsigned int		offset_x;
+	unsigned int		offset_y;
+	unsigned int		width;
+	unsigned int		height;
+	unsigned int		paddr;

dma_addr_t ?

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 58

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +2 -0
+	void __iomem		*vaddr;
+	unsigned int		end_buf_off;

buf_off ?

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 65

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +7 -0
+	unsigned int		buf_offsize;
+	unsigned int		line_size;	/* bytes */
+};
+
+struct fimd_context {
+	struct samsung_drm_subdrv	subdrv;
+	int				irq_no;

Just 'irq'

Quoted 68 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +68 -0
+	struct drm_crtc			*crtc;
+	struct clk			*bus_clk;
+	struct clk			*lcd_clk;
+	struct resource			*regs_res;
+	void __iomem			*regs;
+	struct fimd_win_data		win_data[WINDOWS_NR];
+	unsigned int			clkdiv;
+	unsigned int			default_win;
+	unsigned int			bpp;
+	unsigned long			irq_flags;
+	u32				vidcon0;
+	u32				vidcon1;
+
+	struct fb_videomode		*timing;
+};
+
+static bool fimd_display_is_connected(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+
+	/* TODO. */
+
+	return true;
+}
+
+static void *fimd_get_timing(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+
+	return ctx->timing;
+}
+
+static int fimd_check_timing(struct device *dev, void *timing)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+
+	/* TODO. */
+
+	return 0;
+}
+
+static int fimd_display_power_on(struct device *dev, int mode)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+
+	/* TODO. */
+
+	return 0;
+}
+
+static struct samsung_drm_display fimd_display = {
+	.type = SAMSUNG_DISPLAY_TYPE_LCD,
+	.is_connected = fimd_display_is_connected,
+	.get_timing = fimd_get_timing,
+	.check_timing = fimd_check_timing,
+	.power_on = fimd_display_power_on,
+};
+
+static void fimd_commit(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	struct fb_videomode *timing = ctx->timing;
+	u32 val;
+
+	/* vidcon0 */
+	val = ctx->vidcon0;
+	val &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 143

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+
+	if (ctx->clkdiv > 1)
+		val |= VIDCON0_CLKVAL_F(ctx->clkdiv - 1) | VIDCON0_CLKDIR;
+	else
+		val &= ~VIDCON0_CLKDIR;	/* 1:1 clock */
+
+	val |= VIDCON0_ENVID | VIDCON0_ENVID_F;
+	writel(val, regs + VIDCON0);
+
+	/* vidcon1 */

That comment is bit useless.. It is clear what you are doing.

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 146

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +3 -0
+	writel(ctx->vidcon1, regs + VIDCON1);
+
+	/* vidtcon0 */

Ah, so the order is important. Perhaps you should
just have a comment before you do any writes that
enumarates in which order it should be done?

And why the order is important (in case the future chipsets have it fixed/changed).

Quoted 128 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +128 -0
+	val = VIDTCON0_VBPD(timing->upper_margin - 1) |
+	       VIDTCON0_VFPD(timing->lower_margin - 1) |
+	       VIDTCON0_VSPW(timing->vsync_len - 1);
+	writel(val, regs + VIDTCON0);
+
+	/* vidtcon1 */
+	val = VIDTCON1_HBPD(timing->left_margin - 1) |
+	       VIDTCON1_HFPD(timing->right_margin - 1) |
+	       VIDTCON1_HSPW(timing->hsync_len - 1);
+	writel(val, regs + VIDTCON1);
+
+	/* vidtcon2 */
+	val = VIDTCON2_LINEVAL(timing->yres - 1) |
+	       VIDTCON2_HOZVAL(timing->xres - 1);
+	writel(val, regs + VIDTCON2);
+}
+
+static int fimd_enable_vblank(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	u32 val;
+
+	if (!test_and_set_bit(FIMD_VSYNC_IRQ_EN, &ctx->irq_flags)) {
+		val = readl(regs + VIDINTCON0);
+
+		val |= VIDINTCON0_INT_ENABLE;
+		val |= VIDINTCON0_INT_FRAME;
+
+		val &= ~VIDINTCON0_FRAMESEL0_MASK;
+		val |= VIDINTCON0_FRAMESEL0_VSYNC;
+		val &= ~VIDINTCON0_FRAMESEL1_MASK;
+		val |= VIDINTCON0_FRAMESEL1_NONE;
+
+		writel(val, regs + VIDINTCON0);
+	}
+
+	return 0;
+}
+
+static void fimd_disable_vblank(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	u32 val;
+
+	if (test_and_clear_bit(FIMD_VSYNC_IRQ_EN, &ctx->irq_flags)) {
+		val = readl(regs + VIDINTCON0);
+
+		val &= ~VIDINTCON0_INT_FRAME;
+		val &= ~VIDINTCON0_INT_ENABLE;
+
+		writel(val, regs + VIDINTCON0);
+	}
+}
+
+static struct samsung_drm_manager_ops fimd_manager_ops = {
+	.commit = fimd_commit,
+	.enable_vblank = fimd_enable_vblank,
+	.disable_vblank = fimd_disable_vblank,
+};
+
+static void fimd_win_mode_set(struct device *dev,
+			      struct samsung_drm_overlay *overlay)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	struct fimd_win_data *win_data;
+
+	if (!overlay) {
+		dev_err(dev, "overlay is NULL\n");
+		return;
+	}
+
+	win_data = &ctx->win_data[ctx->default_win];
+
+	win_data->offset_x = overlay->offset_x;
+	win_data->offset_y = overlay->offset_y;
+	win_data->width = overlay->width;
+	win_data->height = overlay->height;
+	win_data->paddr = overlay->paddr;
+	win_data->vaddr = overlay->vaddr;
+	win_data->end_buf_off = overlay->end_buf_off * (ctx->bpp >> 3);
+	win_data->buf_offsize = overlay->buf_offsize * (ctx->bpp >> 3);
+	win_data->line_size = overlay->line_size * (ctx->bpp >> 3);
+}
+
+static void fimd_win_commit(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	struct fimd_win_data *win_data;
+	int win = ctx->default_win;
+	u32 val;
+
+	if (win < 0 || win > WINDOWS_NR)
+		return;
+
+	win_data = &ctx->win_data[win];
+
+	/* protect windows */
+	val = readl(regs + SHADOWCON);
+	val |= SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+
+	/* buffer start address */
+	val = win_data->paddr;
+	writel(val, regs + VIDWx_BUF_START(win, 0));
+
+	/* buffer end address */
+	val = win_data->paddr + win_data->end_buf_off;
+	writel(val, regs + VIDWx_BUF_END(win, 0));
+
+	/* buffer size */
+	val = VIDW_BUF_SIZE_OFFSET(win_data->buf_offsize) |
+		VIDW_BUF_SIZE_PAGEWIDTH(win_data->line_size);
+	writel(val, regs + VIDWx_BUF_SIZE(win, 0));
+
+	/* OSD position */
+	val = VIDOSDxA_TOPLEFT_X(win_data->offset_x) |
+		VIDOSDxA_TOPLEFT_Y(win_data->offset_y);
+	writel(val, regs + VIDOSD_A(win));
+
+	val = VIDOSDxB_BOTRIGHT_X(win_data->offset_x + win_data->width - 1) |
+		VIDOSDxB_BOTRIGHT_Y(win_data->offset_y + win_data->height - 1);
+	writel(val, regs + VIDOSD_B(win));
+
+	/* TODO: OSD alpha */
+

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 284

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+	/* OSD size */
+	if (win != 3 && win != 4) {
+		u32 offset = VIDOSD_D(win);
+		if (win == 0)
+			offset = VIDOSD_C(win);
+		val = win_data->width * win_data->height;
+		writel(val, regs + offset);
+	}
+
+	/* FIXME: remove fixed values */

<nods> Yes.

Quoted 66 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +66 -0
+	val = WINCONx_ENWIN;
+	val |= WINCON0_BPPMODE_24BPP_888;
+	val |= WINCONx_WSWP;
+	val |= WINCONx_BURSTLEN_16WORD;
+	writel(val, regs + WINCON(win));
+
+	/* TODO: colour key */
+
+	/* Enable DMA channel and unprotect windows */
+	val = readl(regs + SHADOWCON);
+	val |= SHADOWCON_CHx_ENABLE(win);
+	val &= ~SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+}
+
+static void fimd_win_disable(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	struct fimd_win_data *win_data;
+	int win = ctx->default_win;
+	u32 val;
+
+	if (win < 0 || win > WINDOWS_NR)
+		return;
+
+	win_data = &ctx->win_data[win];
+
+	/* protect windows */
+	val = readl(regs + SHADOWCON);
+	val |= SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+
+	/* wincon */
+	val = readl(regs + WINCON(win));
+	val &= ~WINCONx_ENWIN;
+	writel(val, regs + WINCON(win));
+
+	/* unprotect windows */
+	val = readl(regs + SHADOWCON);
+	val &= ~SHADOWCON_CHx_ENABLE(win);
+	val &= ~SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+}
+
+static struct samsung_drm_overlay_ops fimd_overlay_ops = {
+	.mode_set = fimd_win_mode_set,
+	.commit = fimd_win_commit,
+	.disable = fimd_win_disable,
+};
+
+/* for pageflip event */
+static void fimd_finish_pageflip(struct drm_device *drm_dev, int crtc)
+{
+	struct samsung_drm_private *dev_priv = drm_dev->dev_private;
+	struct drm_pending_vblank_event *e, *t;
+	struct timeval now;
+	unsigned long flags;
+
+	if (!dev_priv->pageflip_event)
+		return;
+
+	spin_lock_irqsave(&drm_dev->event_lock, flags);
+
+	list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list,
+			base.link) {

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 360

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+		do_gettimeofday(&now);
+		e->event.sequence = 0;
+		e->event.tv_sec = now.tv_sec;
+		e->event.tv_usec = now.tv_usec;
+
+		list_move_tail(&e->base.link, &e->base.file_priv->event_list);
+		wake_up_interruptible(&e->base.file_priv->event_wait);
+	}
+
+	drm_vblank_put(drm_dev, crtc);

You can make this call outside the spinlock. But it looks like pretty much everybody is doing it this way?

Quoted 22 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +22 -0
+	dev_priv->pageflip_event = false;
+
+	spin_unlock_irqrestore(&drm_dev->event_lock, flags);
+}
+
+static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
+{
+	struct fimd_context *ctx = (struct fimd_context *)dev_id;
+	struct samsung_drm_subdrv *subdrv = &ctx->subdrv;
+	struct drm_device *drm_dev = subdrv->drm_dev;
+	struct device *dev = subdrv->manager.dev;
+	struct samsung_drm_manager *manager = &subdrv->manager;
+	void __iomem *regs = ctx->regs;
+	u32 val;
+
+	val = readl(regs + VIDINTCON1);
+
+	if (val & VIDINTCON1_INT_FRAME)
+		/* VSYNC interrupt */
+		writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
+
+	drm_handle_vblank(drm_dev, manager->pipe);

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 392

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+	fimd_finish_pageflip(drm_dev, manager->pipe);
+
+	return IRQ_HANDLED;
+}
+
+static int fimd_subdrv_probe(struct drm_device *drm_dev)
+{
+	struct drm_driver *drm_driver = drm_dev->driver;
+
+	drm_dev->irq_enabled = 1;

Hehe.. Just like that ,eh?

Quoted 40 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +40 -0
+
+	/* TODO. */
+
+	/* FIXME */
+	drm_dev->vblank_disable_allowed = 1;
+
+	return 0;
+}
+
+static void fimd_subdrv_remove(struct drm_device *drm_dev)
+{
+	struct drm_driver *drm_driver = drm_dev->driver;
+
+	/* TODO. */
+}
+
+static int fimd_calc_clkdiv(struct fimd_context *ctx,
+			    struct fb_videomode *timing)
+{
+	unsigned long clk = clk_get_rate(ctx->lcd_clk);
+	u32 retrace;
+	u32 clkdiv;
+	u32 best_framerate = 0;
+	u32 framerate;
+
+	retrace = timing->left_margin + timing->hsync_len +
+				timing->right_margin + timing->xres;
+	retrace *= timing->upper_margin + timing->vsync_len +
+				timing->lower_margin + timing->yres;
+
+	/* default framerate is 60Hz */
+	if (!timing->refresh)
+		timing->refresh = 60;
+
+	clk /= retrace;
+
+	for (clkdiv = 1; clkdiv < 0x100; clkdiv++) {
+		int tmp;
+
+		/* get best framerate */

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 442

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+		framerate = clk / clkdiv;
+		tmp = timing->refresh - framerate;
+		if (tmp < 0) {
+			best_framerate = framerate;
+			continue;
+		} else {
+			if (!best_framerate)
+				best_framerate = framerate;
+			else if (tmp < (best_framerate - framerate))
+				best_framerate = framerate ;

The ';' at the end should be moved.

Quoted 27 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +27 -0
+			break;
+		}
+	}
+
+	return clkdiv;
+}
+
+static void fimd_clear_win(struct fimd_context *ctx, int win)
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 460

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+{
+	void __iomem *regs = ctx->regs;
+	u32 val;
+
+	writel(0, regs + WINCON(win));
+	writel(0, regs + VIDOSD_A(win));
+	writel(0, regs + VIDOSD_B(win));
+	writel(0, regs + VIDOSD_C(win));
+
+	if (win == 1 || win == 2)
[… more lines in the raw message]

Hm printk? Use pr_dbg instead.

drivers/gpu/drm/samsung/samsung_drm_fimd.c

Quoted 130 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +130 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

free_irq ?

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 287 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +34 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/samsung/samsung_drm_gem.c new file +247 -0
new file mode 100644
index 0000000..8f71ef0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Um, You can make that error read better. Perhaps

drv_err(dev->dev,"Does not support GEM.\n");

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 29 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +29 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

So .. you can't continue by just using the real size instead?

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You can drop those u32 and use %lx

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Perhaps also include more details. Say the PFN in question, the offset, etc. Something that will help in the field?

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 21 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Ditto.

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 25 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +25 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Is all this casting to (u32) that neccessary?

drivers/gpu/drm/samsung/samsung_drm_gem.h

Quoted 200 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +158 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/samsung/samsung_drm_gem.h new file +36 -0
new file mode 100644
index 0000000..c6cd5e5

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Hm, that sounds like an enum? Or a candidate for enums?

drivers/gpu/drm/samsung/samsung_drm_gem.h

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You are missing @base

drivers/gpu/drm/samsung/samsung_drm_gem.h

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

It is 'P.S.'

drivers/gpu/drm/samsung/samsung_drm_gem.h

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Actually, I don't think you are using this? Could it be chopped off?

include/drm/samsung_drm.h

Quoted 101 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +53 -0

Lines of this file are not shown. View the raw message.

include/drm/samsung_drm.h new file +42 -0
new file mode 100644
index 0000000..5f89cf1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You can deleta that space.

include/drm/samsung_drm.h

Quoted 29 lines
include/drm/samsung_drm.h new file +29 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Ditto

Quoted 34 lines
include/drm/samsung_drm.h new file +32 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.0.4

Part of the diff is not shown here. View the raw message.

author
#17 lore raw

Hello, Konrad Rzeszutek Wilk.

Your review and comments are so very detail. it was very helpful. thank you again.

Quoted 51 lines

-----Original Message-----
From: Konrad Rzeszutek Wilk [mailto:[email protected]]
Sent: Thursday, September 15, 2011 6:42 AM
To: Inki Dae
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux-arm- [email protected]
Subject: Re: [PATCH v4] DRM: add DRM Driver for Samsung SoC EXYNOS4210.

Quoted 4 lines · Inki Dae

This patch is a DRM Driver for Samsung SoC Exynos4210 and now enables only FIMD yet but we will add HDMI support also in the future.

from now on, I will remove RFC prefix because I think we have got

comments

Quoted 7 lines

enough.

this patch is based on git repository below:
git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git,
branch name: drm-next
commit-id: bcc65fd8e929a9d9d34d814d6efc1d2793546922

Quoted 7 lines

you can refer to our working repository below:
http://git.infradead.org/users/kmpark/linux-2.6-samsung
branch name: samsung-drm

We tried to re-use lowlevel codes of the FIMD driver(s3c-fb.c based on Linux framebuffer) but couldn't so because lowlevel codes of s3c-fb.c are included internally and so FIMD module of this driver

has

Quoted 21 lines

its own lowlevel codes.

We used GEM framework for buffer management and DMA APIs(dma_alloc_*) for buffer allocation. by using DMA API, we could use CMA later.

Refer to this link for CMA(Continuous Memory Allocator):
http://lkml.org/lkml/2011/7/20/45

this driver supports only physically continuous memory(non-iommu).

Links to previous versions of the patchset:
v1: < https://lwn.net/Articles/454380/ >
v2: < http://www.spinics.net/lists/kernel/msg1224275.html >
v3: < http://www.gossamer-threads.com/lists/linux/kernel/1423684 >

Changelog v2:
DRM: add DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl command.

this feature maps user address space to physical memory region once user application requests DRM_IOCTL_SAMSUNG_GEM_MMAP ioctl.

Quoted 8 lines
Quoted 6 lines

DRM: code clean and add exception codes.

Changelog v3:
DRM: Support multiple irq.

FIMD and HDMI have their own irq handler but DRM Framework can

regiter

Quoted 1 line

only one irq handler this patch supports mutiple irq for Samsung

SoC.

Quoted 67 lines
Quoted 18 lines

DRM: Consider modularization.

each DRM, FIMD could be built as a module.

DRM: Have indenpendent crtc object.

crtc isn't specific to SoC Platform so this patch gets a crtc to be used as common object.
created crtc could be attached to any encoder object.

DRM: code clean and add exception codes.

Changelog v4:
DRM: remove is_defult from samsung_fb.

is_default isn't used for default framebuffer.

Quoted 8 lines

DRM: code refactoring to fimd module.
this patch is be considered with multiple display objects and would use its own request_irq() to register a irq handler instead of drm framework's one.

DRM: remove find_samsung_drm_gem_object()

DRM: move kernel private data structures and definitions to driver

folder.

Quoted 32 lines

samsung_drm.h would contain only public information for userspace ioctl interface.

DRM: code refactoring to gem modules.
buffer module isn't dependent of gem module anymore.

DRM: fixed security issue.

DRM: remove encoder porinter from specific connector.

samsung connector doesn't need to have generic encoder.

DRM: code clean and add exception codes.

---
 drivers/gpu/drm/Kconfig                         |    2 +
 drivers/gpu/drm/Makefile                        |    1 +
 drivers/gpu/drm/samsung/Kconfig                 |   18 +
 drivers/gpu/drm/samsung/Makefile                |   11 +
 drivers/gpu/drm/samsung/samsung_drm_buf.c       |  109 ++++
 drivers/gpu/drm/samsung/samsung_drm_buf.h       |   50 ++
 drivers/gpu/drm/samsung/samsung_drm_connector.c |  257 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_connector.h |   34 ++
 drivers/gpu/drm/samsung/samsung_drm_core.c      |  213 ++++++++
 drivers/gpu/drm/samsung/samsung_drm_crtc.c      |  329 ++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_crtc.h      |   38 ++
 drivers/gpu/drm/samsung/samsung_drm_drv.c       |  215 ++++++++
Quoted 8 lines
 drivers/gpu/drm/samsung/samsung_drm_drv.h       |  194 +++++++
 drivers/gpu/drm/samsung/samsung_drm_encoder.c   |  261 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_encoder.h   |   45 ++
 drivers/gpu/drm/samsung/samsung_drm_fb.c        |  262 +++++++++
 drivers/gpu/drm/samsung/samsung_drm_fb.h        |   47 ++
 drivers/gpu/drm/samsung/samsung_drm_fbdev.c     |  409 ++++++++++++++
 drivers/gpu/drm/samsung/samsung_drm_fbdev.h     |   37 ++
 drivers/gpu/drm/samsung/samsung_drm_fimd.c      |  643
Quoted 2 lines

+++++++++++++++++++++++

Quoted 1 line
 drivers/gpu/drm/samsung/samsung_drm_gem.c       |  492

+++++++++++++++++

Quoted 48 lines
Quoted 30 lines
 drivers/gpu/drm/samsung/samsung_drm_gem.h       |   98 ++++
 include/drm/samsung_drm.h                       |  103 ++++
 23 files changed, 3868 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpu/drm/samsung/Kconfig
 create mode 100644 drivers/gpu/drm/samsung/Makefile
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_buf.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_buf.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_connector.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_connector.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_core.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_crtc.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_crtc.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_drv.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_drv.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_encoder.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_encoder.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fb.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fb.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fbdev.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fbdev.h
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_fimd.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_gem.c
 create mode 100644 drivers/gpu/drm/samsung/samsung_drm_gem.h
 create mode 100644 include/drm/samsung_drm.h
drivers/gpu/drm/Kconfig +0 -0
index b493663..ce6d3ec 100644

drivers/gpu/drm/Kconfig config DRM_SAVAGE · line 159

Quoted 2 lines
drivers/gpu/drm/Kconfig +0 -0
@@ -158,3 +158,5 @@ config DRM_SAVAGE
 	help
 	  Choose this option if you have a

Savage3D/4/SuperSavage/Pro/Twister

Review

Quoted 14 lines
drivers/gpu/drm/Kconfig +2 -0
 	  chipset. If M is selected the module will be called savage.
+
+source "drivers/gpu/drm/samsung/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 89cf05a..0c6e773 100644
@@ -35,4 +35,5 @@ obj-$(CONFIG_DRM_SAVAGE)+= savage/
 obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
 obj-$(CONFIG_DRM_VIA)	+=via/
 obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
+obj-$(CONFIG_DRM_SAMSUNG) +=samsung/
 obj-y			+= i2c/
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/Kconfig

Quoted 17 lines

drivers/gpu/drm/samsung/Kconfig line 8

Quoted 13 lines

new file mode 100644
index 0000000..34cedda

drivers/gpu/drm/samsung/Kconfig new file +8 -0
@@ -0,0 +1,18 @@
+config DRM_SAMSUNG
+	tristate "DRM Support for Samsung SoC EXYNOS Series"
+	depends on DRM && PLAT_SAMSUNG
+	select DRM_KMS_HELPER
+	select FB_CFB_FILLRECT
+	select FB_CFB_COPYAREA
+	select FB_CFB_IMAGEBLIT
+	select VT_HW_CONSOLE_BINDING if FRAMEBUFFER_CONSOLE

You should probably have
default n

Thank you.

Quoted 9 lines

drivers/gpu/drm/samsung/Kconfig line 15

Quoted 7 lines
drivers/gpu/drm/samsung/Kconfig new file +7 -0
+	help
+	  Choose this option if you have a Samsung SoC EXYNOS chipset.
+	  If M is selected the module will be called samsungdrm.
+
+config DRM_SAMSUNG_FIMD
+	tristate "Samsung DRM FIMD"
+	depends on DRM_SAMSUNG

And here too.

Thank you.

Quoted 13 lines

Review

Quoted 4 lines
drivers/gpu/drm/samsung/Kconfig new file +3 -0
+	help
+	  Choose this option if you want to use Samsung FIMD for DRM.
+	  If M is selected, the module will be called samsung_drm_fimd
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/Makefile

drivers/gpu/drm/samsung/Makefile line 2

Quoted 7 lines

new file mode 100644
index 0000000..70f89f3

drivers/gpu/drm/samsung/Makefile new file +2 -0
@@ -0,0 +1,11 @@
+#
+# Makefile for the drm device driver.  This driver provides support for

the

Quoted 5 lines

drivers/gpu/drm/samsung/Makefile line 3

Quoted 1 line
drivers/gpu/drm/samsung/Makefile new file +1 -0
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.

4.1.0? Really? I mean did you actually test this with 4.1.0? Or have you been using the Xorg instead?

Yes, we tested on DRI of Xorg and also in progress. that is a linux platform and would be opened in the future.

Quoted 40 lines

drivers/gpu/drm/samsung/Makefile

Quoted 3 lines
drivers/gpu/drm/samsung/Makefile new file +3 -0
+
+ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/samsung
+samsungdrm-y := samsung_drm_drv.o samsung_drm_encoder.o

samsung_drm_connector.o \

Review

Quoted 6 lines
drivers/gpu/drm/samsung/Makefile new file +5 -0
+		samsung_drm_crtc.o samsung_drm_fbdev.o samsung_drm_fb.o \
+		samsung_drm_buf.o samsung_drm_gem.o samsung_drm_core.o
+
+obj-$(CONFIG_DRM_SAMSUNG) += samsungdrm.o
+obj-$(CONFIG_DRM_SAMSUNG_FIMD) += samsung_drm_fimd.o
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_buf.c

drivers/gpu/drm/samsung/samsung_drm_buf.c line 6

Quoted 11 lines

new file mode 100644
index 0000000..46cc673

drivers/gpu/drm/samsung/samsung_drm_buf.c new file +6 -0
@@ -0,0 +1,109 @@
+/* samsung_drm_buf.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Author: Inki Dae <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_buf.c line 7

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_buf.c line 8

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_buf.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_buf.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_buf.c

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_buf.c line 14

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_buf.c

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_buf.c line 18

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_buf.c line 19

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_buf.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 15 lines

drivers/gpu/drm/samsung/samsung_drm_buf.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_buf.c line 32

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +10 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_buf.h"
+
+static DEFINE_MUTEX(samsung_drm_buf_lock);

Why the prefix 'samsung_'?

As I mentioned to Dave before, Samsung SoCs have a variety of prefixes such as s3c24xx, s3c64xx, s3c, s5p, s5pv210(=s5pc110) and exynos4210(=s5pc210, =s5pv310). Except old SoCs, our drm driver would support only exynos4210 and later. So we used samsung_ as prefix to represent them. and samsung prefix already is being used at mainline.

You can refer to this link:
http://www.spinics.net/lists/dri-devel/msg13827.html

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +7 -0
+
+static int lowlevel_buffer_allocate(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	entry->vaddr = dma_alloc_writecombine(dev->dev, entry->size,
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_buf.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +8 -0
+			(dma_addr_t *)&entry->paddr, GFP_KERNEL);
+	if (!entry->paddr) {
+		DRM_ERROR("failed to allocate buffer.\n");
+		return -ENOMEM;
+	}
+
+	DRM_DEBUG_KMS("allocated : vaddr(0x%x), paddr(0x%x), size(0x%x)\n",
+			(unsigned int)entry->vaddr, entry->paddr,

entry->size);

Quoted 14 lines

drivers/gpu/drm/samsung/samsung_drm_buf.c

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +13 -0
+
+	return 0;
+}
+
+static void lowlevel_buffer_deallocate(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry)
+{
+	DRM_DEBUG_KMS("%s.\n", __FILE__);
+
+	dma_free_writecombine(dev->dev, entry->size, entry->vaddr,
+			entry->paddr);
+
+	DRM_DEBUG_KMS("deallocated : vaddr(0x%x), paddr(0x%x),

size(0x%x)\n",

Quoted 1 line

drivers/gpu/drm/samsung/samsung_drm_buf.c line 61

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +1 -0
+			(unsigned int)entry->vaddr, entry->paddr,

entry->size);

Quoted 41 lines

drivers/gpu/drm/samsung/samsung_drm_buf.c

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +13 -0
+}
+
+static void  samsung_drm_buf_del(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry)
+{
+	DRM_DEBUG_KMS("%s.\n", __FILE__);
+
+	lowlevel_buffer_deallocate(dev, entry);
+
+	kfree(entry);
+}
+
+struct samsung_drm_buf_entry *samsung_drm_buf_create(struct drm_device

*dev,

Quoted 27 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +26 -0
+		unsigned int size)
 
+{
+	struct samsung_drm_buf_entry *entry;
+
+	DRM_DEBUG_KMS("%s.\n", __FILE__);
+	DRM_DEBUG_KMS("desired size = 0x%x\n", size);
+
+	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+	if (!entry) {
+		DRM_ERROR("failed to allocate samsung_drm_buf_entry.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	entry->size = size;
+
+	/* allocate memory region and set it to vaddr and paddr. */
+	if (lowlevel_buffer_allocate(dev, entry) < 0) {
+		kfree(entry);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	return entry;
+}
+
+void samsung_drm_buf_destroy(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry)
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_buf.c line 104

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +4 -0
+{
+	DRM_DEBUG_KMS("%s.\n", __FILE__);
+
+	samsung_drm_buf_del(dev, entry);

Why not stick the contents of samsung_drm_buf_del in here? This function looks to be the only one calling it.

Your saying is more clean. Thank you.

Quoted 36 lines

Review

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_buf.c new file +5 -0
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");
+MODULE_DESCRIPTION("Samsung SoC DRM Buffer Management Module");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_buf.h

drivers/gpu/drm/samsung/samsung_drm_buf.h line 6

Quoted 11 lines

new file mode 100644
index 0000000..b6d7393

drivers/gpu/drm/samsung/samsung_drm_buf.h new file +6 -0
@@ -0,0 +1,50 @@
+/* samsung_drm_buf.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Author: Inki Dae <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_buf.h line 7

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_buf.h line 8

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_buf.h line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_buf.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_buf.h line 13

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_buf.h line 14

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_buf.h line 17

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_buf.h line 18

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_buf.h line 19

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_buf.h line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 64 lines

drivers/gpu/drm/samsung/samsung_drm_buf.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +11 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_BUF_H_
+#define _SAMSUNG_DRM_BUF_H_
+
+/**
+ * samsung drm buffer entry structure.
+ *
+ * @paddr: physical address of allocated memory.
+ * @vaddr: kernel virtual address of allocated memory.

drivers/gpu/drm/samsung/samsung_drm_buf.h

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +10 -0
+ * @size: size of allocated memory.
+ */
+struct samsung_drm_buf_entry {
+	dma_addr_t paddr;
+	void __iomem *vaddr;
+	unsigned int size;
+};
+
+/* allocate physical memory. */
+struct samsung_drm_buf_entry *samsung_drm_buf_create(struct drm_device

*dev,

Review

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_buf.h new file +7 -0
+		unsigned int size);
+
+/* remove allocated physical memory. */
+void samsung_drm_buf_destroy(struct drm_device *dev,
+		struct samsung_drm_buf_entry *entry);
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_connector.c

drivers/gpu/drm/samsung/samsung_drm_connector.c line 8

Quoted 13 lines

new file mode 100644
index 0000000..cf457c0

drivers/gpu/drm/samsung/samsung_drm_connector.c new file +8 -0
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_connector.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_connector.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_connector.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_connector.c line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_connector.c line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_connector.c line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_connector.c line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_connector.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_connector.c line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_connector.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 89 lines

drivers/gpu/drm/samsung/samsung_drm_connector.c line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +11 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_encoder.h"
+
+#define MAX_EDID 256
+#define to_samsung_connector(x)	container_of(x, struct

samsung_drm_connector,\

Quoted 39 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +39 -0
+				drm_connector)
+
+struct samsung_drm_connector {
+	struct drm_connector	drm_connector;
+
+	/* add hardware specific callbacks or data structure. */
+};
+
+/* convert samsung_video_timings to drm_display_mode */
+static inline void
+convert_to_display_mode(struct drm_display_mode *mode,
+			struct fb_videomode *timing)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode->clock = timing->pixclock / 1000;
+
+	mode->hdisplay = timing->xres;
+	mode->hsync_start = mode->hdisplay + timing->left_margin;
+	mode->hsync_end = mode->hsync_start + timing->hsync_len;
+	mode->htotal = mode->hsync_end + timing->right_margin;
+
+	mode->vdisplay = timing->yres;
+	mode->vsync_start = mode->vdisplay + timing->upper_margin;
+	mode->vsync_end = mode->vsync_start + timing->vsync_len;
+	mode->vtotal = mode->vsync_end + timing->lower_margin;
+}
+
+/* convert drm_display_mode to samsung_video_timings */
+static inline void
+convert_to_video_timing(struct fb_videomode *timing,
+			struct drm_display_mode *mode)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	timing->pixclock = mode->clock * 1000;
+
+	timing->xres = mode->hdisplay;
+	timing->left_margin = mode->hsync_start - mode->hdisplay;

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+	timing->hsync_len = mode->hsync_end - mode->hsync_start;
+	timing->right_margin = mode->htotal - mode->hsync_end;
+
+	timing->yres = mode->vdisplay;
+	timing->upper_margin = mode->vsync_start - mode->vdisplay;
+	timing->vsync_len = mode->vsync_end - mode->vsync_start;
+	timing->lower_margin = mode->vtotal - mode->vsync_end;
+}
+
+static int samsung_drm_connector_get_modes(struct drm_connector

*connector)

Quoted 25 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +24 -0
+{
+	struct samsung_drm_manager *manager =
+				samsung_drm_get_manager(connector->encoder);
+	struct samsung_drm_display *display = manager->display;
+	unsigned int count;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (display && display->get_edid) {
+		void *edid = kzalloc(MAX_EDID, GFP_KERNEL);
+		if (!edid) {
+			DRM_ERROR("failed to allocate edid\n");
+			return 0;
+		}
+
+		display->get_edid(manager->dev, connector, edid, MAX_EDID);
+
+		drm_mode_connector_update_edid_property(connector, edid);
+		count = drm_add_edid_modes(connector, edid);
+
+		kfree(connector->display_info.raw_edid);
+		connector->display_info.raw_edid = edid;
+	} else {
+		struct drm_display_mode *mode = drm_mode_create(connector-

dev);

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_connector.c line 114

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +6 -0
+		struct fb_videomode *timing;
+
+		if (display && display->get_timing)
+			timing = display->get_timing(manager->dev);
+		else
+			return 0;

and memory leak. The 'mode' is still allocated.

I will release mode object properly. Thank you.

Quoted 93 lines
Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +4 -0
+
+		convert_to_display_mode(mode, timing);
+
+		mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+		drm_mode_set_name(mode);
+		drm_mode_probed_add(connector, mode);
+
+		count = 1;
+	}
+
+	return count;
+}
+
+static int samsung_drm_connector_mode_valid(struct drm_connector

*connector,

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+					    struct drm_display_mode *mode)
+{
+	struct samsung_drm_manager *manager =
+				samsung_drm_get_manager(connector->encoder);
+	struct samsung_drm_display *display = manager->display;
+	struct fb_videomode timing;
+	int ret = MODE_BAD;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+	convert_to_video_timing(&timing, mode);
+
+	if (display && display->check_timing)
+		if (!display->check_timing(manager->dev, (void *)&timing))
+			ret = MODE_OK;
+
+	return ret;
+}
+
+struct drm_encoder *samsung_drm_best_encoder(struct drm_connector

*connector)

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +7 -0
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return connector->encoder;
+}
+
+static struct drm_connector_helper_funcs samsung_connector_helper_funcs

= {

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +8 -0
+	.get_modes	= samsung_drm_connector_get_modes,
+	.mode_valid	= samsung_drm_connector_mode_valid,
+	.best_encoder	= samsung_drm_best_encoder,
+};
+
+/* get detection status of display device. */
+static enum drm_connector_status
+samsung_drm_connector_detect(struct drm_connector *connector, bool

force)

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +9 -0
+{
+	struct samsung_drm_manager *manager =
+				samsung_drm_get_manager(connector->encoder);
+	struct samsung_drm_display *display = manager->display;
+	enum drm_connector_status status = connector_status_disconnected;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (display && display->is_connected) {

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+		if (display->is_connected(manager->dev))
+			status = connector_status_connected;
+		else
+			status = connector_status_disconnected;
+	}
+
+	return status;
+}
+
+static void samsung_drm_connector_destroy(struct drm_connector

*connector)

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +9 -0
+{
+	struct samsung_drm_connector *samsung_connector =
+		to_samsung_connector(connector);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	drm_sysfs_connector_remove(connector);
+	drm_connector_cleanup(connector);
+	kfree(samsung_connector);

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+}
+
+static struct drm_connector_funcs samsung_connector_funcs = {
+	.dpms		= drm_helper_connector_dpms,
+	.fill_modes	= drm_helper_probe_single_connector_modes,
+	.detect		= samsung_drm_connector_detect,
+	.destroy	= samsung_drm_connector_destroy,
+};
+
+struct drm_connector *samsung_drm_connector_create(struct drm_device

*dev,

Quoted 1 line

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +1 -0
+						   struct drm_encoder

*encoder)

Quoted 49 lines

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +3 -0
+{
+	struct samsung_drm_connector *samsung_connector;
+	struct samsung_drm_manager *manager =

samsung_drm_get_manager(encoder);

Quoted 15 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +15 -0
+	struct drm_connector *connector;
+	int type;
+	int err;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_connector = kzalloc(sizeof(*samsung_connector), GFP_KERNEL);
+	if (!samsung_connector) {
+		DRM_ERROR("failed to allocate connector\n");
+		return NULL;
+	}
+
+	connector = &samsung_connector->drm_connector;
+
+	switch (manager->display->type) {

drivers/gpu/drm/samsung/samsung_drm_connector.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +10 -0
+	case SAMSUNG_DISPLAY_TYPE_HDMI:
+		type = DRM_MODE_CONNECTOR_HDMIA;
+		break;
+	default:
+		type = DRM_MODE_CONNECTOR_Unknown;
+		break;
+	}
+
+	drm_connector_init(dev, connector, &samsung_connector_funcs, type);
+	drm_connector_helper_add(connector,

&samsung_connector_helper_funcs);

Quoted 19 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +19 -0
+
+	err = drm_sysfs_connector_add(connector);
+	if (err)
+		goto err_connector;
+
+	connector->encoder = encoder;
+	err = drm_mode_connector_attach_encoder(connector, encoder);
+	if (err) {
+		DRM_ERROR("failed to attach a connector to a encoder\n");
+		goto err_sysfs;
+	}
+
+	DRM_DEBUG_KMS("connector has been created\n");
+
+	return connector;
+
+err_sysfs:
+	drm_sysfs_connector_remove(connector);
+err_connector:
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_connector.c line 255

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +6 -0
+	drm_connector_cleanup(connector);
+	kfree(samsung_connector);
+	return NULL;
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");

Should you also include the rest of the authors?

You are right. I missed it. thank you.

Quoted 35 lines

Review

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_connector.c new file +2 -0
+MODULE_DESCRIPTION("Samsung SoC DRM Connector Driver");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_connector.h

drivers/gpu/drm/samsung/samsung_drm_connector.h line 8

Quoted 13 lines

new file mode 100644
index 0000000..638d2b3

drivers/gpu/drm/samsung/samsung_drm_connector.h new file +8 -0
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_connector.h line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_connector.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_connector.h line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_connector.h line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_connector.h line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_connector.h line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_connector.h line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_connector.h line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_connector.h line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_connector.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 11 lines

drivers/gpu/drm/samsung/samsung_drm_connector.h line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_connector.h

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +7 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_CONNECTOR_H_
+#define _SAMSUNG_DRM_CONNECTOR_H_
+
+struct drm_connector *samsung_drm_connector_create(struct drm_device

*dev,

drivers/gpu/drm/samsung/samsung_drm_connector.h line 32

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +1 -0
+						   struct drm_encoder

*encoder);

Quoted 34 lines

Review

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_connector.h new file +2 -0
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_core.c

drivers/gpu/drm/samsung/samsung_drm_core.c line 7

Quoted 12 lines

new file mode 100644
index 0000000..752c94c

drivers/gpu/drm/samsung/samsung_drm_core.c new file +7 -0
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Author:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_core.c line 8

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_core.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_core.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_core.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_core.c line 14

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_core.c line 15

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_core.c line 18

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_core.c line 19

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_core.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_core.c line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 14 lines

drivers/gpu/drm/samsung/samsung_drm_core.c line 23

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_core.c line 32

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +9 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "samsung_drm_drv.h"
+#include "samsung_drm_encoder.h"
+#include "samsung_drm_connector.h"
+#include "samsung_drm_fbdev.h"
+

Please explain what the mutex protects.

Ok, get it. thank you.

Quoted 21 lines

drivers/gpu/drm/samsung/samsung_drm_core.c line 35

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +3 -0
+static DEFINE_MUTEX(samsung_drm_mutex);
+static LIST_HEAD(samsung_drm_subdrv_list);
+static struct drm_device *drm_dev;

No locking for it? I guess there is not much sense. Would it be possible to have multiple of those - so owuld have to make this an array or list..

drivers/gpu/drm/samsung/samsung_drm_core.c line 44

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +9 -0
+
+static int samsung_drm_subdrv_probe(struct drm_device *dev,
+					struct samsung_drm_subdrv *subdrv)
+{
+	struct drm_encoder *encoder;
+	struct drm_connector *connector;
+	int ret;
+
+	if (subdrv->probe) {

You might as well decleare 'int ret' here.. since you are only using it within this code path.

Quoted 5 lines

drivers/gpu/drm/samsung/samsung_drm_core.c line 49

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +5 -0
+		ret = subdrv->probe(dev);
+		if (ret)
+			return ret;
+	}
+

Thank you.

Quoted 65 lines
Quoted 45 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +45 -0
+	/* all crtc is available */
+	encoder = samsung_drm_encoder_create(dev, &subdrv->manager,
+			(1 << MAX_CRTC) - 1);
+	if (!encoder) {
+		DRM_ERROR("failed to create encoder\n");
+		return -EFAULT;
+	}
+
+	connector = samsung_drm_connector_create(dev, encoder);
+	if (!connector) {
+		DRM_ERROR("failed to create connector\n");
+		encoder->funcs->destroy(encoder);
+		return -EFAULT;
+	}
+
+	subdrv->encoder = encoder;
+	subdrv->connector = connector;
+
+	return 0;
+}
+
+static void samsung_drm_subdrv_remove(struct drm_device *dev,
+				      struct samsung_drm_subdrv *subdrv)
+{
+	if (subdrv->remove)
+		subdrv->remove(dev);
+
+	if (subdrv->encoder) {
+		struct drm_encoder *encoder = subdrv->encoder;
+		encoder->funcs->destroy(encoder);
+		subdrv->encoder = NULL;
+	}
+
+	if (subdrv->connector) {
+		struct drm_connector *connector = subdrv->connector;
+		connector->funcs->destroy(connector);
+		subdrv->connector = NULL;
+	}
+}
+
+int samsung_drm_device_register(struct drm_device *dev)
+{
+	struct samsung_drm_subdrv *subdrv, *n;
+	int err;
+

drivers/gpu/drm/samsung/samsung_drm_core.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+	if (!dev)
+		return -EINVAL;
+
+	if (drm_dev) {
+		DRM_ERROR("Already drm device were registered\n");
+		return -EBUSY;
+	}
+
+	mutex_lock(&samsung_drm_mutex);
+	list_for_each_entry_safe(subdrv, n, &samsung_drm_subdrv_list, list)

{

drivers/gpu/drm/samsung/samsung_drm_core.c line 108

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +4 -0
+		err = samsung_drm_subdrv_probe(dev, subdrv);
+		if (err) {
+			DRM_ERROR("samsung drm subdrv probe failed\n");
+			list_del(&subdrv->list);

Ok, so you continue on. If that is OK and you can live with, should you remove the DRM_ERROR and just make it something less scary - as in DRM_DEBUG?

Quoted 6 lines

But if you need to stop processing right away, you should probably call 'break' here. Perhaps also remove all the entries from the list?

Either way - please comment what is the "right" way to deal with this.

Ok, get it. thank you.

Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +34 -0
+		}
+	}
+
+	drm_dev = dev;
+	mutex_unlock(&samsung_drm_mutex);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(samsung_drm_device_register);
+
+void samsung_drm_device_unregister(struct drm_device *dev)
+{
+	struct samsung_drm_subdrv *subdrv;
+
+	if (!dev || dev != drm_dev) {
+		WARN(1, "Unexpected drm device unregister!\n");
+		return;
+	}
+
+	mutex_lock(&samsung_drm_mutex);
+	list_for_each_entry(subdrv, &samsung_drm_subdrv_list, list)
+		samsung_drm_subdrv_remove(dev, subdrv);
+
+	drm_dev = NULL;
+	mutex_unlock(&samsung_drm_mutex);
+}
+EXPORT_SYMBOL_GPL(samsung_drm_device_unregister);
+
+static int samsung_drm_mode_group_reinit(struct drm_device *dev)
+{
+	struct drm_mode_group *group = &dev->primary->mode_group;
+	uint32_t *id_list = group->id_list;
+	int ret;
+
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_core.c line 147

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +5 -0
+	ret = drm_mode_group_init_legacy_group(dev, group);
+	if (ret < 0)
+		return ret;
+
+	kfree(id_list);

id_list = NULL ?
Just in case somebody calls _twice_ this function.

group->id_list is allocated again at drm_mode_group_init_legacy_group function when this function is called. it doesn't need id_list = NULL.

Quoted 60 lines
Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +7 -0
+	return 0;
+}
+
+int samsung_drm_subdrv_register(struct samsung_drm_subdrv *subdrv)
+{
+	int err;
+

drivers/gpu/drm/samsung/samsung_drm_core.c line 164

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+	if (!subdrv)
+		return -EINVAL;
+
+	mutex_lock(&samsung_drm_mutex);
+	if (drm_dev) {
+		err = samsung_drm_subdrv_probe(drm_dev, subdrv);
+		if (err) {
+			DRM_ERROR("failed to probe samsung drm subdrv\n");
+			mutex_unlock(&samsung_drm_mutex);
+			return err;

You can make this, and the other two a bit cleaner by using 'goto fail'

drivers/gpu/drm/samsung/samsung_drm_core.c

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +5 -0
+		}
+
+		err = samsung_drm_fbdev_reinit(drm_dev);
+		if (err) {
+			DRM_ERROR("failed to reinitialize samsung drm

fbdev\n");

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +8 -0
+			samsung_drm_subdrv_remove(drm_dev, subdrv);
+			mutex_unlock(&samsung_drm_mutex);
+			return err;
+		}
+
+		err = samsung_drm_mode_group_reinit(drm_dev);
+		if (err) {
+			DRM_ERROR("failed to reinitialize mode group\n");

drivers/gpu/drm/samsung/samsung_drm_core.c line 187

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +10 -0
+			samsung_drm_fbdev_fini(drm_dev);
+			samsung_drm_subdrv_remove(drm_dev, subdrv);
+			mutex_unlock(&samsung_drm_mutex);
+			return err;
+		}
+	}
+
+	subdrv->drm_dev = drm_dev;
+
+	list_add_tail(&subdrv->list, &samsung_drm_subdrv_list);

fail:

drivers/gpu/drm/samsung/samsung_drm_core.c line 115

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +3 -0
+	mutex_unlock(&samsung_drm_mutex);
+
+	return 0;

.. and returning err; Naturally you would need to set err = 0 in the decleration.

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +9 -0
+}
+EXPORT_SYMBOL_GPL(samsung_drm_subdrv_register);
+
+void samsung_drm_subdrv_unregister(struct samsung_drm_subdrv *subdrv)
+{
+	if (!subdrv) {
+		WARN(1, "Unexpected samsung drm subdrv unregister!\n");
+		return;
+	}
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_core.c line 205

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +6 -0
+
+	mutex_lock(&samsung_drm_mutex);
+	if (drm_dev) {
+		samsung_drm_subdrv_remove(drm_dev, subdrv);
+
+		/* FIXME: error check */

You might as well do it now - before you do the next posting.

Ok, get it. you mean, send this patch modified now, not next posting.?

Quoted 42 lines

Review

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_core.c new file +8 -0
+		samsung_drm_fbdev_reinit(drm_dev);
+		samsung_drm_mode_group_reinit(drm_dev);
+	}
+
+	list_del(&subdrv->list);
+	mutex_unlock(&samsung_drm_mutex);
+}
+EXPORT_SYMBOL_GPL(samsung_drm_subdrv_unregister);
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_crtc.c

Quoted 5 lines

new file mode 100644
index 0000000..5836757

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 9

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +9 -0
@@ -0,0 +1,329 @@
+/* samsung_drm_crtc.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 13

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 16

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 17

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 20

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 23

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 103 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 25

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_crtc.c

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +11 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_fb.h"
+#include "samsung_drm_encoder.h"
+
+#define to_samsung_crtc(x)	container_of(x, struct

samsung_drm_crtc,\

Quoted 16 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +16 -0
+				drm_crtc)
+
+/*
+ * @fb_x: horizontal position from framebuffer base
+ * @fb_y: vertical position from framebuffer base
+ * @base_x: horizontal position from screen base
+ * @base_y: vertical position from screen base
+ * @crtc_w: width of crtc
+ * @crtc_h: height of crtc
+ */
+struct samsung_drm_crtc_pos {
+	unsigned int fb_x;
+	unsigned int fb_y;
+	unsigned int base_x;
+	unsigned int base_y;
+	unsigned int crtc_w;

drivers/gpu/drm/samsung/samsung_drm_crtc.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +10 -0
+	unsigned int crtc_h;
+};
+
+struct samsung_drm_crtc {
+	struct drm_crtc			drm_crtc;
+	struct samsung_drm_overlay	overlay;
+	unsigned int			pipe;
+};
+
+static void samsung_drm_overlay_update(struct samsung_drm_overlay

*overlay,

drivers/gpu/drm/samsung/samsung_drm_crtc.c

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +12 -0
+				       struct drm_framebuffer *fb,
+				       struct drm_display_mode *mode,
+				       struct samsung_drm_crtc_pos *pos)
+{
+	struct samsung_drm_buffer_info buffer_info;
+	unsigned int actual_w = pos->crtc_w;
+	unsigned int actual_h = pos->crtc_h;
+	unsigned int hw_w;
+	unsigned int hw_h;
+
+	/* update buffer address of framebuffer. */
+	samsung_drm_fb_update_buf_off(fb, pos->fb_x, pos->fb_y,

&buffer_info);

Quoted 49 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +49 -0
+	overlay->paddr = buffer_info.paddr;
+	overlay->vaddr = buffer_info.vaddr;
+
+	hw_w = mode->hdisplay - pos->base_x;
+	hw_h = mode->vdisplay - pos->base_y;
+
+	if (actual_w > hw_w)
+		actual_w = hw_w;
+	if (actual_h > hw_h)
+		actual_h = hw_h;
+
+	overlay->offset_x = pos->base_x;
+	overlay->offset_y = pos->base_y;
+	overlay->width = actual_w;
+	overlay->height = actual_h;
+
+	DRM_DEBUG_KMS("overlay : offset_x/y(%d,%d), width/height(%d,%d)",
+			overlay->offset_x, overlay->offset_y,
+			overlay->width, overlay->height);
+
+	overlay->buf_offsize = fb->width - actual_w;
+	overlay->line_size = actual_w;
+	overlay->end_buf_off = fb->width * actual_h;
+}
+
+static int samsung_drm_crtc_update(struct drm_crtc *crtc)
+{
+	struct samsung_drm_crtc *samsung_crtc;
+	struct samsung_drm_overlay *overlay;
+	struct samsung_drm_crtc_pos pos;
+	struct drm_display_mode *mode = &crtc->mode;
+	struct drm_framebuffer *fb = crtc->fb;
+
+	if (!mode || !fb)
+		return -EINVAL;
+
+	samsung_crtc = to_samsung_crtc(crtc);
+	overlay = &samsung_crtc->overlay;
+
+	memset(&pos, 0, sizeof(struct samsung_drm_crtc_pos));
+	pos.fb_x = crtc->x;
+	pos.fb_y = crtc->y;
+	pos.crtc_w = fb->width - crtc->x;
+	pos.crtc_h = fb->height - crtc->y;
+
+	samsung_drm_overlay_update(overlay, crtc->fb, mode, &pos);
+
+	return 0;
+}
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 129

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +6 -0
+
+/* CRTC helper functions */
+static void samsung_drm_crtc_dpms(struct drm_crtc *crtc, int mode)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* TODO */

Can you describe in the comment what it is suppose to do?

Ok, I will add the comment what it is suppose to do. Thank you.

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 135

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +6 -0
+}
+
+static void samsung_drm_crtc_prepare(struct drm_crtc *crtc)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* drm framework doesn't check NULL. */

Uh, ? What does that have to do with the function?

This function doesn't need yet. but now drm framework doesn't check null-point so drm framework has null-point access. Please see drm_crtc_helper_set_mode() of drm_crtc_helper.c file, "crtc_funcs->prepare(crtc)". also you can find similar codes at drm framework.

Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 141

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +6 -0
+}
+
+static void samsung_drm_crtc_commit(struct drm_crtc *crtc)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* drm framework doesn't check NULL. */

Ditto

Ditto.

Quoted 12 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 150

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +9 -0
+}
+
+static bool
+samsung_drm_crtc_mode_fixup(struct drm_crtc *crtc,
+			    struct drm_display_mode *mode,
+			    struct drm_display_mode *adjusted_mode)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* drm framework doesn't check NULL */

Ditto?

Ditto.

Quoted 7 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +5 -0
+	return true;
+}
+
+static int
+samsung_drm_crtc_mode_set(struct drm_crtc *crtc, struct

drm_display_mode *mode,

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 156

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +1 -0
+			  struct drm_display_mode *adjusted_mode, int x, int

y,

Quoted 42 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +10 -0
+			  struct drm_framebuffer *old_fb)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode = adjusted_mode;
+
+	return samsung_drm_crtc_update(crtc);
+}
+
+static int samsung_drm_crtc_mode_set_base(struct drm_crtc *crtc, int x,

int y,

Quoted 31 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +31 -0
+					  struct drm_framebuffer *old_fb)
+{
+	struct samsung_drm_crtc *samsung_crtc = to_samsung_crtc(crtc);
+	struct samsung_drm_overlay *overlay = &samsung_crtc->overlay;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	ret = samsung_drm_crtc_update(crtc);
+	if (ret)
+		return ret;
+
+	samsung_drm_fn_encoder(crtc, overlay,
+			samsung_drm_encoder_crtc_mode_set);
+	samsung_drm_fn_encoder(crtc, NULL, samsung_drm_encoder_crtc_commit);
+
+	return ret;
+}
+
+static void samsung_drm_crtc_load_lut(struct drm_crtc *crtc)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+	/* drm framework doesn't check NULL */
+}
+
+static struct drm_crtc_helper_funcs samsung_crtc_helper_funcs = {
+	.dpms		= samsung_drm_crtc_dpms,
+	.prepare	= samsung_drm_crtc_prepare,
+	.commit		= samsung_drm_crtc_commit,
+	.mode_fixup	= samsung_drm_crtc_mode_fixup,
+	.mode_set	= samsung_drm_crtc_mode_set,
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +8 -0
+	.mode_set_base	= samsung_drm_crtc_mode_set_base,
+	.load_lut	= samsung_drm_crtc_load_lut,
+};
+
+/* CRTC functions */
+static int samsung_drm_crtc_page_flip(struct drm_crtc *crtc,
+				      struct drm_framebuffer *fb,
+				      struct drm_pending_vblank_event

*event)

Quoted 90 lines
Quoted 57 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +57 -0
+{
+	struct drm_device *dev = crtc->dev;
+	struct samsung_drm_private *dev_priv = dev->dev_private;
+	struct samsung_drm_crtc *samsung_crtc = to_samsung_crtc(crtc);
+	struct samsung_drm_overlay *overlay = &samsung_crtc->overlay;
+	struct drm_framebuffer *old_fb = crtc->fb;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mutex_lock(&dev->struct_mutex);
+
+	if (event && !dev_priv->pageflip_event) {
+		list_add_tail(&event->base.link,
+				&dev_priv->pageflip_event_list);
+
+		ret = drm_vblank_get(dev, samsung_crtc->pipe);
+		if (ret) {
+			DRM_DEBUG("failed to acquire vblank counter\n");
+			goto out;
+		}
+
+		dev_priv->pageflip_event = true;
+	}
+
+	crtc->fb = fb;
+
+	ret = samsung_drm_crtc_update(crtc);
+	if (ret) {
+		crtc->fb = old_fb;
+		if (event && dev_priv->pageflip_event) {
+			drm_vblank_put(dev, samsung_crtc->pipe);
+			dev_priv->pageflip_event = false;
+		}
+
+		goto out;
+	}
+
+	samsung_drm_fn_encoder(crtc, overlay,
+			samsung_drm_encoder_crtc_mode_set);
+	samsung_drm_fn_encoder(crtc, NULL, samsung_drm_encoder_crtc_commit);
+
+out:
+	mutex_unlock(&dev->struct_mutex);
+	return ret;
+}
+
+static void samsung_drm_crtc_destroy(struct drm_crtc *crtc)
+{
+	struct samsung_drm_crtc *samsung_crtc = to_samsung_crtc(crtc);
+	struct samsung_drm_private *private = crtc->dev->dev_private;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	private->crtc[samsung_crtc->pipe] = NULL;
+
+	drm_crtc_cleanup(crtc);

drivers/gpu/drm/samsung/samsung_drm_crtc.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +10 -0
+	kfree(samsung_crtc);
+}
+
+static struct drm_crtc_funcs samsung_crtc_funcs = {
+	.set_config	= drm_crtc_helper_set_config,
+	.page_flip	= samsung_drm_crtc_page_flip,
+	.destroy	= samsung_drm_crtc_destroy,
+};
+
+struct samsung_drm_overlay *get_samsung_drm_overlay(struct drm_device

*dev,

Quoted 22 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +22 -0
+		struct drm_crtc *crtc)
+{
+	struct samsung_drm_crtc *samsung_crtc = to_samsung_crtc(crtc);
+
+	return &samsung_crtc->overlay;
+}
+
+int samsung_drm_crtc_create(struct drm_device *dev, unsigned int nr)
+{
+	struct samsung_drm_crtc *samsung_crtc;
+	struct samsung_drm_private *private = dev->dev_private;
+	struct drm_crtc *crtc;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_crtc = kzalloc(sizeof(*samsung_crtc), GFP_KERNEL);
+	if (!samsung_crtc) {
+		DRM_ERROR("failed to allocate samsung crtc\n");
+		return -ENOMEM;
+	}
+
+	samsung_crtc->pipe = nr;
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.c line 300

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +6 -0
+	crtc = &samsung_crtc->drm_crtc;
+
+	private->crtc[nr] = crtc;
+
+	drm_crtc_init(dev, crtc, &samsung_crtc_funcs);
+	drm_crtc_helper_add(crtc, &samsung_crtc_helper_funcs);

Who is responsible for deallocating samsung_crtc?

see samsung_drm_crtc_destory() please. this function would be called by unload callback to deallocate all resources.

Quoted 63 lines

Review

Quoted 30 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.c new file +29 -0
+
+	return 0;
+}
+
+int samsung_drm_crtc_enable_vblank(struct drm_device *dev, int crtc)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_drm_fn_encoder(private->crtc[crtc], &crtc,
+			samsung_drm_enable_vblank);
+
+	return 0;
+}
+
+void samsung_drm_crtc_disable_vblank(struct drm_device *dev, int crtc)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_drm_fn_encoder(private->crtc[crtc], &crtc,
+			samsung_drm_disable_vblank);
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");
+MODULE_DESCRIPTION("Samsung SoC DRM CRTC Driver");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_crtc.h

Quoted 5 lines

new file mode 100644
index 0000000..c6998e1

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 9

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +9 -0
@@ -0,0 +1,38 @@
+/* samsung_drm_crtc.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 13

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 16

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 17

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 20

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 23

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 49 lines

drivers/gpu/drm/samsung/samsung_drm_crtc.h line 25

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_crtc.h

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +7 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_CRTC_H_
+#define _SAMSUNG_DRM_CRTC_H_
+
+struct samsung_drm_overlay *get_samsung_drm_overlay(struct drm_device

*dev,

Review

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_crtc.h new file +6 -0
+		struct drm_crtc *crtc);
+int samsung_drm_crtc_create(struct drm_device *dev, unsigned int nr);
+int samsung_drm_crtc_enable_vblank(struct drm_device *dev, int crtc);
+void samsung_drm_crtc_disable_vblank(struct drm_device *dev, int crtc);
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_drv.c

drivers/gpu/drm/samsung/samsung_drm_drv.c line 8

Quoted 13 lines

new file mode 100644
index 0000000..6e812b3

drivers/gpu/drm/samsung/samsung_drm_drv.c new file +8 -0
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_drv.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_drv.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_drv.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_drv.c line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_drv.c line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_drv.c line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_drv.c line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_drv.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_drv.c line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_drv.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 15 lines

drivers/gpu/drm/samsung/samsung_drm_drv.c line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +13 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm.h"
+
+#include <drm/samsung_drm.h>
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_crtc.h"
+#include "samsung_drm_fbdev.h"
+#include "samsung_drm_fb.h"
+#include "samsung_drm_gem.h"
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_drv.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +8 -0
+
+#define DRIVER_NAME	"samsung-drm"
+#define DRIVER_DESC	"Samsung SoC DRM"
+#define DRIVER_DATE	"20110530"
+#define DRIVER_MAJOR	1
+#define DRIVER_MINOR	0
+
+static int samsung_drm_load(struct drm_device *dev, unsigned long

flags)

Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +44 -0
+{
+	struct samsung_drm_private *private;
+	int ret;
+	int nr;
+
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	private = kzalloc(sizeof(struct samsung_drm_private), GFP_KERNEL);
+	if (!private) {
+		DRM_ERROR("failed to allocate private\n");
+		return -ENOMEM;
+	}
+
+	INIT_LIST_HEAD(&private->pageflip_event_list);
+	dev->dev_private = (void *)private;
+
+	drm_mode_config_init(dev);
+
+	samsung_drm_mode_config_init(dev);
+
+	for (nr = 0; nr < MAX_CRTC; nr++) {
+		ret = samsung_drm_crtc_create(dev, nr);
+		if (ret)
+			goto err_crtc;
+	}
+
+	ret = drm_vblank_init(dev, MAX_CRTC);
+	if (ret)
+		goto err_crtc;
+
+	ret = samsung_drm_device_register(dev);
+	if (ret)
+		goto err_vblank;
+
+	ret = samsung_drm_fbdev_init(dev);
+	if (ret) {
+		DRM_ERROR("failed to initialize drm fbdev\n");
+		goto err_drm_device;
+	}
+
+	return 0;
+
+err_drm_device:
+	samsung_drm_device_unregister(dev);
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_drv.c line 94

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +5 -0
+err_vblank:
+	drm_vblank_cleanup(dev);
+err_crtc:
+	drm_mode_config_cleanup(dev);
+	kfree(private);

You might want to do dev->dev_private = NULL just in case This drm_unload is called twice.

Thank you.

Quoted 34 lines
Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +6 -0
+
+	return ret;
+}
+
+static int samsung_drm_unload(struct drm_device *dev)
+{

drivers/gpu/drm/samsung/samsung_drm_drv.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +10 -0
+	samsung_drm_fbdev_fini(dev);
+	samsung_drm_device_unregister(dev);
+	drm_vblank_cleanup(dev);
+	drm_mode_config_cleanup(dev);
+	kfree(dev->dev_private);
+
+	return 0;
+}
+
+static int samsung_drm_open(struct drm_device *dev, struct drm_file

*file_priv)

Quoted 17 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +17 -0
+{
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	return 0;
+}
+
+static void samsung_drm_lastclose(struct drm_device *dev)
+{
+	samsung_drm_fbdev_restore_mode(dev);
+}
+
+static struct vm_operations_struct samsung_drm_gem_vm_ops = {
+	.fault = samsung_drm_gem_fault,
+	.open = drm_gem_vm_open,
+	.close = drm_gem_vm_close,
+};
+
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_drv.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +8 -0
+static struct drm_ioctl_desc samsung_ioctls[] = {
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_CREATE, samsung_drm_gem_create_ioctl,
+			DRM_UNLOCKED | DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MAP_OFFSET,
+			samsung_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
+				DRM_AUTH),
+	DRM_IOCTL_DEF_DRV(SAMSUNG_GEM_MMAP,
+			samsung_drm_gem_mmap_ioctl, DRM_UNLOCKED |

DRM_AUTH),

Quoted 113 lines

Review

Quoted 81 lines
drivers/gpu/drm/samsung/samsung_drm_drv.c new file +80 -0
+};
+
+static struct drm_driver samsung_drm_driver = {
+	.driver_features	= DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
+				  DRIVER_MODESET | DRIVER_GEM,
+	.load			= samsung_drm_load,
+	.unload			= samsung_drm_unload,
+	.open			= samsung_drm_open,
+	.lastclose		= samsung_drm_lastclose,
+	.get_vblank_counter	= drm_vblank_count,
+	.enable_vblank		= samsung_drm_crtc_enable_vblank,
+	.disable_vblank		= samsung_drm_crtc_disable_vblank,
+	.gem_init_object	= samsung_drm_gem_init_object,
+	.gem_free_object	= samsung_drm_gem_free_object,
+	.gem_vm_ops		= &samsung_drm_gem_vm_ops,
+	.dumb_create		= samsung_drm_gem_dumb_create,
+	.dumb_map_offset	= samsung_drm_gem_dumb_map_offset,
+	.dumb_destroy		= samsung_drm_gem_dumb_destroy,
+	.ioctls			= samsung_ioctls,
+	.fops = {
+		.owner		= THIS_MODULE,
+		.open		= drm_open,
+		.mmap		= samsung_drm_gem_mmap,
+		.poll		= drm_poll,
+		.read		= drm_read,
+		.unlocked_ioctl	= drm_ioctl,
+		.release	= drm_release,
+	},
+	.name	= DRIVER_NAME,
+	.desc	= DRIVER_DESC,
+	.date	= DRIVER_DATE,
+	.major	= DRIVER_MAJOR,
+	.minor	= DRIVER_MINOR,
+};
+
+static int samsung_drm_platform_probe(struct platform_device *pdev)
+{
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	samsung_drm_driver.num_ioctls = DRM_ARRAY_SIZE(samsung_ioctls);
+
+	return drm_platform_init(&samsung_drm_driver, pdev);
+}
+
+static int samsung_drm_platform_remove(struct platform_device *pdev)
+{
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	drm_platform_exit(&samsung_drm_driver, pdev);
+
+	return 0;
+}
+
+static struct platform_driver samsung_drm_platform_driver = {
+	.probe		= samsung_drm_platform_probe,
+	.remove		= __devexit_p(samsung_drm_platform_remove),
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= DRIVER_NAME,
+	},
+};
+
+static int __init samsung_drm_init(void)
+{
+	DRM_DEBUG_DRIVER("%s\n", __FILE__);
+
+	return platform_driver_register(&samsung_drm_platform_driver);
+}
+
+static void __exit samsung_drm_exit(void)
+{
+	platform_driver_unregister(&samsung_drm_platform_driver);
+}
+
+module_init(samsung_drm_init);
+module_exit(samsung_drm_exit);
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");
+MODULE_DESCRIPTION("Samsung SoC DRM Driver");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_drv.h

drivers/gpu/drm/samsung/samsung_drm_drv.h line 8

Quoted 13 lines

new file mode 100644
index 0000000..a5a49c2

drivers/gpu/drm/samsung/samsung_drm_drv.h new file +8 -0
@@ -0,0 +1,194 @@
+/* samsung_drm_drv.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_drv.h line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_drv.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_drv.h line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_drv.h line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_drv.h line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_drv.h line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_drv.h line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_drv.h line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_drv.h line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_drv.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 33 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 31 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +31 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_DRV_H_
+#define _SAMSUNG_DRM_DRV_H_
+
+#include "drm.h"
+
+#define MAX_CRTC	2
+
+struct drm_device;
+struct samsung_drm_overlay;
+struct drm_connector;
+
+enum samsung_drm_output_type {
+	SAMSUNG_DISPLAY_TYPE_NONE,
+	SAMSUNG_DISPLAY_TYPE_LCD,	/* RGB or CPU Interface. */
+	SAMSUNG_DISPLAY_TYPE_HDMI,	/* HDMI Interface. */
+};
+
+/**
+ * Samsung drm overlay ops structure.
+ *
+ * @mode_set: copy drm overlay info to hw specific overlay info.
+ * @commit: set hw specific overlay into to hw.
+ */
+struct samsung_drm_overlay_ops {
+	void (*mode_set)(struct device *subdrv_dev,
+			 struct samsung_drm_overlay *overlay);
+	void (*commit)(struct device *subdrv_dev);
+	void (*disable)(struct device *subdrv_dev);
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 61

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +6 -0
+};
+
+/**
+ * Samsung drm common overlay structure.
+ *
+ * @win_num: window number.

Not seeing that.

It would be clean. Thank you.

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 68

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +7 -0
+ * @offset_x: offset to x position.
+ * @offset_y: offset to y position.
+ * @pos_x: x position.
+ * @pos_y: y position.
+ * @width: window width.
+ * @height: window height.
+ * @bpp: bit per pixel.

Ditto

Also.

Quoted 3 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 69

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * @paddr: physical memory address to this overlay.

That is CPU physical or bus physical (DMA)

Ok, get it. I will correct this comment. Thank you.

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +9 -0
+ * @vaddr: virtual memory addresss to this overlay.
+ * @buf_off: start offset of framebuffer to be displayed.
+ * @end_buf_off: end offset of framebuffer to be displayed.
+ * @buf_offsize: this value has result from
+ *			(framebuffer width - display width) * bpp.
+ * @line_size: line size to this overlay memory in bytes.
+ * @default_win: a window to be enabled.
+ * @color_key: color key on or off.
+ * @index_color: if using color key feature then this value would be
Quoted 8 lines

used

drivers/gpu/drm/samsung/samsung_drm_drv.h line 83

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +5 -0
+ *			as index color.
+ * @local_path: in case of lcd type, local path mode on or off.
+ * @transparency: transparency on or off.
+ * @activated: activated or not.
+ * @subdrv_dev: pointer to device object for subdrv device driver.

?

I missed it. I will remove this comment. Thank you.

Quoted 7 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 87

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +4 -0
+ * @ops: pointer to samsung_drm_overlay_ops.
+ *
+ * this structure is common to Samsung SoC and would be copied
+ * to hardware specific overlay info.

Uh?

This means that contents of samsung_drm_overlay object will copied to fimd's one, struct fimd_win_data.

Quoted 10 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 94

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +7 -0
+ */
+struct samsung_drm_overlay {
+	unsigned int offset_x;
+	unsigned int offset_y;
+	unsigned int width;
+	unsigned int height;
+	unsigned int paddr;

You don't want to use 'dma_addr_t' ?

You are right. I will correct it. thank you.

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +13 -0
+	void __iomem *vaddr;
+	unsigned int buf_off;
+	unsigned int end_buf_off;
+	unsigned int buf_offsize;
+	unsigned int line_size;
+
+	bool default_win;
+	bool color_key;
+	unsigned int index_color;
+	bool local_path;
+	bool transparency;
+	bool activated;
+};
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 113

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +6 -0
+
+/**
+ * Samsung DRM Display Structure.
+ *	- this structure is common to analog tv, digital tv and lcd panel.
+ *
+ * @dev: pointer to specific device object.

??

Ah, this should be removed. Thank you.

Quoted 38 lines
Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +13 -0
+ * @is_connected: check for that display is connected or not.
+ * @get_edid: get edid modes from display driver.
+ * @get_timing: get timing object from display driver.
+ * @check_timing: check if timing is valid or not.
+ * @power_on: display device on or off.
+ */
+struct samsung_drm_display {
+	unsigned int type;
+	bool (*is_connected)(struct device *dev);
+	int (*get_edid)(struct device *dev, struct drm_connector *connector,
+				u8 *edid, int len);
+	void *(*get_timing)(struct device *dev);
+	int (*check_timing)(struct device *dev, void *timing);

drivers/gpu/drm/samsung/samsung_drm_drv.h

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+	int (*power_on)(struct device *dev, int mode);
+};
+
+/**
+ * Samsung drm manager ops
+ *
+ * @mode_set: convert drm_display_mode to hw specific display mode and
+ *	      would be called by encoder->mode_set().
+ * @commit: set current hw specific display mode to hw.
+ * @enable_vblank: specific driver callback for enabling vblank

interrupt.

drivers/gpu/drm/samsung/samsung_drm_drv.h line 137

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * @disable_vblank: specific driver callback for disabling vblank

interrupt.

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +12 -0
+ */
+struct samsung_drm_manager_ops {
+	void (*mode_set)(struct device *subdrv_dev, void *mode);
+	void (*commit)(struct device *subdrv_dev);
+	int (*enable_vblank)(struct device *subdrv_dev);
+	void (*disable_vblank)(struct device *subdrv_dev);
+};
+
+/**
+ * Samsung drm common manager structure.
+ *
+ * @dev: pointer to device object for subdrv device driver.
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 155

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +6 -0
+ * @ops: ops pointer to samsung drm common framebuffer.
+ *	 ops of fimd or hdmi driver should be set to this ones.
+ */
+struct samsung_drm_manager {
+	struct device *dev;
+	int pipe;

No comment for that?

Ok, get it. I will add some comment for that. thank you.

Quoted 5 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 158

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+	struct samsung_drm_manager_ops *ops;
+	struct samsung_drm_overlay_ops *overlay_ops;
+	struct samsung_drm_display *display;

And you are missing the comments for these two.

Also.

Quoted 7 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 45

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+};
+
+/**

I just noticed it, but the '**' is not the kerneldoc style comment. You might want to remove them from all the files.

Ok, get it. thank you.

Quoted 5 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 162

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +1 -0
+ * Samsung drm private structure.

Ok, you are defining it in a public header so you should at least document what the fields mean.

Ok, get it. I will add comments to all fields and thank you for your pointing.

Quoted 4 lines

If you don't want the public to use it - make another header file, helpfully called 'xxx_private.h'

Quoted 14 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 173

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +11 -0
+ */
+struct samsung_drm_private {
+	struct drm_fb_helper *fb_helper;
+
+	/* for pageflip */
+	struct list_head pageflip_event_list;
+	bool pageflip_event;
+
+	struct drm_crtc *crtc[MAX_CRTC];
+
+	/* add some structures. */

Umm, which ones?

This comment will be removed. Thank you.

Quoted 55 lines
Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +9 -0
+};
+
+struct samsung_drm_subdrv {
+	struct list_head list;
+	struct drm_device *drm_dev;
+
+	/* driver ops */
+	int (*probe)(struct drm_device *dev);
+	void (*remove)(struct drm_device *dev);

drivers/gpu/drm/samsung/samsung_drm_drv.h

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+
+	struct samsung_drm_manager manager;
+	struct drm_encoder *encoder;
+	struct drm_connector *connector;
+};
+
+int samsung_drm_device_register(struct drm_device *dev);
+void samsung_drm_device_unregister(struct drm_device *dev);
+int samsung_drm_subdrv_register(struct samsung_drm_subdrv *drm_subdrv);
+void samsung_drm_subdrv_unregister(struct samsung_drm_subdrv

*drm_subdrv);

Review

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +2 -0
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_encoder.c

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 8

Quoted 13 lines

new file mode 100644
index 0000000..c875968

drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +8 -0
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 28 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +11 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_crtc.h"
+#include "samsung_drm_encoder.h"
+
+#define to_samsung_encoder(x)	container_of(x, struct

samsung_drm_encoder,\

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +8 -0
+				drm_encoder)
+
+struct samsung_drm_encoder {
+	struct drm_encoder		drm_encoder;
+	struct samsung_drm_manager	*manager;
+};
+
+static void samsung_drm_encoder_dpms(struct drm_encoder *encoder, int

mode)

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +4 -0
+{
+	struct drm_device *dev = encoder->dev;
+	struct drm_connector *connector;
+	struct samsung_drm_manager *manager =

samsung_drm_get_manager(encoder);

Quoted 7 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +4 -0
+
+	DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__, mode);
+
+	list_for_each_entry(connector, &dev->mode_config.connector_list,

head) {

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 53

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +2 -0
+		if (connector->encoder == encoder) {
+			struct samsung_drm_display *display =

manager->display;

Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +12 -0
+
+			if (display && display->power_on)
+				display->power_on(manager->dev, mode);
+		}
+	}
+}
+
+static bool
+samsung_drm_encoder_mode_fixup(struct drm_encoder *encoder,
+			       struct drm_display_mode *mode,
+			       struct drm_display_mode *adjusted_mode)
+{
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +8 -0
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return true;
+}
+
+static void samsung_drm_encoder_mode_set(struct drm_encoder *encoder,
+					 struct drm_display_mode *mode,
+					 struct drm_display_mode

*adjusted_mode)

Quoted 16 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +4 -0
+{
+	struct drm_device *dev = encoder->dev;
+	struct drm_connector *connector;
+	struct samsung_drm_manager *manager =

samsung_drm_get_manager(encoder);

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +10 -0
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+	struct samsung_drm_overlay *overlay = get_samsung_drm_overlay(dev,
+						encoder->crtc);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode = adjusted_mode;
+
+	list_for_each_entry(connector, &dev->mode_config.connector_list,

head) {

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +6 -0
+		if (connector->encoder == encoder) {
+			if (manager_ops && manager_ops->mode_set)
+				manager_ops->mode_set(manager->dev, mode);
+
+			if (overlay_ops && overlay_ops->mode_set)
+				overlay_ops->mode_set(manager->dev,

overlay);

Quoted 122 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +12 -0
+		}
+	}
+}
+
+static void samsung_drm_encoder_prepare(struct drm_encoder *encoder)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+}
+
+static void samsung_drm_encoder_commit(struct drm_encoder *encoder)
+{
+	struct samsung_drm_manager *manager =

samsung_drm_get_manager(encoder);

Quoted 74 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +74 -0
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (manager_ops && manager_ops->commit)
+		manager_ops->commit(manager->dev);
+
+	if (overlay_ops && overlay_ops->commit)
+		overlay_ops->commit(manager->dev);
+}
+
+static struct drm_crtc *
+samsung_drm_encoder_get_crtc(struct drm_encoder *encoder)
+{
+	return encoder->crtc;
+}
+
+static struct drm_encoder_helper_funcs samsung_encoder_helper_funcs = {
+	.dpms		= samsung_drm_encoder_dpms,
+	.mode_fixup	= samsung_drm_encoder_mode_fixup,
+	.mode_set	= samsung_drm_encoder_mode_set,
+	.prepare	= samsung_drm_encoder_prepare,
+	.commit		= samsung_drm_encoder_commit,
+	.get_crtc	= samsung_drm_encoder_get_crtc,
+};
+
+static void samsung_drm_encoder_destroy(struct drm_encoder *encoder)
+{
+	struct samsung_drm_encoder *samsung_encoder =
+		to_samsung_encoder(encoder);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_encoder->manager->pipe = -1;
+
+	drm_encoder_cleanup(encoder);
+	encoder->dev->mode_config.num_encoder--;
+	kfree(samsung_encoder);
+}
+
+static struct drm_encoder_funcs samsung_encoder_funcs = {
+	.destroy = samsung_drm_encoder_destroy,
+};
+
+struct drm_encoder *
+samsung_drm_encoder_create(struct drm_device *dev,
+			   struct samsung_drm_manager *manager,
+			   unsigned int possible_crtcs)
+{
+	struct drm_encoder *encoder;
+	struct samsung_drm_encoder *samsung_encoder;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (!manager || !possible_crtcs)
+		return NULL;
+
+	if (!manager->dev)
+		return NULL;
+
+	samsung_encoder = kzalloc(sizeof(*samsung_encoder), GFP_KERNEL);
+	if (!samsung_encoder) {
+		DRM_ERROR("failed to allocate encoder\n");
+		return NULL;
+	}
+
+	samsung_encoder->manager = manager;
+	encoder = &samsung_encoder->drm_encoder;
+	encoder->possible_crtcs = possible_crtcs;
+
+	DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
+
+	drm_encoder_init(dev, encoder, &samsung_encoder_funcs,

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +10 -0
+			DRM_MODE_ENCODER_TMDS);
+
+	drm_encoder_helper_add(encoder, &samsung_encoder_helper_funcs);
+
+	DRM_DEBUG_KMS("encoder has been created\n");
+
+	return encoder;
+}
+
+struct samsung_drm_manager *samsung_drm_get_manager(struct drm_encoder

*encoder)

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +11 -0
+{
+	return to_samsung_encoder(encoder)->manager;
+}
+
+void samsung_drm_fn_encoder(struct drm_crtc *crtc, void *data,
+			    void (*fn)(struct drm_encoder *, void *))
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_encoder *encoder;
+
+	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)

{

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +12 -0
+		if (encoder->crtc != crtc)
+			continue;
+
+		fn(encoder, data);
+	}
+}
+
+void samsung_drm_enable_vblank(struct drm_encoder *encoder, void *data)
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 218

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +6 -0
+	int crtc = *(int *)data;
+
+	if (manager->pipe == -1)
+		manager->pipe = crtc;
+
+	/* old_crtc checking needs? FIXME!!! */

Is this still pertient?

I will remove this comment after looking over more. Thank you.

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +6 -0
+
+	if (manager_ops->enable_vblank)
+		manager_ops->enable_vblank(manager->dev);
+}
+
+void samsung_drm_disable_vblank(struct drm_encoder *encoder, void

*data)

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 213

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +5 -0
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	int crtc = *(int *)data;

You don't want to check whether data is NULL before you derefernce it?

Ok, get it. thank you.

Quoted 11 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 218

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +5 -0
+
+	if (manager->pipe == -1)
+		manager->pipe = crtc;
+
+	/* old_crtc checking needs? FIXME!!! */

I am not really sure what it means.. It probably means something to you - but
perhaps it might make sense to expand it in case somebody else wants to implement this?

As I mentioned above, I will remove this comment after looking over more. Thank you.

Quoted 17 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +6 -0
+
+	if (manager_ops->disable_vblank)
+		manager_ops->disable_vblank(manager->dev);
+}
+
+void samsung_drm_encoder_crtc_commit(struct drm_encoder *encoder, void

*data)

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +9 -0
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+
+	overlay_ops->commit(manager->dev);
+}
+
+void samsung_drm_encoder_crtc_mode_set(struct drm_encoder *encoder,

void *data)

Quoted 12 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 259

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +10 -0
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+	struct samsung_drm_overlay *overlay = data;
+
+	overlay_ops->mode_set(manager->dev, overlay);
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");

You don't want to include the rest of the authors?

Definitely no. I will add other authors. Thank you.

Quoted 35 lines

Review

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +2 -0
+MODULE_DESCRIPTION("Samsung SoC DRM Encoder Driver");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_encoder.h

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 8

Quoted 13 lines

new file mode 100644
index 0000000..99040b2

drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +8 -0
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 12 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_encoder.h

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +10 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_ENCODER_H_
+#define _SAMSUNG_DRM_ENCODER_H_
+
+struct samsung_drm_manager;
+
+struct drm_encoder *samsung_drm_encoder_create(struct drm_device *dev,
+					       struct samsung_drm_manager

*mgr,

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.h

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +6 -0
+					       unsigned int possible_crtcs);
+struct samsung_drm_manager *
+samsung_drm_get_manager(struct drm_encoder *encoder);
+void samsung_drm_fn_encoder(struct drm_crtc *crtc, void *data,
+			    void (*fn)(struct drm_encoder *, void *));
+void samsung_drm_enable_vblank(struct drm_encoder *encoder, void

*data);

Quoted 41 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 41

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+void samsung_drm_disable_vblank(struct drm_encoder *encoder, void

*data);

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 42

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+void samsung_drm_encoder_crtc_commit(struct drm_encoder *encoder, void

*data);

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 43

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+void samsung_drm_encoder_crtc_mode_set(struct drm_encoder *encoder,

void *data);

Review

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +2 -0
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_fb.c

drivers/gpu/drm/samsung/samsung_drm_fb.c line 8

Quoted 13 lines

new file mode 100644
index 0000000..f087ecf

drivers/gpu/drm/samsung/samsung_drm_fb.c new file +8 -0
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_fb.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_fb.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_fb.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_fb.c line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_fb.c line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

5 lines not shown · raw message

Quoted 8 lines

8 lines not shown · raw message

2,439 lines not shown · raw message

Part of this message is not shown here. View the raw message.

#18 lore raw
Quoted 4 lines · Inki Dae

Hello, Konrad Rzeszutek Wilk.

Your review and comments are so very detail. it was very helpful. thank you again.

.. snip ..

Quoted 6 lines
Quoted 4 lines

drivers/gpu/drm/samsung/samsung_drm_core.c line 205

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_core.c new file +1 -0
+		/* FIXME: error check */

You might as well do it now - before you do the next posting.

Ok, get it. you mean, send this patch modified now, not next posting.?

When you are ready to send V5 (hopefully the last version) of these patches.

.. snip..

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

+ * @ops: pointer to samsung_drm_overlay_ops.
+ *
+ * this structure is common to Samsung SoC and would be copied
+ * to hardware specific overlay info.

Uh?

This means that contents of samsung_drm_overlay object will copied to fimd's one, struct fimd_win_data.

Ok, lets use that comment instead then.

Quoted 1,271 lines
Quoted 11 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 94

Quoted 8 lines

+ */

drivers/gpu/drm/samsung/samsung_drm_drv.h new file +6 -0
+struct samsung_drm_overlay {
+	unsigned int offset_x;
+	unsigned int offset_y;
+	unsigned int width;
+	unsigned int height;
+	unsigned int paddr;

You don't want to use 'dma_addr_t' ?

You are right. I will correct it. thank you.

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +13 -0
+	void __iomem *vaddr;
+	unsigned int buf_off;
+	unsigned int end_buf_off;
+	unsigned int buf_offsize;
+	unsigned int line_size;
+
+	bool default_win;
+	bool color_key;
+	unsigned int index_color;
+	bool local_path;
+	bool transparency;
+	bool activated;
+};
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 113

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +6 -0
+
+/**
+ * Samsung DRM Display Structure.
+ *	- this structure is common to analog tv, digital tv and lcd panel.
+ *
+ * @dev: pointer to specific device object.

??

Ah, this should be removed. Thank you.

Quoted 38 lines
Quoted 13 lines

+ * @is_connected: check for that display is connected or not.
+ * @get_edid: get edid modes from display driver.
+ * @get_timing: get timing object from display driver.
+ * @check_timing: check if timing is valid or not.
+ * @power_on: display device on or off.
+ */

drivers/gpu/drm/samsung/samsung_drm_drv.h new file +7 -0
+struct samsung_drm_display {
+	unsigned int type;
+	bool (*is_connected)(struct device *dev);
+	int (*get_edid)(struct device *dev, struct drm_connector *connector,
+				u8 *edid, int len);
+	void *(*get_timing)(struct device *dev);
+	int (*check_timing)(struct device *dev, void *timing);

drivers/gpu/drm/samsung/samsung_drm_drv.h

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+	int (*power_on)(struct device *dev, int mode);
+};
+
+/**
+ * Samsung drm manager ops
+ *
+ * @mode_set: convert drm_display_mode to hw specific display mode and
+ *	      would be called by encoder->mode_set().
+ * @commit: set current hw specific display mode to hw.
+ * @enable_vblank: specific driver callback for enabling vblank

interrupt.

Quoted 1 line

+ * @disable_vblank: specific driver callback for disabling vblank

interrupt.

Quoted 12 lines

+ */

drivers/gpu/drm/samsung/samsung_drm_drv.h new file +11 -0
+struct samsung_drm_manager_ops {
+	void (*mode_set)(struct device *subdrv_dev, void *mode);
+	void (*commit)(struct device *subdrv_dev);
+	int (*enable_vblank)(struct device *subdrv_dev);
+	void (*disable_vblank)(struct device *subdrv_dev);
+};
+
+/**
+ * Samsung drm common manager structure.
+ *
+ * @dev: pointer to device object for subdrv device driver.
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 155

Quoted 6 lines

+ * @ops: ops pointer to samsung drm common framebuffer.
+ * ops of fimd or hdmi driver should be set to this ones.
+ */

drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+struct samsung_drm_manager {
+	struct device *dev;
+	int pipe;

No comment for that?

Ok, get it. I will add some comment for that. thank you.

Quoted 5 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 158

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+	struct samsung_drm_manager_ops *ops;
+	struct samsung_drm_overlay_ops *overlay_ops;
+	struct samsung_drm_display *display;

And you are missing the comments for these two.

Also.

Quoted 7 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 45

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +3 -0
+};
+
+/**

I just noticed it, but the '**' is not the kerneldoc style comment. You might want to remove them from all the files.

Ok, get it. thank you.

Quoted 5 lines
Quoted 1 line

+ * Samsung drm private structure.

Ok, you are defining it in a public header so you should at least document what the fields mean.

Ok, get it. I will add comments to all fields and thank you for your pointing.

Quoted 4 lines

If you don't want the public to use it - make another header file, helpfully called 'xxx_private.h'

Quoted 14 lines

drivers/gpu/drm/samsung/samsung_drm_drv.h line 173

Quoted 11 lines

+ */

drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+struct samsung_drm_private {
+	struct drm_fb_helper *fb_helper;
+
+	/* for pageflip */
+	struct list_head pageflip_event_list;
+	bool pageflip_event;
+
+	struct drm_crtc *crtc[MAX_CRTC];
+
+	/* add some structures. */

Umm, which ones?

This comment will be removed. Thank you.

Quoted 55 lines
Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +9 -0
+};
+
+struct samsung_drm_subdrv {
+	struct list_head list;
+	struct drm_device *drm_dev;
+
+	/* driver ops */
+	int (*probe)(struct drm_device *dev);
+	void (*remove)(struct drm_device *dev);

drivers/gpu/drm/samsung/samsung_drm_drv.h

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_drv.h new file +10 -0
+
+	struct samsung_drm_manager manager;
+	struct drm_encoder *encoder;
+	struct drm_connector *connector;
+};
+
+int samsung_drm_device_register(struct drm_device *dev);
+void samsung_drm_device_unregister(struct drm_device *dev);
+int samsung_drm_subdrv_register(struct samsung_drm_subdrv *drm_subdrv);
+void samsung_drm_subdrv_unregister(struct samsung_drm_subdrv

*drm_subdrv);

Review

Quoted 3 lines
(quoted diff) +2 -0
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_encoder.c

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 8

Quoted 13 lines

new file mode 100644
index 0000000..c875968

drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +8 -0
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 28 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +11 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_crtc.h"
+#include "samsung_drm_encoder.h"
+
+#define to_samsung_encoder(x)	container_of(x, struct

samsung_drm_encoder,\

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +8 -0
+				drm_encoder)
+
+struct samsung_drm_encoder {
+	struct drm_encoder		drm_encoder;
+	struct samsung_drm_manager	*manager;
+};
+
+static void samsung_drm_encoder_dpms(struct drm_encoder *encoder, int

mode)

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +4 -0
+{
+	struct drm_device *dev = encoder->dev;
+	struct drm_connector *connector;
+	struct samsung_drm_manager *manager =

samsung_drm_get_manager(encoder);

Quoted 7 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +4 -0
+
+	DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__, mode);
+
+	list_for_each_entry(connector, &dev->mode_config.connector_list,

head) {

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 53

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +2 -0
+		if (connector->encoder == encoder) {
+			struct samsung_drm_display *display =

manager->display;

Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +12 -0
+
+			if (display && display->power_on)
+				display->power_on(manager->dev, mode);
+		}
+	}
+}
+
+static bool
+samsung_drm_encoder_mode_fixup(struct drm_encoder *encoder,
+			       struct drm_display_mode *mode,
+			       struct drm_display_mode *adjusted_mode)
+{
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +8 -0
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return true;
+}
+
+static void samsung_drm_encoder_mode_set(struct drm_encoder *encoder,
+					 struct drm_display_mode *mode,
+					 struct drm_display_mode

*adjusted_mode)

Quoted 16 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +4 -0
+{
+	struct drm_device *dev = encoder->dev;
+	struct drm_connector *connector;
+	struct samsung_drm_manager *manager =

samsung_drm_get_manager(encoder);

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +10 -0
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+	struct samsung_drm_overlay *overlay = get_samsung_drm_overlay(dev,
+						encoder->crtc);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode = adjusted_mode;
+
+	list_for_each_entry(connector, &dev->mode_config.connector_list,

head) {

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +6 -0
+		if (connector->encoder == encoder) {
+			if (manager_ops && manager_ops->mode_set)
+				manager_ops->mode_set(manager->dev, mode);
+
+			if (overlay_ops && overlay_ops->mode_set)
+				overlay_ops->mode_set(manager->dev,

overlay);

Quoted 122 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +12 -0
+		}
+	}
+}
+
+static void samsung_drm_encoder_prepare(struct drm_encoder *encoder)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+}
+
+static void samsung_drm_encoder_commit(struct drm_encoder *encoder)
+{
+	struct samsung_drm_manager *manager =

samsung_drm_get_manager(encoder);

Quoted 74 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +74 -0
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (manager_ops && manager_ops->commit)
+		manager_ops->commit(manager->dev);
+
+	if (overlay_ops && overlay_ops->commit)
+		overlay_ops->commit(manager->dev);
+}
+
+static struct drm_crtc *
+samsung_drm_encoder_get_crtc(struct drm_encoder *encoder)
+{
+	return encoder->crtc;
+}
+
+static struct drm_encoder_helper_funcs samsung_encoder_helper_funcs = {
+	.dpms		= samsung_drm_encoder_dpms,
+	.mode_fixup	= samsung_drm_encoder_mode_fixup,
+	.mode_set	= samsung_drm_encoder_mode_set,
+	.prepare	= samsung_drm_encoder_prepare,
+	.commit		= samsung_drm_encoder_commit,
+	.get_crtc	= samsung_drm_encoder_get_crtc,
+};
+
+static void samsung_drm_encoder_destroy(struct drm_encoder *encoder)
+{
+	struct samsung_drm_encoder *samsung_encoder =
+		to_samsung_encoder(encoder);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_encoder->manager->pipe = -1;
+
+	drm_encoder_cleanup(encoder);
+	encoder->dev->mode_config.num_encoder--;
+	kfree(samsung_encoder);
+}
+
+static struct drm_encoder_funcs samsung_encoder_funcs = {
+	.destroy = samsung_drm_encoder_destroy,
+};
+
+struct drm_encoder *
+samsung_drm_encoder_create(struct drm_device *dev,
+			   struct samsung_drm_manager *manager,
+			   unsigned int possible_crtcs)
+{
+	struct drm_encoder *encoder;
+	struct samsung_drm_encoder *samsung_encoder;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (!manager || !possible_crtcs)
+		return NULL;
+
+	if (!manager->dev)
+		return NULL;
+
+	samsung_encoder = kzalloc(sizeof(*samsung_encoder), GFP_KERNEL);
+	if (!samsung_encoder) {
+		DRM_ERROR("failed to allocate encoder\n");
+		return NULL;
+	}
+
+	samsung_encoder->manager = manager;
+	encoder = &samsung_encoder->drm_encoder;
+	encoder->possible_crtcs = possible_crtcs;
+
+	DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
+
+	drm_encoder_init(dev, encoder, &samsung_encoder_funcs,

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +10 -0
+			DRM_MODE_ENCODER_TMDS);
+
+	drm_encoder_helper_add(encoder, &samsung_encoder_helper_funcs);
+
+	DRM_DEBUG_KMS("encoder has been created\n");
+
+	return encoder;
+}
+
+struct samsung_drm_manager *samsung_drm_get_manager(struct drm_encoder

*encoder)

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +11 -0
+{
+	return to_samsung_encoder(encoder)->manager;
+}
+
+void samsung_drm_fn_encoder(struct drm_crtc *crtc, void *data,
+			    void (*fn)(struct drm_encoder *, void *))
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_encoder *encoder;
+
+	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)

{

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +12 -0
+		if (encoder->crtc != crtc)
+			continue;
+
+		fn(encoder, data);
+	}
+}
+
+void samsung_drm_enable_vblank(struct drm_encoder *encoder, void *data)
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 218

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +6 -0
+	int crtc = *(int *)data;
+
+	if (manager->pipe == -1)
+		manager->pipe = crtc;
+
+	/* old_crtc checking needs? FIXME!!! */

Is this still pertient?

I will remove this comment after looking over more. Thank you.

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +6 -0
+
+	if (manager_ops->enable_vblank)
+		manager_ops->enable_vblank(manager->dev);
+}
+
+void samsung_drm_disable_vblank(struct drm_encoder *encoder, void

*data)

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 213

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +5 -0
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_manager_ops *manager_ops = manager->ops;
+	int crtc = *(int *)data;

You don't want to check whether data is NULL before you derefernce it?

Ok, get it. thank you.

Quoted 11 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 218

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +5 -0
+
+	if (manager->pipe == -1)
+		manager->pipe = crtc;
+
+	/* old_crtc checking needs? FIXME!!! */

I am not really sure what it means.. It probably means something to you - but
perhaps it might make sense to expand it in case somebody else wants to implement this?

As I mentioned above, I will remove this comment after looking over more. Thank you.

Quoted 17 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +6 -0
+
+	if (manager_ops->disable_vblank)
+		manager_ops->disable_vblank(manager->dev);
+}
+
+void samsung_drm_encoder_crtc_commit(struct drm_encoder *encoder, void

*data)

drivers/gpu/drm/samsung/samsung_drm_encoder.c

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +9 -0
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+
+	overlay_ops->commit(manager->dev);
+}
+
+void samsung_drm_encoder_crtc_mode_set(struct drm_encoder *encoder,

void *data)

Quoted 12 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.c line 259

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +10 -0
+{
+	struct samsung_drm_manager *manager =
+		to_samsung_encoder(encoder)->manager;
+	struct samsung_drm_overlay_ops *overlay_ops = manager->overlay_ops;
+	struct samsung_drm_overlay *overlay = data;
+
+	overlay_ops->mode_set(manager->dev, overlay);
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");

You don't want to include the rest of the authors?

Definitely no. I will add other authors. Thank you.

Quoted 35 lines

Review

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.c new file +2 -0
+MODULE_DESCRIPTION("Samsung SoC DRM Encoder Driver");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_encoder.h

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 8

Quoted 13 lines

new file mode 100644
index 0000000..99040b2

drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +8 -0
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 12 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_encoder.h

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +10 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_ENCODER_H_
+#define _SAMSUNG_DRM_ENCODER_H_
+
+struct samsung_drm_manager;
+
+struct drm_encoder *samsung_drm_encoder_create(struct drm_device *dev,
+					       struct samsung_drm_manager

*mgr,

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.h

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +6 -0
+					       unsigned int possible_crtcs);
+struct samsung_drm_manager *
+samsung_drm_get_manager(struct drm_encoder *encoder);
+void samsung_drm_fn_encoder(struct drm_crtc *crtc, void *data,
+			    void (*fn)(struct drm_encoder *, void *));
+void samsung_drm_enable_vblank(struct drm_encoder *encoder, void

*data);

Quoted 41 lines

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 41

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+void samsung_drm_disable_vblank(struct drm_encoder *encoder, void

*data);

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 42

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+void samsung_drm_encoder_crtc_commit(struct drm_encoder *encoder, void

*data);

drivers/gpu/drm/samsung/samsung_drm_encoder.h line 43

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +1 -0
+void samsung_drm_encoder_crtc_mode_set(struct drm_encoder *encoder,

void *data);

Review

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_encoder.h new file +2 -0
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_fb.c

drivers/gpu/drm/samsung/samsung_drm_fb.c line 8

Quoted 13 lines

new file mode 100644
index 0000000..f087ecf

drivers/gpu/drm/samsung/samsung_drm_fb.c new file +8 -0
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_fb.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_fb.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_fb.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_fb.c line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_fb.c line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_fb.c line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_fb.c line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_fb.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_fb.c line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_fb.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 28 lines

drivers/gpu/drm/samsung/samsung_drm_fb.c line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_fb.c

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +12 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_fb.h"
+#include "samsung_drm_buf.h"
+#include "samsung_drm_gem.h"
+
+#define to_samsung_fb(x)	container_of(x, struct samsung_drm_fb,

fb)

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +13 -0
+
+struct samsung_drm_fb {
+	struct drm_framebuffer		fb;
+	struct samsung_drm_gem_obj	*samsung_gem_obj;
+
+	unsigned int			fb_size;
+	dma_addr_t			paddr;
+	void __iomem			*vaddr;
+};
+
+static void samsung_drm_fb_destroy(struct drm_framebuffer *fb)
+{
+	struct samsung_drm_fb *samsung_fb = to_samsung_fb(fb);
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fb.c line 55

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +6 -0
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	drm_framebuffer_cleanup(fb);
+
+	/* default framebuffer has no gem object so it releases buffer. */

What is 'it' ?

Please, ignore 'it'. and I will correct this comment. Thank you.

Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fb.c line 60

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +5 -0
+	if (!samsung_fb->samsung_gem_obj)
+		samsung_drm_buf_destroy(fb->dev,
+				samsung_fb->samsung_gem_obj->entry);
+
+	kfree(samsung_fb);

samsung_fb = NULL;

Thank you.

Quoted 85 lines
Quoted 74 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +74 -0
+}
+
+static int samsung_drm_fb_create_handle(struct drm_framebuffer *fb,
+					struct drm_file *file_priv,
+					unsigned int *handle)
+{
+	struct samsung_drm_fb *samsung_fb = to_samsung_fb(fb);
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return drm_gem_handle_create(file_priv,
+					&samsung_fb->samsung_gem_obj->base,
+					handle);
+}
+
+static int samsung_drm_fb_dirty(struct drm_framebuffer *fb,
+				struct drm_file *file_priv, unsigned flags,
+				unsigned color, struct drm_clip_rect *clips,
+				unsigned num_clips)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	/*
+	 * update framebuffer and its hardware.
+	 * - this callback would be called by user application
+	 *	with DRM_IOCTL_MODE_DIRTYFB command.
+	 *
+	 * ps. Userspace can notify the driver via this callback
+	 * that an area of the framebuffer has been changed then should
+	 * be flushed to the display hardware.
+	 */
+
+	return 0;
+}
+
+static struct drm_framebuffer_funcs samsung_drm_fb_funcs = {
+	.destroy	= samsung_drm_fb_destroy,
+	.create_handle	= samsung_drm_fb_create_handle,
+	.dirty		= samsung_drm_fb_dirty,
+};
+
+static struct drm_framebuffer *
+samsung_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev,
+		    struct drm_mode_fb_cmd *mode_cmd)
+{
+	struct samsung_drm_fb *samsung_fb;
+	struct drm_framebuffer *fb;
+	struct samsung_drm_gem_obj *samsung_gem_obj = NULL;
+	struct drm_gem_object *obj;
+	unsigned int size;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mode_cmd->pitch = max(mode_cmd->pitch,
+			mode_cmd->width * (mode_cmd->bpp >> 3));
+
+	DRM_LOG_KMS("drm fb create(%dx%d)\n",
+			mode_cmd->width, mode_cmd->height);
+
+	samsung_fb = kzalloc(sizeof(*samsung_fb), GFP_KERNEL);
+	if (!samsung_fb) {
+		DRM_ERROR("failed to allocate samsung drm framebuffer.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	fb = &samsung_fb->fb;
+	ret = drm_framebuffer_init(dev, fb, &samsung_drm_fb_funcs);
+	if (ret) {
+		DRM_ERROR("failed to initialize framebuffer.\n");
+		goto err_init;
+	}
+
+	DRM_LOG_KMS("create: fb id: %d\n", fb->base.id);

drivers/gpu/drm/samsung/samsung_drm_fb.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +10 -0
+
+	size = mode_cmd->pitch * mode_cmd->height;
+
+	/*
+	 * mode_cmd->handle could be pointer to a buffer allocated by user
+	 * application using KMS library.
+	 */
+	if (!mode_cmd->handle) {
+		/*
+		 * in case that file_priv is NULL, it allocates only buffer

and

Quoted 15 lines
Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +5 -0
+		 * this buffer would be used for default framebuffer.
+		 */
+		if (!file_priv) {
+			struct samsung_drm_buf_entry *entry;
+

drivers/gpu/drm/samsung/samsung_drm_fb.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +10 -0
+			entry = samsung_drm_buf_create(dev, size);
+			if (IS_ERR(entry)) {
+				ret = PTR_ERR(entry);
+				goto err_buf_create;
+			}
+
+			samsung_fb->vaddr = entry->vaddr;
+			samsung_fb->paddr = entry->paddr;
+
+			DRM_LOG_KMS("default fb: paddr = 0x%x, size =

0x%x\n",

Quoted 27 lines

drivers/gpu/drm/samsung/samsung_drm_fb.c

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +5 -0
+					entry->paddr, size);
+
+			goto out;
+		} else {
+			samsung_gem_obj = samsung_drm_gem_create(file_priv,

dev,

Quoted 21 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +9 -0
+							size,
+							&mode_cmd->handle);
+			if (IS_ERR(samsung_gem_obj)) {
+				ret = PTR_ERR(samsung_gem_obj);
+				goto err_gem_create;
+			}
+		}
+	} else {
+		obj = drm_gem_object_lookup(dev, file_priv, mode_cmd-

handle);

drivers/gpu/drm/samsung/samsung_drm_fb.c new file +11 -0
+		if (!obj) {
+			DRM_ERROR("failed to lookup gem object.\n");
+			goto err_lookup;
+		}
+
+		samsung_gem_obj = to_samsung_gem_obj(obj);
+
+		drm_gem_object_unreference_unlocked(obj);
+	}
+
+	/*
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fb.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +8 -0
+	 * in case of getting samsung_gem_obj from either handle or
+	 * new creation.
+	 */
+	samsung_fb->vaddr = samsung_gem_obj->entry->vaddr;
+	samsung_fb->paddr = samsung_gem_obj->entry->paddr;
+
+	DRM_LOG_KMS("paddr = 0x%x, size = 0x%x, gem object = 0x%x\n",
+			samsung_fb->paddr, size,

(u32)&samsung_gem_obj->base);

Quoted 4 lines

Why truncating it to be 4GB? Is it potentially possible that this could run a machine with 5GB?

You are right. I will correct it. thank you.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +7 -0
+
+out:
+	samsung_fb->samsung_gem_obj = samsung_gem_obj;
+	samsung_fb->fb_size = size;
+
+	drm_helper_mode_fill_fb_struct(fb, mode_cmd);
+
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fb.c line 204

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +5 -0
+	return fb;
+
+err_lookup:
+err_gem_create:
+err_buf_create:

Why don't you just coalesce them all together and call it:
err:

Ok, get it. your saying is more clean. Thank you.

Quoted 11 lines

drivers/gpu/drm/samsung/samsung_drm_fb.c

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +11 -0
+	drm_framebuffer_cleanup(fb);
+
+err_init:
+	kfree(samsung_fb);
+
+	return ERR_PTR(ret);
+}
+
+struct drm_framebuffer *samsung_drm_fb_create(struct drm_device *dev,
+					      struct drm_file *file_priv,
+					      struct drm_mode_fb_cmd

*mode_cmd)

Quoted 81 lines
Quoted 30 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +30 -0
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return samsung_drm_fb_init(file_priv, dev, mode_cmd);
+}
+
+void samsung_drm_fb_update_buf_off(struct drm_framebuffer *fb,
+				   unsigned int x, unsigned int y,
+				   struct samsung_drm_buffer_info *info)
+{
+	struct samsung_drm_fb *samsung_fb = to_samsung_fb(fb);
+	unsigned long offset;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	offset = x * (fb->bits_per_pixel >> 3);
+	offset += y * fb->pitch;
+
+	info->base_addr = samsung_fb->paddr;
+	info->vaddr = samsung_fb->vaddr + offset;
+	info->paddr = samsung_fb->paddr + offset;
+
+	DRM_DEBUG_KMS("updated vaddr = 0x%x, paddr = 0x%x, offset = 0x%x\n",
+			(unsigned int)info->vaddr,
+			(unsigned int)info->paddr,
+			(unsigned int)offset);
+}
+
+static struct drm_mode_config_funcs samsung_drm_mode_config_funcs = {
+	.fb_create = samsung_drm_fb_create,

drivers/gpu/drm/samsung/samsung_drm_fb.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +10 -0
+};
+
+void samsung_drm_mode_config_init(struct drm_device *dev)
+{
+	dev->mode_config.min_width = 0;
+	dev->mode_config.min_height = 0;
+
+	/*
+	 * It sets max width and height as default value(4096x4096).
+	 * this value would be used to check for framebuffer size

limitation

Review

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fb.c new file +7 -0
+	 * at drm_mode_addfb().
+	 */
+	dev->mode_config.max_width = 4096;
+	dev->mode_config.max_height = 4096;
+
+	dev->mode_config.funcs = &samsung_drm_mode_config_funcs;
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_fb.h

drivers/gpu/drm/samsung/samsung_drm_fb.h line 8

Quoted 13 lines

new file mode 100644
index 0000000..6256089

drivers/gpu/drm/samsung/samsung_drm_fb.h new file +8 -0
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_fb.h line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_fb.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_fb.h line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_fb.h line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_fb.h line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_fb.h line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_fb.h line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_fb.h line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_fb.h line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_fb.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 13 lines

drivers/gpu/drm/samsung/samsung_drm_fb.h line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +11 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_FB_H_
+#define _SAMSUNG_DRM_FB_H
+
+struct samsung_drm_buffer_info {
+	unsigned long base_addr;
+	dma_addr_t paddr;
+	void __iomem *vaddr;
+};
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fb.h

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +8 -0
+
+void samsung_drm_fb_update_buf_off(struct drm_framebuffer *fb,
+				   unsigned int x, unsigned int y,
+				   struct samsung_drm_buffer_info *info);
+
+struct drm_framebuffer *samsung_drm_fb_create(struct drm_device *dev,
+					      struct drm_file *filp,
+					      struct drm_mode_fb_cmd

*mode_cmd);

Quoted 37 lines

Review

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fb.h new file +4 -0
+
+void samsung_drm_mode_config_init(struct drm_device *dev);
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_fbdev.c

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 8

Quoted 13 lines

new file mode 100644
index 0000000..1c46bc6

drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
@@ -0,0 +1,409 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 15

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 16

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 19

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 31 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 24

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

drivers/gpu/drm/samsung/samsung_drm_fbdev.c

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +12 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_crtc.h"
+#include "drm_fb_helper.h"
+#include "drm_crtc_helper.h"
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_fb.h"
+
+#define to_samsung_fbdev(x)	container_of(x, struct

samsung_drm_fbdev,\

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 48

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +12 -0
+				drm_fb_helper)
+
+struct samsung_drm_fbdev {
+	struct drm_fb_helper	drm_fb_helper;
+	struct drm_framebuffer	*fb;
+};
+
+static inline unsigned int chan_to_field(unsigned int chan,
+					 struct fb_bitfield *bf)
+{
+	chan &= 0xffff;
+	chan >>= 16 - bf->length;

Any chance that bf->length can be bigger than 16? And cause this to return um wrong vlaues?

Quoted 2 lines

perhaps chan >>= (16 - max(16,bf->length));

Ok, get it. thank you.

Quoted 8 lines

?

drivers/gpu/drm/samsung/samsung_drm_fbdev.c

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +7 -0
+
+	return chan << bf->offset;
+}
+
+static int samsung_drm_fbdev_setcolreg(unsigned regno, unsigned red,
+				       unsigned green, unsigned blue,
+				       unsigned transp, struct fb_info

*info)

Quoted 10 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 63

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
+{
+	unsigned int val;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	switch (info->fix.visual) {
+	case FB_VISUAL_TRUECOLOR:
+		if (regno < 16) {

Not <=?

Ah, you are right. 16bit is high color. thank you.

Quoted 11 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 71

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
+			u32 *pal = info->pseudo_palette;
+
+			val = chan_to_field(red, &info->var.red);
+			val |= chan_to_field(green, &info->var.green);
+			val |= chan_to_field(blue, &info->var.blue);
+
+			pal[regno] = val;
+		}

so if regno > 16 then we still return 0. Should we return -EINVAL instead.

Ok, get it. thank you.

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 74

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +3 -0
+		break;
+	default:
+		return 1;

-EINVAL?

Thank you.

Quoted 43 lines
Quoted 18 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +18 -0
+	}
+
+	return 0;
+}
+
+static struct fb_ops samsung_drm_fb_ops = {
+	.owner		= THIS_MODULE,
+	.fb_fillrect	= cfb_fillrect,
+	.fb_copyarea	= cfb_copyarea,
+	.fb_imageblit	= cfb_imageblit,
+	.fb_check_var	= drm_fb_helper_check_var,
+	.fb_set_par	= drm_fb_helper_set_par,
+	.fb_setcolreg	= samsung_drm_fbdev_setcolreg,
+	.fb_blank	= drm_fb_helper_blank,
+	.fb_pan_display	= drm_fb_helper_pan_display,
+	.fb_setcmap	= drm_fb_helper_setcmap,
+};
+

drivers/gpu/drm/samsung/samsung_drm_fbdev.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +10 -0
+static void samsung_drm_fbdev_update(struct drm_fb_helper *helper,
+				     struct drm_framebuffer *fb,
+				     unsigned int fb_width,
+				     unsigned int fb_height)
+{
+	struct fb_info *fbi = helper->fbdev;
+	struct drm_device *dev = helper->dev;
+	struct samsung_drm_fbdev *samsung_fb = to_samsung_fbdev(helper);
+	struct samsung_drm_buffer_info buffer_info;
+	unsigned int size = fb_width * fb_height * (fb->bits_per_pixel >>

3);

Quoted 14 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +9 -0
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	samsung_fb->fb = fb;
+
+	drm_fb_helper_fill_fix(fbi, fb->pitch, fb->depth);
+	drm_fb_helper_fill_var(fbi, helper, fb_width, fb_height);
+
+	samsung_drm_fb_update_buf_off(fb, fbi->var.xoffset, fbi-

var.yoffset,

drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +4 -0
+			&buffer_info);
+
+	dev->mode_config.fb_base = buffer_info.base_addr;
+
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
+	fbi->screen_base = buffer_info.vaddr;
+	fbi->screen_size = size;
+	fbi->fix.smem_start = buffer_info.paddr;
+	fbi->fix.smem_len = size;
+}
+
+static int samsung_drm_fbdev_create(struct drm_fb_helper *helper,
+				    struct drm_fb_helper_surface_size

*sizes)

Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +24 -0
+{
+	struct samsung_drm_fbdev *samsung_fbdev = to_samsung_fbdev(helper);
+	struct drm_device *dev = helper->dev;
+	struct fb_info *fbi;
+	struct drm_mode_fb_cmd mode_cmd = { 0 };
+	struct platform_device *pdev = dev->platformdev;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	DRM_DEBUG_KMS("surface width(%d), height(%d) and bpp(%d\n",
+			sizes->surface_width, sizes->surface_height,
+			sizes->surface_bpp);
+
+	mode_cmd.width = sizes->surface_width;
+	mode_cmd.height = sizes->surface_height;
+	mode_cmd.bpp = sizes->surface_bpp;
+	mode_cmd.depth = sizes->surface_depth;
+
+	mutex_lock(&dev->struct_mutex);
+
+	fbi = framebuffer_alloc(0, &pdev->dev);
+	if (!fbi) {
+		DRM_ERROR("failed to allocate fb info.\n");
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 153

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +6 -0
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	samsung_fbdev->fb = samsung_drm_fb_create(dev, NULL, &mode_cmd);
+	if (IS_ERR(samsung_fbdev->fb)) {

You probably want to do IS_ERR_OR_NULL?

Ok, that's more safe. thank you.

Quoted 7 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 155

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +2 -0
+		DRM_ERROR("failed to create drm dramebuffer.\n");
+		ret = PTR_ERR(samsung_fbdev->fb);

framebuffer_release ?

drivers/gpu/drm/samsung/samsung_drm_fbdev.c

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +3 -0
+		goto out;
+	}
+

I missed it. thank you.

Quoted 12 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 167

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +9 -0
+	helper->fb = samsung_fbdev->fb;
+	helper->fbdev = fbi;
+
+	fbi->par = helper;
+	fbi->flags = FBINFO_FLAG_DEFAULT;
+	fbi->fbops = &samsung_drm_fb_ops;
+
+	ret = fb_alloc_cmap(&fbi->cmap, 256, 0);
+	if (ret) {

framebuffer_release ?

Also. Thank you.

Quoted 24 lines

Or just add a new label that will make that call.

Quoted 22 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +22 -0
+		DRM_ERROR("failed to allocate cmap.\n");
+		goto out;
+	}
+
+	samsung_drm_fbdev_update(helper, helper->fb, sizes->fb_width,
+			sizes->fb_height);
+
+out:
+	mutex_unlock(&dev->struct_mutex);
+	return ret;
+}
+
+static bool
+samsung_drm_fbdev_is_samefb(struct drm_framebuffer *fb,
+			    struct drm_fb_helper_surface_size *sizes)
+{
+	if (fb->width != sizes->surface_width)
+		return false;
+	if (fb->height != sizes->surface_height)
+		return false;
+	if (fb->bits_per_pixel != sizes->surface_bpp)
+		return false;
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
+	if (fb->depth != sizes->surface_depth)
+		return false;
+
+	return true;
+}
+
+static int samsung_drm_fbdev_recreate(struct drm_fb_helper *helper,
+				      struct drm_fb_helper_surface_size

*sizes)

Quoted 54 lines
Quoted 54 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +54 -0
+{
+	struct drm_device *dev = helper->dev;
+	struct samsung_drm_fbdev *samsung_fbdev = to_samsung_fbdev(helper);
+	struct drm_framebuffer *fb = samsung_fbdev->fb;
+	struct drm_mode_fb_cmd mode_cmd = { 0 };
+
+	if (helper->fb != fb) {
+		DRM_ERROR("drm framebuffer is different\n");
+		return -EINVAL;
+	}
+
+	if (samsung_drm_fbdev_is_samefb(fb, sizes))
+		return 0;
+
+	mode_cmd.width = sizes->surface_width;
+	mode_cmd.height = sizes->surface_height;
+	mode_cmd.bpp = sizes->surface_bpp;
+	mode_cmd.depth = sizes->surface_depth;
+
+	if (fb->funcs->destroy)
+		fb->funcs->destroy(fb);
+
+	samsung_fbdev->fb = samsung_drm_fb_create(dev, NULL, &mode_cmd);
+	if (IS_ERR(samsung_fbdev->fb)) {
+		DRM_ERROR("failed to allocate fb.\n");
+		return PTR_ERR(samsung_fbdev->fb);
+	}
+
+	helper->fb = samsung_fbdev->fb;
+	samsung_drm_fbdev_update(helper, helper->fb, sizes->fb_width,
+			sizes->fb_height);
+
+	return 0;
+}
+
+static int samsung_drm_fbdev_probe(struct drm_fb_helper *helper,
+				   struct drm_fb_helper_surface_size *sizes)
+{
+	int ret = 0;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (!helper->fb) {
+		ret = samsung_drm_fbdev_create(helper, sizes);
+		if (ret < 0) {
+			DRM_ERROR("failed to create fbdev.\n");
+			return ret;
+		}
+
+		/*
+		 * fb_helper expects a value more than 1 if succeed
+		 * because register_framebuffer() should be called.
+		 */
+		ret = 1;
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 257

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +6 -0
+	} else {
+		ret = samsung_drm_fbdev_recreate(helper, sizes);
+		if (ret < 0) {
+			DRM_ERROR("failed to reconfigure fbdev\n");
+			return ret;
+		}

No need to do the same thing you did before?

Ah, I will correct it. thank you.

Quoted 7 lines
Quoted 2 lines

ret = 1?

This code must be strange. please, see new_fb = (*fb_helper->funcs->fb_prob)(fb_helper, &sizes) of drm_fb_helper_single_fb_probe(). drm_fb_helper.c requires three return values.

So confusing...

Quoted 263 lines
Quoted 29 lines
Quoted 29 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +28 -0
+	}
+
+	return ret;
+}
+
+static struct drm_fb_helper_funcs samsung_drm_fb_helper_funcs = {
+	.fb_probe =	samsung_drm_fbdev_probe,
+};
+
+int samsung_drm_fbdev_init(struct drm_device *dev)
+{
+	struct samsung_drm_fbdev *fbdev;
+	struct samsung_drm_private *private = dev->dev_private;
+	struct drm_fb_helper *helper;
+	unsigned int num_crtc;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (!dev->mode_config.num_crtc || !dev->mode_config.num_connector)
+		return 0;
+
+	fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
+	if (!fbdev) {
+		DRM_ERROR("failed to allocate drm fbdev.\n");
+		return -ENOMEM;
+	}
+
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 291

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +6 -0
+	private->fb_helper = helper = &fbdev->drm_fb_helper;
+	helper->funcs = &samsung_drm_fb_helper_funcs;
+
+	num_crtc = dev->mode_config.num_crtc;
+
+	ret = drm_fb_helper_init(dev, helper, num_crtc, 4);

Is that value '4'

Yes, this driver is going to provide maximum four connectors.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +7 -0
+	if (ret < 0) {
+		DRM_ERROR("failed to initialize drm fb helper.\n");
+		goto fail;
+	}
+
+	ret = drm_fb_helper_single_add_all_connectors(helper);
+	if (ret < 0) {
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 304

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +6 -0
+		DRM_ERROR("failed to register drm_fb_helper_connector.\n");
+		goto fail;
+
+	}
+
+	ret = drm_fb_helper_initial_config(helper, 32);

and '32' should perhaps be in #defines?

Ok, get it. thank you.

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +2 -0
+	if (ret < 0) {
+		DRM_ERROR("failed to set up hw configuration.\n");

Which I think leaks memory. The drm_fb_helper_single_add_all_connectors does a bunch of kzallocs. Should you free them here?

Ah, you are right. thank you.

Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +21 -0
+		goto fail;
+	}
+
+	return 0;
+
+fail:
+	private->fb_helper = NULL;
+	kfree(fbdev);
+
+	return ret;
+}
+
+static void samsung_drm_fbdev_destroy(struct drm_device *dev,
+				      struct drm_fb_helper *fb_helper)
+{
+	struct drm_framebuffer *fb;
+	struct fb_info *info;
+
+	/* release drm framebuffer and real buffer */
+	if (fb_helper->fb && fb_helper->fb->funcs) {
+		fb = fb_helper->fb;
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 333

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +6 -0
+		if (fb->funcs->destroy)
+			fb->funcs->destroy(fb);
+	}
+
+	/* release linux framebuffer */
+	if (fb_helper->fbdev) {

You can declare the 'info' here.

Ok, get it. thank you.

Quoted 55 lines
Quoted 55 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +55 -0
+		info = fb_helper->fbdev;
+		unregister_framebuffer(info);
+		if (info->cmap.len)
+			fb_dealloc_cmap(&info->cmap);
+		framebuffer_release(info);
+	}
+
+	drm_fb_helper_fini(fb_helper);
+}
+
+void samsung_drm_fbdev_fini(struct drm_device *dev)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+	struct samsung_drm_fbdev *fbdev;
+
+	if (!private || !private->fb_helper)
+		return;
+
+	fbdev = to_samsung_fbdev(private->fb_helper);
+
+	samsung_drm_fbdev_destroy(dev, private->fb_helper);
+	kfree(fbdev);
+	private->fb_helper = NULL;
+}
+
+void samsung_drm_fbdev_restore_mode(struct drm_device *dev)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+
+	if (!private || !private->fb_helper)
+		return;
+
+	drm_fb_helper_restore_fbdev_mode(private->fb_helper);
+}
+
+int samsung_drm_fbdev_reinit(struct drm_device *dev)
+{
+	struct samsung_drm_private *private = dev->dev_private;
+	int ret;
+
+	if (!private)
+		return -EINVAL;
+
+	if (!dev->mode_config.num_connector) {
+		samsung_drm_fbdev_fini(dev);
+		return 0;
+	}
+
+	if (private->fb_helper) {
+		struct drm_fb_helper *fb_helper = private->fb_helper;
+
+		drm_fb_helper_fini(fb_helper);
+
+		ret = drm_fb_helper_init(dev, fb_helper,
+				dev->mode_config.num_crtc, 4);
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
+		if (ret < 0) {
+			DRM_ERROR("failed to initialize drm fb helper\n");
+			return ret;
+		}
+
+		ret = drm_fb_helper_single_add_all_connectors(fb_helper);
+		if (ret < 0) {
+			DRM_ERROR("failed to add fb helper to

connectors\n");

Quoted 2 lines

You should free what drm_fb_helper_init allocated

Ok, get it. thank you.

Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.c line 401

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +5 -0
+			return ret;
+		}
+
+		ret = drm_fb_helper_initial_config(fb_helper, 32);
+		if (ret < 0) {

.. and free what drm_fb_helper_single_add_all_connectors allocated too.

Ok, thank you.

Quoted 42 lines

Review

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.c new file +8 -0
+			DRM_ERROR("failed to set up hw configuration.\n");
+			return ret;
+		}
+	} else
+		ret = samsung_drm_fbdev_init(dev);
+
+	return ret;
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_fbdev.h

Quoted 5 lines

new file mode 100644
index 0000000..3ef4e0d

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 9

Quoted 9 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +9 -0
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *	SeungWoo Kim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 11

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 12

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 13

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 16

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 17

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 20

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 21

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 23

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 33 lines

drivers/gpu/drm/samsung/samsung_drm_fbdev.h line 25

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Review

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_fbdev.h new file +12 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_FBDEV_H_
+#define _SAMSUNG_DRM_FBDEV_H_
+
+int samsung_drm_fbdev_init(struct drm_device *dev);
+int samsung_drm_fbdev_reinit(struct drm_device *dev);
+void samsung_drm_fbdev_fini(struct drm_device *dev);
+void samsung_drm_fbdev_restore_mode(struct drm_device *dev);
+
+#endif
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_fimd.c

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 7

Quoted 12 lines

new file mode 100644
index 0000000..d823e19

drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +7 -0
@@ -0,0 +1,643 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics Co.Ltd
+ * Authors:
+ *	Joonyoung Shim <[email protected]>
+ *	Inki Dae <[email protected]>
+ *
+ * This program is free software; you can redistribute  it and/or

modify it

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 8

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +1 -0
+ * under  the terms of  the GNU General  Public License as published by

the

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +1 -0
+ * Free Software Foundation;  either version 2 of the  License, or (at

your

Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 12

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +3 -0
+ * option) any later version.
+ *
+ */

What is 'FIMD'? Is there an explanation of what that stands for?

That's Fully Interactive Mobile Display and this is display controller.

OK, can you include that comment and perhaps a link to the specification? (if such thing exists).

Quoted 1,048 lines
Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +18 -0
+
+/*
+ * TODO list
+ *  - Code cleanup(FIXME and TODO parts)
+ *  - Clock gating and Power management
+ *  - Writeback feature
+ */
+
+#include "drmP.h"
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+
+#include <drm/samsung_drm.h>
+#include <plat/regs-fb-v4.h>
+
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 36

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +6 -0
+#include "samsung_drm_drv.h"
+#include "samsung_drm_fbdev.h"
+#include "samsung_drm_crtc.h"
+
+/* irq_flags bits */
+#define FIMD_VSYNC_IRQ_EN	0

Which is just one value right? 0?

This definition isn't needed. so I will remove it and directly use 0 instead.

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 41

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +5 -0
+
+#define VIDOSD_A(win)	(VIDOSD_BASE + 0x00 + (win) * 16)
+#define VIDOSD_B(win)	(VIDOSD_BASE + 0x04 + (win) * 16)
+#define VIDOSD_C(win)	(VIDOSD_BASE + 0x08 + (win) * 16)
+#define VIDOSD_D(win)	(VIDOSD_BASE + 0x0C + (win) * 16)

What about a comment for these very important low-level values?

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +1 -0
+

I think it's good to leave some comments to them also. I will add some comments. thank you.

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 44

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +2 -0
+#define VIDWx_BUF_START(win, buf)	(VIDW_BUF_START(buf) + (win) * 8)
+#define VIDWx_BUF_END(win, buf)		(VIDW_BUF_END(buf) + (win)

* 8)

drivers/gpu/drm/samsung/samsung_drm_fimd.c

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +5 -0
+#define VIDWx_BUF_SIZE(win, buf)	(VIDW_BUF_SIZE(buf) + (win) * 4)
+
+#define WINDOWS_NR	5
+
+#define get_fimd_context(dev)

platform_get_drvdata(to_platform_device(dev))

Quoted 10 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 56

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +7 -0
+
+struct fimd_win_data {
+	unsigned int		offset_x;
+	unsigned int		offset_y;
+	unsigned int		width;
+	unsigned int		height;
+	unsigned int		paddr;

dma_addr_t ?

Get it. thank you.

Quoted 4 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 58

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +2 -0
+	void __iomem		*vaddr;
+	unsigned int		end_buf_off;

buf_off ?

I have a feeling that this variable could be removed. thank you.

Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 65

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +7 -0
+	unsigned int		buf_offsize;
+	unsigned int		line_size;	/* bytes */
+};
+
+struct fimd_context {
+	struct samsung_drm_subdrv	subdrv;
+	int				irq_no;

Just 'irq'

Ok, get it.

Quoted 74 lines
Quoted 74 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +73 -0
+	struct drm_crtc			*crtc;
+	struct clk			*bus_clk;
+	struct clk			*lcd_clk;
+	struct resource			*regs_res;
+	void __iomem			*regs;
+	struct fimd_win_data		win_data[WINDOWS_NR];
+	unsigned int			clkdiv;
+	unsigned int			default_win;
+	unsigned int			bpp;
+	unsigned long			irq_flags;
+	u32				vidcon0;
+	u32				vidcon1;
+
+	struct fb_videomode		*timing;
+};
+
+static bool fimd_display_is_connected(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+
+	/* TODO. */
+
+	return true;
+}
+
+static void *fimd_get_timing(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+
+	return ctx->timing;
+}
+
+static int fimd_check_timing(struct device *dev, void *timing)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+
+	/* TODO. */
+
+	return 0;
+}
+
+static int fimd_display_power_on(struct device *dev, int mode)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+
+	/* TODO. */
+
+	return 0;
+}
+
+static struct samsung_drm_display fimd_display = {
+	.type = SAMSUNG_DISPLAY_TYPE_LCD,
+	.is_connected = fimd_display_is_connected,
+	.get_timing = fimd_get_timing,
+	.check_timing = fimd_check_timing,
+	.power_on = fimd_display_power_on,
+};
+
+static void fimd_commit(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	struct fb_videomode *timing = ctx->timing;
+	u32 val;
+
+	/* vidcon0 */
+	val = ctx->vidcon0;
+	val &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
+
+	if (ctx->clkdiv > 1)
+		val |= VIDCON0_CLKVAL_F(ctx->clkdiv - 1) | VIDCON0_CLKDIR;
+	else
+		val &= ~VIDCON0_CLKDIR;	/* 1:1 clock */
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 143

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +5 -0
+
+	val |= VIDCON0_ENVID | VIDCON0_ENVID_F;
+	writel(val, regs + VIDCON0);
+
+	/* vidcon1 */

That comment is bit useless.. It is clear what you are doing.

Ok, get it. thank you.

Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 146

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +3 -0
+	writel(ctx->vidcon1, regs + VIDCON1);
+
+	/* vidtcon0 */

Ah, so the order is important. Perhaps you should
just have a comment before you do any writes that
enumarates in which order it should be done?

The order hasn't implications for working. no problem if this setting is done before dma of fimd is enabled. Ah.. such comments should be added. thank you.

Quoted 3 lines

And why the order is important (in case the future chipsets have it fixed/changed).

I understood what you mean. Thank you for your pointing.

Quoted 126 lines
Quoted 113 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +113 -0
+	val = VIDTCON0_VBPD(timing->upper_margin - 1) |
+	       VIDTCON0_VFPD(timing->lower_margin - 1) |
+	       VIDTCON0_VSPW(timing->vsync_len - 1);
+	writel(val, regs + VIDTCON0);
+
+	/* vidtcon1 */
+	val = VIDTCON1_HBPD(timing->left_margin - 1) |
+	       VIDTCON1_HFPD(timing->right_margin - 1) |
+	       VIDTCON1_HSPW(timing->hsync_len - 1);
+	writel(val, regs + VIDTCON1);
+
+	/* vidtcon2 */
+	val = VIDTCON2_LINEVAL(timing->yres - 1) |
+	       VIDTCON2_HOZVAL(timing->xres - 1);
+	writel(val, regs + VIDTCON2);
+}
+
+static int fimd_enable_vblank(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	u32 val;
+
+	if (!test_and_set_bit(FIMD_VSYNC_IRQ_EN, &ctx->irq_flags)) {
+		val = readl(regs + VIDINTCON0);
+
+		val |= VIDINTCON0_INT_ENABLE;
+		val |= VIDINTCON0_INT_FRAME;
+
+		val &= ~VIDINTCON0_FRAMESEL0_MASK;
+		val |= VIDINTCON0_FRAMESEL0_VSYNC;
+		val &= ~VIDINTCON0_FRAMESEL1_MASK;
+		val |= VIDINTCON0_FRAMESEL1_NONE;
+
+		writel(val, regs + VIDINTCON0);
+	}
+
+	return 0;
+}
+
+static void fimd_disable_vblank(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	u32 val;
+
+	if (test_and_clear_bit(FIMD_VSYNC_IRQ_EN, &ctx->irq_flags)) {
+		val = readl(regs + VIDINTCON0);
+
+		val &= ~VIDINTCON0_INT_FRAME;
+		val &= ~VIDINTCON0_INT_ENABLE;
+
+		writel(val, regs + VIDINTCON0);
+	}
+}
+
+static struct samsung_drm_manager_ops fimd_manager_ops = {
+	.commit = fimd_commit,
+	.enable_vblank = fimd_enable_vblank,
+	.disable_vblank = fimd_disable_vblank,
+};
+
+static void fimd_win_mode_set(struct device *dev,
+			      struct samsung_drm_overlay *overlay)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	struct fimd_win_data *win_data;
+
+	if (!overlay) {
+		dev_err(dev, "overlay is NULL\n");
+		return;
+	}
+
+	win_data = &ctx->win_data[ctx->default_win];
+
+	win_data->offset_x = overlay->offset_x;
+	win_data->offset_y = overlay->offset_y;
+	win_data->width = overlay->width;
+	win_data->height = overlay->height;
+	win_data->paddr = overlay->paddr;
+	win_data->vaddr = overlay->vaddr;
+	win_data->end_buf_off = overlay->end_buf_off * (ctx->bpp >> 3);
+	win_data->buf_offsize = overlay->buf_offsize * (ctx->bpp >> 3);
+	win_data->line_size = overlay->line_size * (ctx->bpp >> 3);
+}
+
+static void fimd_win_commit(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	struct fimd_win_data *win_data;
+	int win = ctx->default_win;
+	u32 val;
+
+	if (win < 0 || win > WINDOWS_NR)
+		return;
+
+	win_data = &ctx->win_data[win];
+
+	/* protect windows */
+	val = readl(regs + SHADOWCON);
+	val |= SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+
+	/* buffer start address */
+	val = win_data->paddr;
+	writel(val, regs + VIDWx_BUF_START(win, 0));
+
+	/* buffer end address */
+	val = win_data->paddr + win_data->end_buf_off;
+	writel(val, regs + VIDWx_BUF_END(win, 0));
+
+	/* buffer size */

drivers/gpu/drm/samsung/samsung_drm_fimd.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+	val = VIDW_BUF_SIZE_OFFSET(win_data->buf_offsize) |
+		VIDW_BUF_SIZE_PAGEWIDTH(win_data->line_size);
+	writel(val, regs + VIDWx_BUF_SIZE(win, 0));
+
+	/* OSD position */
+	val = VIDOSDxA_TOPLEFT_X(win_data->offset_x) |
+		VIDOSDxA_TOPLEFT_Y(win_data->offset_y);
+	writel(val, regs + VIDOSD_A(win));
+
+	val = VIDOSDxB_BOTRIGHT_X(win_data->offset_x + win_data->width - 1)

|

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 270

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +1 -0
+		VIDOSDxB_BOTRIGHT_Y(win_data->offset_y + win_data->height -

1);

Quoted 17 lines
Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +4 -0
+	writel(val, regs + VIDOSD_B(win));
+
+	/* TODO: OSD alpha */
+

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 284

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+	/* OSD size */
+	if (win != 3 && win != 4) {
+		u32 offset = VIDOSD_D(win);
+		if (win == 0)
+			offset = VIDOSD_C(win);
+		val = win_data->width * win_data->height;
+		writel(val, regs + offset);
+	}
+
+	/* FIXME: remove fixed values */

<nods> Yes.

That FIXME would be updated soon. :)

Quoted 72 lines
Quoted 72 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +72 -0
+	val = WINCONx_ENWIN;
+	val |= WINCON0_BPPMODE_24BPP_888;
+	val |= WINCONx_WSWP;
+	val |= WINCONx_BURSTLEN_16WORD;
+	writel(val, regs + WINCON(win));
+
+	/* TODO: colour key */
+
+	/* Enable DMA channel and unprotect windows */
+	val = readl(regs + SHADOWCON);
+	val |= SHADOWCON_CHx_ENABLE(win);
+	val &= ~SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+}
+
+static void fimd_win_disable(struct device *dev)
+{
+	struct fimd_context *ctx = get_fimd_context(dev);
+	void __iomem *regs = ctx->regs;
+	struct fimd_win_data *win_data;
+	int win = ctx->default_win;
+	u32 val;
+
+	if (win < 0 || win > WINDOWS_NR)
+		return;
+
+	win_data = &ctx->win_data[win];
+
+	/* protect windows */
+	val = readl(regs + SHADOWCON);
+	val |= SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+
+	/* wincon */
+	val = readl(regs + WINCON(win));
+	val &= ~WINCONx_ENWIN;
+	writel(val, regs + WINCON(win));
+
+	/* unprotect windows */
+	val = readl(regs + SHADOWCON);
+	val &= ~SHADOWCON_CHx_ENABLE(win);
+	val &= ~SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+}
+
+static struct samsung_drm_overlay_ops fimd_overlay_ops = {
+	.mode_set = fimd_win_mode_set,
+	.commit = fimd_win_commit,
+	.disable = fimd_win_disable,
+};
+
+/* for pageflip event */
+static void fimd_finish_pageflip(struct drm_device *drm_dev, int crtc)
+{
+	struct samsung_drm_private *dev_priv = drm_dev->dev_private;
+	struct drm_pending_vblank_event *e, *t;
+	struct timeval now;
+	unsigned long flags;
+
+	if (!dev_priv->pageflip_event)
+		return;
+
+	spin_lock_irqsave(&drm_dev->event_lock, flags);
+
+	list_for_each_entry_safe(e, t, &dev_priv->pageflip_event_list,
+			base.link) {
+		do_gettimeofday(&now);
+		e->event.sequence = 0;
+		e->event.tv_sec = now.tv_sec;
+		e->event.tv_usec = now.tv_usec;
+
+		list_move_tail(&e->base.link, &e->base.file_priv-
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 360

Quoted 5 lines

event_list);

drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +4 -0
+		wake_up_interruptible(&e->base.file_priv->event_wait);
+	}
+
+	drm_vblank_put(drm_dev, crtc);

You can make this call outside the spinlock. But it looks like pretty much everybody is doing it this way?

No problem to move it outside(to fimd_irq_handler) and spinlock is used only here. thank you.

Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +26 -0
+	dev_priv->pageflip_event = false;
+
+	spin_unlock_irqrestore(&drm_dev->event_lock, flags);
+}
+
+static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
+{
+	struct fimd_context *ctx = (struct fimd_context *)dev_id;
+	struct samsung_drm_subdrv *subdrv = &ctx->subdrv;
+	struct drm_device *drm_dev = subdrv->drm_dev;
+	struct device *dev = subdrv->manager.dev;
+	struct samsung_drm_manager *manager = &subdrv->manager;
+	void __iomem *regs = ctx->regs;
+	u32 val;
+
+	val = readl(regs + VIDINTCON1);
+
+	if (val & VIDINTCON1_INT_FRAME)
+		/* VSYNC interrupt */
+		writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
+
+	drm_handle_vblank(drm_dev, manager->pipe);
+	fimd_finish_pageflip(drm_dev, manager->pipe);
+
+	return IRQ_HANDLED;
+}
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 392

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +6 -0
+
+static int fimd_subdrv_probe(struct drm_device *drm_dev)
+{
+	struct drm_driver *drm_driver = drm_dev->driver;
+
+	drm_dev->irq_enabled = 1;

Hehe.. Just like that ,eh?

I will add some comments. :)

Quoted 6 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 398

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +6 -0
+
+	/* TODO. */
+
+	/* FIXME */
+	drm_dev->vblank_disable_allowed = 1;
+

Ditto.

Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +38 -0
+	return 0;
+}
+
+static void fimd_subdrv_remove(struct drm_device *drm_dev)
+{
+	struct drm_driver *drm_driver = drm_dev->driver;
+
+	/* TODO. */
+}
+
+static int fimd_calc_clkdiv(struct fimd_context *ctx,
+			    struct fb_videomode *timing)
+{
+	unsigned long clk = clk_get_rate(ctx->lcd_clk);
+	u32 retrace;
+	u32 clkdiv;
+	u32 best_framerate = 0;
+	u32 framerate;
+
+	retrace = timing->left_margin + timing->hsync_len +
+				timing->right_margin + timing->xres;
+	retrace *= timing->upper_margin + timing->vsync_len +
+				timing->lower_margin + timing->yres;
+
+	/* default framerate is 60Hz */
+	if (!timing->refresh)
+		timing->refresh = 60;
+
+	clk /= retrace;
+
+	for (clkdiv = 1; clkdiv < 0x100; clkdiv++) {
+		int tmp;
+
+		/* get best framerate */
+		framerate = clk / clkdiv;
+		tmp = timing->refresh - framerate;
+		if (tmp < 0) {
+			best_framerate = framerate;
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 442

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +6 -0
+			continue;
+		} else {
+			if (!best_framerate)
+				best_framerate = framerate;
+			else if (tmp < (best_framerate - framerate))
+				best_framerate = framerate ;

The ';' at the end should be moved.

Ah, get it. thank you.

Quoted 31 lines
Quoted 31 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +31 -0
+			break;
+		}
+	}
+
+	return clkdiv;
+}
+
+static void fimd_clear_win(struct fimd_context *ctx, int win)
+{
+	void __iomem *regs = ctx->regs;
+	u32 val;
+
+	writel(0, regs + WINCON(win));
+	writel(0, regs + VIDOSD_A(win));
+	writel(0, regs + VIDOSD_B(win));
+	writel(0, regs + VIDOSD_C(win));
+
+	if (win == 1 || win == 2)
+		writel(0, regs + VIDOSD_D(win));
+
+	val = readl(regs + SHADOWCON);
+	val &= ~SHADOWCON_WINx_PROTECT(win);
+	writel(val, regs + SHADOWCON);
+}
+
+static int __devinit fimd_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct fimd_context *ctx;
+	struct samsung_drm_subdrv *subdrv;
+	struct samsung_drm_fimd_pdata *pdata;
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 479

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +6 -0
+	struct fb_videomode *timing;
+	struct resource *res;
+	int win;
+	int ret = -EINVAL;
+
+	printk(KERN_DEBUG "[%d] %s\n", __LINE__, __func__);

Hm printk? Use pr_dbg instead.

Ok, get it. thank you.

Quoted 125 lines
Quoted 59 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +59 -0
+
+	pdata = pdev->dev.platform_data;
+	if (!pdata) {
+		dev_err(dev, "no platform data specified\n");
+		return -EINVAL;
+	}
+
+	timing = &pdata->timing;
+	if (!timing) {
+		dev_err(dev, "timing is null.\n");
+		return -EINVAL;
+	}
+
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	ctx->bus_clk = clk_get(dev, "fimd");
+	if (IS_ERR(ctx->bus_clk)) {
+		dev_err(dev, "failed to get bus clock\n");
+		ret = PTR_ERR(ctx->bus_clk);
+		goto err_clk_get;
+	}
+
+	clk_enable(ctx->bus_clk);
+
+	ctx->lcd_clk = clk_get(dev, "sclk_fimd");
+	if (IS_ERR(ctx->lcd_clk)) {
+		dev_err(dev, "failed to get lcd clock\n");
+		ret = PTR_ERR(ctx->lcd_clk);
+		goto err_bus_clk;
+	}
+
+	clk_enable(ctx->lcd_clk);
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "failed to find registers\n");
+		ret = -ENOENT;
+		goto err_clk;
+	}
+
+	ctx->regs_res = request_mem_region(res->start, resource_size(res),
+					   dev_name(dev));
+	if (!ctx->regs_res) {
+		dev_err(dev, "failed to claim register region\n");
+		ret = -ENOENT;
+		goto err_clk;
+	}
+
+	ctx->regs = ioremap(res->start, resource_size(res));
+	if (!ctx->regs) {
+		dev_err(dev, "failed to map registers\n");
+		ret = -ENXIO;
+		goto err_req_region_io;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (!res) {

drivers/gpu/drm/samsung/samsung_drm_fimd.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +10 -0
+		dev_err(dev, "irq request failed.\n");
+		goto err_req_region_irq;
+	}
+
+	ctx->irq_no = res->start;
+
+	for (win = 0; win < WINDOWS_NR; win++)
+		fimd_clear_win(ctx, win);
+
+	ret = request_irq(ctx->irq_no, fimd_irq_handler, 0, "drm_fimd",

ctx);

Quoted 55 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +55 -0
+	if (ret < 0) {
+		dev_err(dev, "irq request failed.\n");
+		goto err_req_irq;
+	}
+
+	ctx->clkdiv = fimd_calc_clkdiv(ctx, timing);
+	ctx->vidcon0 = pdata->vidcon0;
+	ctx->vidcon1 = pdata->vidcon1;
+	ctx->default_win = pdata->default_win;
+	ctx->bpp = pdata->bpp;
+	ctx->timing = timing;
+
+	timing->pixclock = clk_get_rate(ctx->lcd_clk) / ctx->clkdiv;
+
+	subdrv = &ctx->subdrv;
+
+	subdrv->probe = fimd_subdrv_probe;
+	subdrv->remove = fimd_subdrv_remove;
+	subdrv->manager.pipe = -1;
+	subdrv->manager.ops = &fimd_manager_ops;
+	subdrv->manager.overlay_ops = &fimd_overlay_ops;
+	subdrv->manager.display = &fimd_display;
+	subdrv->manager.dev = dev;
+
+	platform_set_drvdata(pdev, ctx);
+	samsung_drm_subdrv_register(subdrv);
+
+	return 0;
+
+err_req_irq:
+err_req_region_irq:
+	iounmap(ctx->regs);
+
+err_req_region_io:
+	release_resource(ctx->regs_res);
+	kfree(ctx->regs_res);
+
+err_clk:
+	clk_disable(ctx->lcd_clk);
+	clk_put(ctx->lcd_clk);
+
+err_bus_clk:
+	clk_disable(ctx->bus_clk);
+	clk_put(ctx->bus_clk);
+
+err_clk_get:
+	kfree(ctx);
+	return ret;
+}
+
+static int __devexit fimd_remove(struct platform_device *pdev)
+{
+	struct fimd_context *ctx = platform_get_drvdata(pdev);
+
+	samsung_drm_subdrv_unregister(&ctx->subdrv);
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_fimd.c line 609

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +6 -0
+
+	clk_disable(ctx->lcd_clk);
+	clk_disable(ctx->bus_clk);
+	clk_put(ctx->lcd_clk);
+	clk_put(ctx->bus_clk);
+

free_irq ?

Ah , I missed it. thank you.

Quoted 65 lines

Review

Quoted 35 lines
drivers/gpu/drm/samsung/samsung_drm_fimd.c new file +34 -0
+	iounmap(ctx->regs);
+	release_resource(ctx->regs_res);
+	kfree(ctx->regs_res);
+
+	kfree(ctx);
+
+	return 0;
+}
+
+static struct platform_driver fimd_driver = {
+	.probe		= fimd_probe,
+	.remove		= __devexit_p(fimd_remove),
+	.driver		= {
+		.name	= "exynos4-fb",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init fimd_init(void)
+{
+	return platform_driver_register(&fimd_driver);
+}
+
+static void __exit fimd_exit(void)
+{
+	platform_driver_unregister(&fimd_driver);
+}
+
+module_init(fimd_init);
+module_exit(fimd_exit);
+
+MODULE_AUTHOR("Joonyoung Shim <[email protected]>");
+MODULE_DESCRIPTION("Samsung DRM FIMD Driver");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_gem.c

drivers/gpu/drm/samsung/samsung_drm_gem.c line 6

Quoted 11 lines

new file mode 100644
index 0000000..8f71ef0

drivers/gpu/drm/samsung/samsung_drm_gem.c new file +6 -0
@@ -0,0 +1,492 @@
+/* samsung_drm_gem.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Author: Inki Dae <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_gem.c line 7

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_gem.c line 8

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_gem.c line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_gem.c line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_gem.c line 13

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_gem.c line 14

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_gem.c line 17

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_gem.c line 18

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_gem.c line 19

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_gem.c line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 214 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 34 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +34 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm.h"
+
+#include <drm/samsung_drm.h>
+
+#include "samsung_drm_drv.h"
+#include "samsung_drm_gem.h"
+#include "samsung_drm_buf.h"
+
+static unsigned int convert_to_vm_err_msg(int msg)
+{
+	unsigned int out_msg;
+
+	switch (msg) {
+	case 0:
+	case -ERESTARTSYS:
+	case -EINTR:
+		out_msg = VM_FAULT_NOPAGE;
+		break;
+
+	case -ENOMEM:
+		out_msg = VM_FAULT_OOM;
+		break;
+
+	default:
+		out_msg = VM_FAULT_SIGBUS;
+		break;
+	}
+
+	return out_msg;
+}

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +10 -0
+
+static unsigned int get_gem_mmap_offset(struct drm_gem_object *obj)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return (unsigned int)obj->map_list.hash.key << PAGE_SHIFT;
+}
+
+/**
+ * samsung_drm_gem_create_mmap_offset - create a fake mmap offset for

an object

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +3 -0
+ * @obj: obj in question
+ *
+ * GEM memory mapping works by handing back to userspace a fake mmap

offset

drivers/gpu/drm/samsung/samsung_drm_gem.c line 70

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * it can use in a subsequent mmap(2) call.  The DRM core code then

looks

drivers/gpu/drm/samsung/samsung_drm_gem.c line 71

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +1 -0
+ * up the object based on the offset and sets up the various memory

mapping

Quoted 65 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +65 -0
+ * structures.
+ *
+ * This routine allocates and attaches a fake offset for @obj.
+ */
+static int
+samsung_drm_gem_create_mmap_offset(struct drm_gem_object *obj)
+{
+	struct drm_device *dev = obj->dev;
+	struct drm_gem_mm *mm = dev->mm_private;
+	struct drm_map_list *list;
+	struct drm_local_map *map;
+	int ret = 0;
+
+	/* Set the object up for mmap'ing */
+	list = &obj->map_list;
+	list->map = kzalloc(sizeof(struct drm_map_list), GFP_KERNEL);
+	if (!list->map)
+		return -ENOMEM;
+
+	map = list->map;
+	map->type = _DRM_GEM;
+	map->size = obj->size;
+	map->handle = obj;
+
+	/* Get a DRM GEM mmap offset allocated... */
+	list->file_offset_node = drm_mm_search_free(&mm->offset_manager,
+						    obj->size / PAGE_SIZE,
+						    0, 0);
+	if (!list->file_offset_node) {
+		DRM_ERROR("failed to allocate offset for bo %d\n",
+			  obj->name);
+		ret = -ENOSPC;
+		goto out_free_list;
+	}
+
+	list->file_offset_node = drm_mm_get_block(list->file_offset_node,
+						  obj->size / PAGE_SIZE,
+						  0);
+	if (!list->file_offset_node) {
+		ret = -ENOMEM;
+		goto out_free_list;
+	}
+
+	list->hash.key = list->file_offset_node->start;
+	ret = drm_ht_insert_item(&mm->offset_hash, &list->hash);
+	if (ret) {
+		DRM_ERROR("failed to add to map hash\n");
+		goto out_free_mm;
+	}
+
+	return 0;
+
+out_free_mm:
+	drm_mm_put_block(list->file_offset_node);
+out_free_list:
+	kfree(list->map);
+	list->map = NULL;
+
+	return ret;
+}
+
+static void
+samsung_drm_gem_free_mmap_offset(struct drm_gem_object *obj)
+{
+	struct drm_device *dev = obj->dev;

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +10 -0
+	struct drm_gem_mm *mm = dev->mm_private;
+	struct drm_map_list *list = &obj->map_list;
+
+	drm_ht_remove_item(&mm->offset_hash, &list->hash);
+	drm_mm_put_block(list->file_offset_node);
+	kfree(list->map);
+	list->map = NULL;
+}
+
+struct samsung_drm_gem_obj *samsung_drm_gem_create(struct drm_file

*file_priv,

Quoted 83 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +36 -0
+		struct drm_device *dev, unsigned int size,
+		unsigned int *handle)
+{
+	struct samsung_drm_gem_obj *samsung_gem_obj;
+	struct samsung_drm_buf_entry *entry;
+	struct drm_gem_object *obj;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	size = roundup(size, PAGE_SIZE);
+
+	samsung_gem_obj = kzalloc(sizeof(*samsung_gem_obj), GFP_KERNEL);
+	if (!samsung_gem_obj) {
+		DRM_ERROR("failed to allocate samsung gem object.\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	/* allocate the new buffer object and memory region. */
+	entry = samsung_drm_buf_create(dev, size);
+	if (!entry) {
+		kfree(samsung_gem_obj);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	samsung_gem_obj->entry = entry;
+
+	obj = &samsung_gem_obj->base;
+
+	ret = drm_gem_object_init(dev, obj, size);
+	if (ret < 0) {
+		DRM_ERROR("failed to initailize gem object.\n");
+		goto err_obj_init;
+	}
+
+	DRM_DEBUG_KMS("created file object = 0x%x\n", (unsigned int)obj-

filp);

drivers/gpu/drm/samsung/samsung_drm_gem.c new file +46 -0
+
+	ret = samsung_drm_gem_create_mmap_offset(obj);
+	if (ret < 0) {
+		DRM_ERROR("failed to allocate mmap offset.\n");
+		goto err_create_mmap_offset;
+	}
+
+	/**
+	 * allocate a id of idr table where the obj is registered
+	 * and handle has the id what user can see.
+	 */
+	ret = drm_gem_handle_create(file_priv, obj, handle);
+	if (ret)
+		goto err_handle_create;
+
+	DRM_DEBUG_KMS("gem handle = 0x%x\n", *handle);
+
+	/* drop reference from allocate - handle holds it now. */
+	drm_gem_object_unreference_unlocked(obj);
+
+	return samsung_gem_obj;
+
+err_handle_create:
+	samsung_drm_gem_free_mmap_offset(obj);
+	drm_gem_object_release(obj);
+
+err_create_mmap_offset:
+	/* add exception. FIXME. */
+
+err_obj_init:
+	samsung_drm_buf_destroy(dev, samsung_gem_obj->entry);
+
+	kfree(samsung_gem_obj);
+
+	return ERR_PTR(ret);
+}
+
+int samsung_drm_gem_create_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file_priv)
+{
+	struct drm_samsung_gem_create *args = data;
+	struct samsung_drm_gem_obj *samsung_gem_obj;
+
+	DRM_DEBUG_KMS("%s : size = 0x%x\n", __FILE__, args->size);
+
+	samsung_gem_obj = samsung_drm_gem_create(file_priv, dev, args->size,
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +8 -0
+			&args->handle);
+	if (IS_ERR(samsung_gem_obj))
+		return PTR_ERR(samsung_gem_obj);
+
+	return 0;
+}
+
+int samsung_drm_gem_map_offset_ioctl(struct drm_device *dev, void

*data,

Quoted 14 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c line 247

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +11 -0
+		struct drm_file *file_priv)
+{
+	struct drm_samsung_gem_map_off *args = data;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	DRM_DEBUG_KMS("handle = 0x%x, offset = 0x%x\n",
+			args->handle, (u32)args->offset);
+
+	if (!(dev->driver->driver_features & DRIVER_GEM)) {
+		DRM_ERROR("not support GEM.\n");

Um, You can make that error read better. Perhaps

Quoted 2 lines

drv_err(dev->dev,"Does not support GEM.\n");

Ok, get it. thank you.

Quoted 24 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +12 -0
+		return -ENODEV;
+	}
+
+	return samsung_drm_gem_dumb_map_offset(file_priv, dev, args->handle,
+			&args->offset);
+}
+
+static int samsung_drm_gem_mmap_buffer(struct file *filp,
+		struct vm_area_struct *vma)
+{
+	struct drm_gem_object *obj = filp->private_data;
+	struct samsung_drm_gem_obj *samsung_gem_obj =

to_samsung_gem_obj(obj);

Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +11 -0
+	struct samsung_drm_buf_entry *entry;
+	unsigned long pfn, size;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	vma->vm_flags |= (VM_IO | VM_RESERVED);
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+	vma->vm_file = filp;
+
+	size = vma->vm_end - vma->vm_start;
+	entry = samsung_gem_obj->entry;
Quoted 9 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c line 276

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +6 -0
+
+	/* check if the region to be mapped is valid or not. */
+	if ((entry->paddr + vma->vm_pgoff + size) >
+			(entry->paddr + entry->size)) {
+		drm_gem_object_unreference_unlocked(obj);
+		DRM_ERROR("desired size is bigger then real size.\n");

So .. you can't continue by just using the real size instead?

Quoted 5 lines

I am afraid I don't understand what you mean but I think that condition is fine. size is a vm area to user-desired size and you could request mapping as specific size. so it just check user-requested virtual space region it bigger than allocated physical memory region to be mapped. if there is my missing points, I would be happy to you give me your comments. thank you.

I meant that you return -EINVAL. But I am wondering if it would be possible to just continue on, but ignore what the user specified.

I think the issue here is that you are outputing the DRM_ERROR and I am not sure if it is that neccessary. Perhaps DRM_DEBUG, but DRM_ERROR just seems a bit.. heavy handed.

Quoted 329 lines
Quoted 10 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c line 283

Quoted 8 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +7 -0
+		return -EINVAL;
+	}
+
+	pfn = (samsung_gem_obj->entry->paddr + vma->vm_pgoff) >> PAGE_SHIFT;
+
+	DRM_DEBUG_KMS("offset = 0x%x, pfn to be mapped = 0x%x\n",
+			(u32)vma->vm_pgoff, (u32)pfn);

You can drop those u32 and use %lx

Thank you.

Quoted 10 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c line 288

Quoted 5 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +5 -0
+
+	if (remap_pfn_range(vma, vma->vm_start, pfn,
+				vma->vm_end - vma->vm_start,
+				vma->vm_page_prot)) {
+		DRM_ERROR("failed to remap pfn range.\n");

Perhaps also include more details. Say the PFN in question, the offset, etc.
Something that will help in the field?

Ok, get it. thank you.

Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +15 -0
+		return -EAGAIN;
+	}
+
+	return 0;
+}
+
+static const struct file_operations samsung_drm_gem_fops = {
+	.mmap = samsung_drm_gem_mmap_buffer,
+};
+
+int samsung_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file_priv)
+{
+	struct drm_samsung_gem_mmap *args = data;
+	struct drm_gem_object *obj;
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c line 309

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +6 -0
+	unsigned int addr;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	if (!(dev->driver->driver_features & DRIVER_GEM)) {
+		DRM_ERROR("not support GEM.\n");

Ditto.

Thank you.

Quoted 19 lines
Quoted 19 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +19 -0
+		return -ENODEV;
+	}
+
+	obj = drm_gem_object_lookup(dev, file_priv, args->handle);
+	if (!obj) {
+		DRM_ERROR("failed to lookup gem object.\n");
+		return -EINVAL;
+	}
+
+	obj->filp->f_op = &samsung_drm_gem_fops;
+	obj->filp->private_data = obj;
+
+	down_write(&current->mm->mmap_sem);
+	addr = do_mmap(obj->filp, 0, args->size,
+			PROT_READ | PROT_WRITE, MAP_SHARED, args->offset);
+	up_write(&current->mm->mmap_sem);
+
+	drm_gem_object_unreference_unlocked(obj);
+
Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_gem.c line 334

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +6 -0
+	if (IS_ERR((void *)addr))
+		return PTR_ERR((void *)addr);
+
+	args->mapped = addr;
+
+	DRM_DEBUG_KMS("mapped = 0x%x\n", (u32)args->mapped);

Is all this casting to (u32) that neccessary?

Definitely no, this casting should be changed to 64bit type. thank you.

Quoted 192 lines
Quoted 82 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +82 -0
+
+	return 0;
+}
+
+int samsung_drm_gem_init_object(struct drm_gem_object *obj)
+{
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	return 0;
+}
+
+void samsung_drm_gem_free_object(struct drm_gem_object *gem_obj)
+{
+	struct samsung_drm_gem_obj *samsung_gem_obj;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	DRM_DEBUG_KMS("handle count = %d\n",
+			atomic_read(&gem_obj->handle_count));
+
+	if (gem_obj->map_list.map)
+		samsung_drm_gem_free_mmap_offset(gem_obj);
+
+	/* release file pointer to gem object. */
+	drm_gem_object_release(gem_obj);
+
+	samsung_gem_obj = to_samsung_gem_obj(gem_obj);
+
+	samsung_drm_buf_destroy(gem_obj->dev, samsung_gem_obj->entry);
+}
+
+int samsung_drm_gem_dumb_create(struct drm_file *file_priv,
+		struct drm_device *dev, struct drm_mode_create_dumb *args)
+{
+	struct samsung_drm_gem_obj *samsung_gem_obj;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	/**
+	 * alocate memory to be used for framebuffer.
+	 * - this callback would be called by user application
+	 *	with DRM_IOCTL_MODE_CREATE_DUMB command.
+	 */
+
+	args->pitch = args->width * args->bpp >> 3;
+	args->size = args->pitch * args->height;
+
+	samsung_gem_obj = samsung_drm_gem_create(file_priv, dev, args->size,
+							&args->handle);
+	if (IS_ERR(samsung_gem_obj))
+		return PTR_ERR(samsung_gem_obj);
+
+	return 0;
+}
+
+int samsung_drm_gem_dumb_map_offset(struct drm_file *file_priv,
+		struct drm_device *dev, uint32_t handle, uint64_t *offset)
+{
+	struct samsung_drm_gem_obj *samsung_gem_obj;
+	struct drm_gem_object *obj;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	mutex_lock(&dev->struct_mutex);
+
+	/**
+	 * get offset of memory allocated for drm framebuffer.
+	 * - this callback would be called by user application
+	 *	with DRM_IOCTL_MODE_MAP_DUMB command.
+	 */
+
+	obj = drm_gem_object_lookup(dev, file_priv, handle);
+	if (!obj) {
+		DRM_ERROR("failed to lookup gem object.\n");
+		mutex_unlock(&dev->struct_mutex);
+		return -EINVAL;
+	}
+
+	samsung_gem_obj = to_samsung_gem_obj(obj);
+
+	*offset = get_gem_mmap_offset(&samsung_gem_obj->base);
+

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +10 -0
+	drm_gem_object_unreference(obj);
+
+	DRM_DEBUG_KMS("offset = 0x%x\n", (unsigned int)*offset);
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return 0;
+}
+
+int samsung_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault

*vmf)

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +3 -0
+{
+	struct drm_gem_object *obj = vma->vm_private_data;
+	struct samsung_drm_gem_obj *samsung_gem_obj =

to_samsung_gem_obj(obj);

drivers/gpu/drm/samsung/samsung_drm_gem.c

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +13 -0
+	struct drm_device *dev = obj->dev;
+	unsigned long pfn;
+	pgoff_t page_offset;
+	int ret;
+
+	page_offset = ((unsigned long)vmf->virtual_address -
+			vma->vm_start) >> PAGE_SHIFT;
+
+	mutex_lock(&dev->struct_mutex);
+
+	pfn = (samsung_gem_obj->entry->paddr >> PAGE_SHIFT) + page_offset;
+
+	ret = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address,

pfn);

Review

Quoted 51 lines
drivers/gpu/drm/samsung/samsung_drm_gem.c new file +50 -0
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return convert_to_vm_err_msg(ret);
+}
+
+int samsung_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	/* set vm_area_struct. */
+	ret = drm_gem_mmap(filp, vma);
+	if (ret < 0) {
+		DRM_ERROR("failed to mmap.\n");
+		return ret;
+	}
+
+	vma->vm_flags &= ~VM_PFNMAP;
+	vma->vm_flags |= VM_MIXEDMAP;
+
+	return ret;
+}
+
+
+int samsung_drm_gem_dumb_destroy(struct drm_file *file_priv,
+		struct drm_device *dev, unsigned int handle)
+{
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __FILE__);
+
+	/**
+	 * obj->refcount and obj->handle_count are decreased and
+	 * if both them are 0 then samsung_drm_gem_free_object()
+	 * would be called by callback to release resources.
+	 */
+	ret = drm_gem_handle_delete(file_priv, handle);
+	if (ret < 0) {
+		DRM_ERROR("failed to delete drm_gem_handle.\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+MODULE_AUTHOR("Inki Dae <[email protected]>");
+MODULE_DESCRIPTION("Samsung SoC DRM GEM Module");
+MODULE_LICENSE("GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/samsung/samsung_drm_gem.h

drivers/gpu/drm/samsung/samsung_drm_gem.h line 6

Quoted 11 lines

new file mode 100644
index 0000000..c6cd5e5

drivers/gpu/drm/samsung/samsung_drm_gem.h new file +6 -0
@@ -0,0 +1,98 @@
+/* samsung_drm_gem.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authoer: Inki Dae <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

drivers/gpu/drm/samsung/samsung_drm_gem.h line 7

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

drivers/gpu/drm/samsung/samsung_drm_gem.h line 8

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

drivers/gpu/drm/samsung/samsung_drm_gem.h line 9

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

drivers/gpu/drm/samsung/samsung_drm_gem.h line 10

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

drivers/gpu/drm/samsung/samsung_drm_gem.h line 13

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

drivers/gpu/drm/samsung/samsung_drm_gem.h line 14

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

drivers/gpu/drm/samsung/samsung_drm_gem.h line 17

Quoted 3 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

drivers/gpu/drm/samsung/samsung_drm_gem.h line 18

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

drivers/gpu/drm/samsung/samsung_drm_gem.h line 19

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

drivers/gpu/drm/samsung/samsung_drm_gem.h line 20

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 18 lines

drivers/gpu/drm/samsung/samsung_drm_gem.h line 22

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 4 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +4 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_GEM_H_

drivers/gpu/drm/samsung/samsung_drm_gem.h line 36

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +10 -0
+#define _SAMSUNG_DRM_GEM_H_
+
+#define to_samsung_gem_obj(x)	container_of(x,\
+			struct samsung_drm_gem_obj, base)
+
+/**
+ * samsung drm buffer structure.
+ *
+ * @entry: pointer to samsung drm buffer entry object.
+ * @flags: it means memory type to be alloated or cache attributes.

Hm, that sounds like an enum? Or a candidate for enums?

Yes, it's better to use enums. Thank you.

Quoted 4 lines

drivers/gpu/drm/samsung/samsung_drm_gem.h line 37

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+ * @handle: gem handle.

You are missing @base

Yes, I missed it. thank you.

Quoted 4 lines

drivers/gpu/drm/samsung/samsung_drm_gem.h line 39

Quoted 2 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +2 -0
+ *
+ * ps. this object would be transfered to user as kms_bo.handle so

It is 'P.S.'

Thank you.

Quoted 8 lines

drivers/gpu/drm/samsung/samsung_drm_gem.h line 45

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +6 -0
+ *	user can access to memory through kms_bo.handle.
+ */
+struct samsung_drm_gem_obj {
+	struct drm_gem_object base;
+	struct samsung_drm_buf_entry *entry;
+	unsigned int flags;

Actually, I don't think you are using this? Could it be chopped off?

Quoted 3 lines

Could you give me your more comments. I am afraid what is 'it'. I assume maybe it's flags. Yes, flags isn't used yet. I will remove it until this feature would be added. thank you.

Yup. That is the one I was thinking off.

Quoted 188 lines
Quoted 7 lines

drivers/gpu/drm/samsung/samsung_drm_gem.h

Quoted 6 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +5 -0
+};
+
+
+/* create a new buffer and get a new gem handle. */
+struct samsung_drm_gem_obj *samsung_drm_gem_create(struct drm_file

*file_priv,

Quoted 13 lines

drivers/gpu/drm/samsung/samsung_drm_gem.h

Quoted 13 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +13 -0
+		struct drm_device *dev, unsigned int size,
+		unsigned int *handle);
+
+/*
+ * request gem object creation and buffer allocation as the size
+ * that it is calculated with framebuffer information such as width,
+ * height and bpp.
+ */
+int samsung_drm_gem_create_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file_priv);
+
+/* get buffer offset to map to user space. */
+int samsung_drm_gem_map_offset_ioctl(struct drm_device *dev, void

*data,

Quoted 23 lines
Quoted 11 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +11 -0
+		struct drm_file *file_priv);
+
+/* unmap a buffer from user space. */
+int samsung_drm_gem_munmap_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file_priv);
+
+/* initialize gem object. */
+int samsung_drm_gem_init_object(struct drm_gem_object *obj);
+
+/* free gem object. */
+void samsung_drm_gem_free_object(struct drm_gem_object *gem_obj);

drivers/gpu/drm/samsung/samsung_drm_gem.h

Quoted 10 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +10 -0
+
+/* create memory region for drm framebuffer. */
+int samsung_drm_gem_dumb_create(struct drm_file *file_priv,
+		struct drm_device *dev, struct drm_mode_create_dumb *args);
+
+/* map memory region for drm framebuffer to user space. */
+int samsung_drm_gem_dumb_map_offset(struct drm_file *file_priv,
+		struct drm_device *dev, uint32_t handle, uint64_t *offset);
+
+/* page fault handler and mmap fault address(virtual) to physical

memory. */

drivers/gpu/drm/samsung/samsung_drm_gem.h line 85

Quoted 1 line
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +1 -0
+int samsung_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault
Quoted 8 lines

*vmf);

drivers/gpu/drm/samsung/samsung_drm_gem.h

Quoted 7 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +7 -0
+
+/* mmap gem object. */
+int samsung_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file_priv);
+
+/* set vm_flags and we can change vm attribute to other here. */
+int samsung_drm_gem_mmap(struct file *filp, struct vm_area_struct

*vma);

Quoted 38 lines
Quoted 12 lines
drivers/gpu/drm/samsung/samsung_drm_gem.h new file +6 -0
+
+/* destroy memory region allocated. */
+int samsung_drm_gem_dumb_destroy(struct drm_file *file_priv,
+		struct drm_device *dev, unsigned int handle);
+
+#endif
include/drm/samsung_drm.h new file +0 -0
new file mode 100644
index 0000000..5f89cf1

include/drm/samsung_drm.h line 8

Quoted 8 lines
include/drm/samsung_drm.h new file +8 -0
@@ -0,0 +1,103 @@
+/* samsung_drm.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Authors:
+ *	Inki Dae <[email protected]>
+ *	Joonyoung Shim <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person

obtaining a

include/drm/samsung_drm.h line 9

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * copy of this software and associated documentation files (the

"Software"),

include/drm/samsung_drm.h line 10

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * to deal in the Software without restriction, including without

limitation

include/drm/samsung_drm.h line 11

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * the rights to use, copy, modify, merge, publish, distribute,

sublicense,

include/drm/samsung_drm.h line 12

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * and/or sell copies of the Software, and to permit persons to whom

the

include/drm/samsung_drm.h line 15

Quoted 3 lines
include/drm/samsung_drm.h new file +3 -0
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the

next

include/drm/samsung_drm.h line 16

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * paragraph) shall be included in all copies or substantial portions

of the

include/drm/samsung_drm.h line 19

Quoted 3 lines
include/drm/samsung_drm.h new file +3 -0
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Quoted 8 lines

EXPRESS OR

include/drm/samsung_drm.h line 20

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY,

include/drm/samsung_drm.h line 21

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT

SHALL

include/drm/samsung_drm.h line 22

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,

DAMAGES OR

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR

OTHERWISE,

Quoted 14 lines

include/drm/samsung_drm.h line 24

Quoted 1 line
include/drm/samsung_drm.h new file +1 -0
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE

OR

Quoted 12 lines
include/drm/samsung_drm.h new file +12 -0
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _SAMSUNG_DRM_H_
+#define _SAMSUNG_DRM_H_
+
+/**
+ * User-desired buffer creation information structure.
+ *
+ * @size: requested size for the object.
+ *	- this size value would be page-aligned internally.
+ * @flags: user request for setting memory type or cache attributes.
Quoted 8 lines

include/drm/samsung_drm.h line 42

Quoted 6 lines
include/drm/samsung_drm.h new file +6 -0
+ * @handle: returned handle for the object.
+ */
+struct drm_samsung_gem_create {
+	unsigned int size;
+	unsigned int flags;
+

You can deleta that space.

Ok, get it. thank you.

Quoted 23 lines
Quoted 23 lines
include/drm/samsung_drm.h new file +23 -0
+	unsigned int handle;
+};
+
+/**
+ * A structure for getting buffer offset.
+ *
+ * @handle: a pointer to gem object created.
+ * @offset: relatived offset value of the memory region allocated.
+ *	- this value should be set by user.
+ */
+struct drm_samsung_gem_map_off {
+	unsigned int handle;
+	uint64_t offset;
+};
+
+/**
+ * A structure for mapping buffer.
+ *
+ * @handle: a pointer to gem object created.
+ * @offset: relatived offset value of the memory region allocated.
+ *	- this value should be set by user.
+ * @size: memory size to be mapped.
+ * @mapped: user virtual address to be mapped.
Quoted 8 lines

include/drm/samsung_drm.h line 71

Quoted 6 lines
include/drm/samsung_drm.h new file +6 -0
+ */
+struct drm_samsung_gem_mmap {
+	unsigned int handle;
+	uint64_t offset;
+	unsigned int size;
+

Ditto

Thank you.

Quoted 8 lines

include/drm/samsung_drm.h

Quoted 8 lines
include/drm/samsung_drm.h new file +8 -0
+	uint64_t mapped;
+};
+
+#define DRM_SAMSUNG_GEM_CREATE		0x00
+#define DRM_SAMSUNG_GEM_MAP_OFFSET	0x01
+#define DRM_SAMSUNG_GEM_MMAP		0x02
+
+#define DRM_IOCTL_SAMSUNG_GEM_CREATE

DRM_IOWR(DRM_COMMAND_BASE +

Quoted 20 lines

\

include/drm/samsung_drm.h

Quoted 3 lines
include/drm/samsung_drm.h new file +3 -0
+		DRM_SAMSUNG_GEM_CREATE, struct drm_samsung_gem_create)
+
+#define DRM_IOCTL_SAMSUNG_GEM_MAP_OFFSET	DRM_IOWR(DRM_COMMAND_BASE +

\

Quoted 15 lines
include/drm/samsung_drm.h new file +15 -0
+		DRM_SAMSUNG_GEM_MAP_OFFSET, struct drm_samsung_gem_map_off)
+
+#define DRM_IOCTL_SAMSUNG_GEM_MMAP	DRM_IOWR(DRM_COMMAND_BASE + \
+		DRM_SAMSUNG_GEM_MMAP, struct drm_samsung_gem_mmap)
+
+/**
+ * Platform Specific Structure for DRM based FIMD.
+ *
+ * @timing: default video mode for initializing
+ * @default_win: default window layer number to be used for UI.
+ * @bpp: default bit per pixel.
+ */
+struct samsung_drm_fimd_pdata {
+	struct fb_videomode		timing;
+	u32				vidcon0;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/drm/samsung_drm.h new file +6 -1
+	u32				vidcon1;
+	unsigned int			default_win;
+	unsigned int			bpp;
+};
+
+#endif
--

1.7.0.4

You might also include in V5 the comments about CMA/DMA and about exhaustion so that if somebody looks at the code in a year they won't wonder about it anymore.