add Drm driver for Rockchip
Subsystems (4)
PATCH 1/1 add Drm driver for Rockchip
From: mark <[email protected]>
This patch is a DRM Driver for Rockchip Socs and now only add the framework of Rockchips Socs, but we will add Rockchips Socs soon.
mark (1):
drm: Add Drm driver for Rockchip Socs
Signature · 1 line
1.7.9.5
PATCH 1/1 drm: Add Drm driver for Rockchip Socs
From: mark <[email protected]>
This patch is a DRM Driver for Rockchip Socs and now only add the framework of Rockchips Socs, but we will add Rockchips Socs soon.
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/rockchip/Kconfig | 35 + drivers/gpu/drm/rockchip/Makefile | 14 + drivers/gpu/drm/rockchip/rockchip_drm_buf.c | 191 ++++++ drivers/gpu/drm/rockchip/rockchip_drm_buf.h | 39 ++ drivers/gpu/drm/rockchip/rockchip_drm_connector.c | 261 ++++++++ drivers/gpu/drm/rockchip/rockchip_drm_connector.h | 24 + drivers/gpu/drm/rockchip/rockchip_drm_core.c | 163 +++++ drivers/gpu/drm/rockchip/rockchip_drm_crtc.c | 515 ++++++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_crtc.h | 42 ++ drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c | 290 ++++++++ drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.h | 32 + drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 618 +++++++++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 319 +++++++++ drivers/gpu/drm/rockchip/rockchip_drm_encoder.c | 206 ++++++ drivers/gpu/drm/rockchip/rockchip_drm_encoder.h | 30 + drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 333 ++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_fb.h | 39 ++ drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c | 380 +++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h | 26 + drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 738 +++++++++++++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_gem.h | 198 ++++++ drivers/gpu/drm/rockchip/rockchip_drm_iommu.c | 149 +++++ drivers/gpu/drm/rockchip/rockchip_drm_iommu.h | 76 +++ drivers/gpu/drm/rockchip/rockchip_drm_plane.c | 290 ++++++++ drivers/gpu/drm/rockchip/rockchip_drm_plane.h | 30 + include/uapi/drm/rockchip_drm.h | 155 +++++ 28 files changed, 5196 insertions(+) create mode 100644 drivers/gpu/drm/rockchip/Kconfig create mode 100644 drivers/gpu/drm/rockchip/Makefile create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_buf.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_buf.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_connector.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_connector.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_core.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_crtc.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_crtc.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_drv.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_drv.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_encoder.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_encoder.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fb.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fb.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_gem.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_gem.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_iommu.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_iommu.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_plane.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_plane.h create mode 100644 include/uapi/drm/rockchip_drm.h
drivers/gpu/drm/Kconfig +2 -0
@@ -170,6 +170,8 @@ config DRM_SAVAGE source "drivers/gpu/drm/exynos/Kconfig" +source "drivers/gpu/drm/rockchip/Kconfig" + source "drivers/gpu/drm/vmwgfx/Kconfig" source "drivers/gpu/drm/gma500/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/ obj-$(CONFIG_DRM_VIA) +=via/ obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/ obj-$(CONFIG_DRM_EXYNOS) +=exynos/ +obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/ obj-$(CONFIG_DRM_GMA500) += gma500/ obj-$(CONFIG_DRM_UDL) += udl/ obj-$(CONFIG_DRM_AST) += ast/
drivers/gpu/drm/rockchip/Kconfig new file +35 -0
@@ -0,0 +1,35 @@ +config DRM_ROCKCHIP + tristate "DRM Support for Rockchip " + depends on DRM + select DRM_KMS_HELPER + select DRM_KMS_FB_HELPER + select FB_CFB_FILLRECT + select FB_CFB_COPYAREA + select FB_CFB_IMAGEBLIT + select VT_HW_CONSOLE_BINDING if FRAMEBUFFER_CONSOLE + select VIDEOMODE_HELPERS + select OF + help + Choose this option if you have a ROCKCHIP soc chipset. + support will be included for lcd controller and display interface. + use dma buffer and iommu to get continus Continuous memory. + If M is selected the module will be called rockchipdrm. + +config DRM_ROCKCHIP_IOMMU + bool "ROCKCHIP DRM IOMMU Support" + depends on DRM_ROCKCHIP && ARM_DMA_USE_IOMMU + help + Choose this option if you want to use IOMMU feature for DRM. + support will be included for rk3288 lcd controller. + the IOMMU takes care of mapping device-visible virtual addresses + to physical addresses. + + +config DRM_ROCKCHIP_DMABUF + bool "ROCKCHIP DRM DMABUF" + depends on DRM_ROCKCHIP + help + Choose this option if you want to use DMABUF feature for DRM. + device drivers need dma buffers, we should use dma mapping APIs, + if DRM_ROCKCHIP_IOMMU is not support, CMA should work behind + kernel DMA mapping.
drivers/gpu/drm/rockchip/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +# +# 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/rockchip +rockchipdrm-y := rockchip_drm_drv.o rockchip_drm_encoder.o \ + rockchip_drm_crtc.o rockchip_drm_fbdev.o rockchip_drm_fb.o \ + rockchip_drm_buf.o rockchip_drm_gem.o rockchip_drm_core.o \ + rockchip_drm_plane.o + +rockchipdrm-$(CONFIG_DRM_ROCKCHIP_IOMMU) += rockchip_drm_iommu.o +rockchipdrm-$(CONFIG_DRM_ROCKCHIP_DMABUF) += rockchip_drm_dmabuf.o + +obj-$(CONFIG_DRM_ROCKCHIP) += rockchipdrm.o
drivers/gpu/drm/rockchip/rockchip_drm_buf.c new file +191 -0
191 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_buf.h new file +39 -0
@@ -0,0 +1,39 @@ +/* rockchip_drm_buf.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_buf.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_BUF_H_ +#define _ROCKCHIP_DRM_BUF_H_ + +/* create and initialize buffer object. */ +struct rockchip_drm_gem_buf *rockchip_drm_init_buf (struct drm_device *dev, +unsigned int size); + +/* destroy buffer object. */ +void rockchip_drm_fini_buf (struct drm_device *dev, +struct rockchip_drm_gem_buf *buffer); + +/* allocate physical memory region and setup sgt. */ +int rockchip_drm_alloc_buf (struct drm_device *dev, +struct rockchip_drm_gem_buf *buf, +unsigned int flags); + +/* release physical memory region, and sgt. */ +void rockchip_drm_free_buf (struct drm_device *dev, +unsigned int flags, +struct rockchip_drm_gem_buf *buffer); + +#endif /* _ROCKCHIP_DRM_BUF_H_ */
drivers/gpu/drm/rockchip/rockchip_drm_connector.c new file +261 -0
261 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_connector.h new file +24 -0
@@ -0,0 +1,24 @@ +/* rockchip_drm_connector.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_connector.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_CONNECTOR_H_ +#define _ROCKCHIP_DRM_CONNECTOR_H_ + +struct drm_connector *rockchip_drm_connector_create (struct drm_device *dev, +struct drm_encoder *encoder); + +#endif /* _ROCKCHIP_DRM_CONNECTOR_H_ */
drivers/gpu/drm/rockchip/rockchip_drm_core.c new file +163 -0
163 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +515 -0
515 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_crtc.h new file +42 -0
42 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c new file +290 -0
290 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.h new file +32 -0
@@ -0,0 +1,32 @@ +/* rockchip_drm_dmabuf.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_dmabuf.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_DMABUF_H_ +#define _ROCKCHIP_DRM_DMABUF_H_ + +#ifdef CONFIG_DRM_ROCKCHIP_DMABUF +struct dma_buf *rockchip_dmabuf_prime_export (struct drm_device *drm_dev, +struct drm_gem_object *obj,int flags); + +struct drm_gem_object *rockchip_dmabuf_prime_import (struct drm_device *drm_dev, +struct dma_buf *dma_buf); +#else +#define rockchip_dmabuf_prime_export NULL +#define rockchip_dmabuf_prime_import NULL +#endif + +#endif /* _ROCKCHIP_DRM_DMABUF_H_ */
drivers/gpu/drm/rockchip/rockchip_drm_drv.c new file +618 -0
618 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_drv.h new file +319 -0
319 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_encoder.c new file +206 -0
206 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_encoder.h new file +30 -0
@@ -0,0 +1,30 @@ +/* rockchip_drm_encoder.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_encoder.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_ENCODER_H_ +#define _ROCKCHIP_DRM_ENCODER_H_ + +struct rockchip_drm_manager ; + +void rockchip_drm_encoder_setup (struct drm_device *dev); +struct drm_encoder *rockchip_drm_encoder_create (struct drm_device *dev, +struct rockchip_drm_display *mgr, +unsigned long possible_crtcs); +struct rockchip_drm_display * +rockchip_drm_get_display (struct drm_encoder *encoder); + +#endif /* _ROCKCHIP_DRM_ENCODER_H_ */
drivers/gpu/drm/rockchip/rockchip_drm_fb.c new file +333 -0
206 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_fb.h new file +39 -0
Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c new file +380 -0
380 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h new file +26 -0
Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_gem.c new file +738 -0
738 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_gem.h new file +198 -0
198 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_iommu.c new file +149 -0
149 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_iommu.h new file +76 -0
76 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_plane.c new file +290 -0
290 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_plane.h new file +30 -0
Lines of this file are not shown. View the raw message.
include/uapi/drm/rockchip_drm.h new file +155 -0
155 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.9.5
Part of the diff is not shown here. View the raw message.
Re: [PATCH] drm: Add Drm driver for Rockchip Socs
Quoted 4 lines · mark yao
From: mark <[email protected]>
This patch is a DRM Driver for Rockchip Socs and now only add the framework of Rockchips Socs, but we will add Rockchips Socs soon.
just a very quick skim over this.. I expect I'll have some more comments when I see a usage of the subdrv stuff.
This is not an exhaustive review, and would be good to get review comments from some others as well.
Quoted 114 lines
Signed-off-by mark <[email protected]>--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/rockchip/Kconfig | 35 + drivers/gpu/drm/rockchip/Makefile | 14 + drivers/gpu/drm/rockchip/rockchip_drm_buf.c | 191 ++++++ drivers/gpu/drm/rockchip/rockchip_drm_buf.h | 39 ++ drivers/gpu/drm/rockchip/rockchip_drm_connector.c | 261 ++++++++ drivers/gpu/drm/rockchip/rockchip_drm_connector.h | 24 + drivers/gpu/drm/rockchip/rockchip_drm_core.c | 163 +++++ drivers/gpu/drm/rockchip/rockchip_drm_crtc.c | 515 ++++++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_crtc.h | 42 ++ drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c | 290 ++++++++ drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.h | 32 + drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 618 +++++++++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 319 +++++++++ drivers/gpu/drm/rockchip/rockchip_drm_encoder.c | 206 ++++++ drivers/gpu/drm/rockchip/rockchip_drm_encoder.h | 30 + drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 333 ++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_fb.h | 39 ++ drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c | 380 +++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h | 26 + drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 738 +++++++++++++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_gem.h | 198 ++++++ drivers/gpu/drm/rockchip/rockchip_drm_iommu.c | 149 +++++ drivers/gpu/drm/rockchip/rockchip_drm_iommu.h | 76 +++ drivers/gpu/drm/rockchip/rockchip_drm_plane.c | 290 ++++++++ drivers/gpu/drm/rockchip/rockchip_drm_plane.h | 30 + include/uapi/drm/rockchip_drm.h | 155 +++++ 28 files changed, 5196 insertions(+) create mode 100644 drivers/gpu/drm/rockchip/Kconfig create mode 100644 drivers/gpu/drm/rockchip/Makefile create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_buf.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_buf.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_connector.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_connector.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_core.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_crtc.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_crtc.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_drv.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_drv.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_encoder.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_encoder.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fb.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fb.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_gem.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_gem.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_iommu.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_iommu.h create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_plane.c create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_plane.h create mode 100644 include/uapi/drm/rockchip_drm.hdrivers/gpu/drm/Kconfig +2
-0@@ -170,6 +170,8 @@ config DRM_SAVAGE source "drivers/gpu/drm/exynos/Kconfig" +source "drivers/gpu/drm/rockchip/Kconfig" + source "drivers/gpu/drm/vmwgfx/Kconfig" source "drivers/gpu/drm/gma500/Kconfig"drivers/gpu/drm/Makefile +1
-0@@ -51,6 +51,7 @@ obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/ obj-$(CONFIG_DRM_VIA) +=via/ obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/ obj-$(CONFIG_DRM_EXYNOS) +=exynos/ +obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/ obj-$(CONFIG_DRM_GMA500) += gma500/ obj-$(CONFIG_DRM_UDL) += udl/ obj-$(CONFIG_DRM_AST) += ast/drivers/gpu/drm/rockchip/Kconfig new file +25
-0@@ -0,0 +1,35 @@ +config DRM_ROCKCHIP + tristate "DRM Support for Rockchip " + depends on DRM + select DRM_KMS_HELPER + select DRM_KMS_FB_HELPER + select FB_CFB_FILLRECT + select FB_CFB_COPYAREA + select FB_CFB_IMAGEBLIT + select VT_HW_CONSOLE_BINDING if FRAMEBUFFER_CONSOLE + select VIDEOMODE_HELPERS + select OF + help + Choose this option if you have a ROCKCHIP soc chipset. + support will be included for lcd controller and display interface. + use dma buffer and iommu to get continus Continuous memory. + If M is selected the module will be called rockchipdrm. + +config DRM_ROCKCHIP_IOMMU + bool "ROCKCHIP DRM IOMMU Support" + depends on DRM_ROCKCHIP && ARM_DMA_USE_IOMMU + help + Choose this option if you want to use IOMMU feature for DRM. + support will be included for rk3288 lcd controller. + the IOMMU takes care of mapping device-visible virtual addresses + to physical addresses.
drivers/gpu/drm/rockchip/Kconfig line 35
Quoted 10 lines
drivers/gpu/drm/rockchip/Kconfig new file +10
-0+ + +config DRM_ROCKCHIP_DMABUF + bool "ROCKCHIP DRM DMABUF" + depends on DRM_ROCKCHIP + help + Choose this option if you want to use DMABUF feature for DRM. + device drivers need dma buffers, we should use dma mapping APIs, + if DRM_ROCKCHIP_IOMMU is not support, CMA should work behind + kernel DMA mapping.
btw, is there a good reason to let the user disable dmabuf (or iommu for that matter)?
Quoted 615 lines
drivers/gpu/drm/rockchip/Makefile new file +14
-0@@ -0,0 +1,14 @@ +# +# 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/rockchip +rockchipdrm-y := rockchip_drm_drv.o rockchip_drm_encoder.o \ + rockchip_drm_crtc.o rockchip_drm_fbdev.o rockchip_drm_fb.o \ + rockchip_drm_buf.o rockchip_drm_gem.o rockchip_drm_core.o \ + rockchip_drm_plane.o + +rockchipdrm-$(CONFIG_DRM_ROCKCHIP_IOMMU) += rockchip_drm_iommu.o +rockchipdrm-$(CONFIG_DRM_ROCKCHIP_DMABUF) += rockchip_drm_dmabuf.o + +obj-$(CONFIG_DRM_ROCKCHIP) += rockchipdrm.odrivers/gpu/drm/rockchip/rockchip_drm_buf.c new file +191
-0@@ -0,0 +1,191 @@ +/* rockchip_drm_buf.c +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_buf.c +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <drm/drmP.h> +#include <drm/rockchip_drm.h> + +#include "rockchip_drm_drv.h" +#include "rockchip_drm_gem.h" +#include "rockchip_drm_buf.h" +#include "rockchip_drm_iommu.h" + +static int lowlevel_buffer_allocate (struct drm_device *dev, +unsigned int flags,struct rockchip_drm_gem_buf *buf) +{ +int ret =0 ; +enum dma_attr attr; +unsigned int nr_pages; + +if (buf->dma_addr) { +DRM_DEBUG_KMS ("already allocated.\n" ); +return 0 ; + } + +init_dma_attrs (&buf->dma_attrs); + +/* +* if ROCKCHIP_BO_CONTIG, fully physically contiguous memory +* region will be allocated else physically contiguous +* as possible. +*/ +if (!(flags &ROCKCHIP_BO_NONCONTIG )) +dma_set_attr (DMA_ATTR_FORCE_CONTIGUOUS , &buf->dma_attrs); + +/* +* if ROCKCHIP_BO_WC or ROCKCHIP_BO_NONCACHABLE, writecombine mapping +* else cachable mapping. +*/ +if (flags &ROCKCHIP_BO_WC || !(flags &ROCKCHIP_BO_CACHABLE )) + attr =DMA_ATTR_WRITE_COMBINE ; +else + attr =DMA_ATTR_NON_CONSISTENT ; + +dma_set_attr (attr, &buf->dma_attrs); +dma_set_attr (DMA_ATTR_NO_KERNEL_MAPPING , &buf->dma_attrs); + + nr_pages = buf->size >>PAGE_SHIFT ; + +if (!is_drm_iommu_supported (dev)) { +dma_addr_t start_addr; +unsigned int i =0 ; + + buf->pages =drm_calloc_large (nr_pages,sizeof (struct page *)); +if (!buf->pages) { +DRM_ERROR ("failed to allocate pages.\n" ); +return -ENOMEM ; + } + + buf->kvaddr = (void __iomem *)dma_alloc_attrs (dev->dev, + buf->size, + &buf->dma_addr,GFP_KERNEL , + &buf->dma_attrs); +if (!buf->kvaddr) { +DRM_ERROR ("failed to allocate buffer.\n" ); + ret = -ENOMEM ; + goto err_free; + } + + start_addr = buf->dma_addr; +while (i < nr_pages) { + buf->pages[i] =phys_to_page (start_addr); + start_addr +=PAGE_SIZE ; + i++; + } + }else { + + buf->pages =dma_alloc_attrs (dev->dev, buf->size, + &buf->dma_addr,GFP_KERNEL , + &buf->dma_attrs); +if (!buf->pages) { +DRM_ERROR ("failed to allocate buffer.\n" ); +return -ENOMEM ; + } + } + + buf->sgt =drm_prime_pages_to_sg (buf->pages, nr_pages); +if (IS_ERR (buf->sgt)) { +DRM_ERROR ("failed to get sg table.\n" ); + ret =PTR_ERR (buf->sgt); + goto err_free_attrs; + } + +DRM_DEBUG_KMS ("dma_addr(0x%lx), size(0x%lx)\n" , + (unsigned long )buf->dma_addr, + buf->size); + +return ret; + +err_free_attrs: +dma_free_attrs (dev->dev, buf->size, buf->pages, + (dma_addr_t )buf->dma_addr, &buf->dma_attrs); + buf->dma_addr = (dma_addr_t )NULL ; +err_free: +if (!is_drm_iommu_supported (dev)) +drm_free_large (buf->pages); + +return ret; +} + +static void lowlevel_buffer_deallocate (struct drm_device *dev, +unsigned int flags,struct rockchip_drm_gem_buf *buf) +{ +if (!buf->dma_addr) { +DRM_DEBUG_KMS ("dma_addr is invalid.\n" ); +return ; + } + +DRM_DEBUG_KMS ("dma_addr(0x%lx), size(0x%lx)\n" , + (unsigned long )buf->dma_addr, + buf->size); + +sg_free_table (buf->sgt); + +kfree (buf->sgt); + buf->sgt =NULL ; + +if (!is_drm_iommu_supported (dev)) { +dma_free_attrs (dev->dev, buf->size, buf->kvaddr, + (dma_addr_t )buf->dma_addr, &buf->dma_attrs); +drm_free_large (buf->pages); + }else +dma_free_attrs (dev->dev, buf->size, buf->pages, + (dma_addr_t )buf->dma_addr, &buf->dma_attrs); + + buf->dma_addr = (dma_addr_t )NULL ; +} + +struct rockchip_drm_gem_buf *rockchip_drm_init_buf (struct drm_device *dev, +unsigned int size) +{ +struct rockchip_drm_gem_buf *buffer; + +DRM_DEBUG_KMS ("desired size = 0x%x\n" , size); + + buffer =kzalloc (sizeof (*buffer),GFP_KERNEL ); +if (!buffer) +return NULL ; + + buffer->size = size; + +return buffer; +} + +void rockchip_drm_fini_buf (struct drm_device *dev, +struct rockchip_drm_gem_buf *buffer) +{ +kfree (buffer); + buffer =NULL ; +} + +int rockchip_drm_alloc_buf (struct drm_device *dev, +struct rockchip_drm_gem_buf *buf,unsigned int flags) +{ +/* +* allocate memory region and set the memory information +* to vaddr and dma_addr of a buffer object. +*/ +if (lowlevel_buffer_allocate (dev, flags, buf) <0 ) +return -ENOMEM ; + +return 0 ; +} + +void rockchip_drm_free_buf (struct drm_device *dev, +unsigned int flags,struct rockchip_drm_gem_buf *buffer) +{ +lowlevel_buffer_deallocate (dev, flags, buffer); +}drivers/gpu/drm/rockchip/rockchip_drm_buf.h new file +39
-0@@ -0,0 +1,39 @@ +/* rockchip_drm_buf.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_buf.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_BUF_H_ +#define _ROCKCHIP_DRM_BUF_H_ + +/* create and initialize buffer object. */ +struct rockchip_drm_gem_buf *rockchip_drm_init_buf (struct drm_device *dev, +unsigned int size); + +/* destroy buffer object. */ +void rockchip_drm_fini_buf (struct drm_device *dev, +struct rockchip_drm_gem_buf *buffer); + +/* allocate physical memory region and setup sgt. */ +int rockchip_drm_alloc_buf (struct drm_device *dev, +struct rockchip_drm_gem_buf *buf, +unsigned int flags); + +/* release physical memory region, and sgt. */ +void rockchip_drm_free_buf (struct drm_device *dev, +unsigned int flags, +struct rockchip_drm_gem_buf *buffer); + +#endif /* _ROCKCHIP_DRM_BUF_H_ */ drivers/gpu/drm/rockchip/rockchip_drm_connector.c new file +261
-0@@ -0,0 +1,261 @@ +/* rockchip_drm_connector.c +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_connector.c +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <drm/drmP.h> +#include <drm/drm_crtc_helper.h> + +#include <drm/rockchip_drm.h> +#include "rockchip_drm_drv.h" +#include "rockchip_drm_encoder.h" +#include "rockchip_drm_connector.h" + +#define to_rockchip_connector (x) \ + container_of(x, struct rockchip_drm_connector, drm_connector) + +struct rockchip_drm_connector { +struct drm_connector drm_connector; +struct rockchip_drm_display *display; +uint32_t encoder_id; +}; + +static int rockchip_drm_connector_get_modes (struct drm_connector *connector) +{ +struct rockchip_drm_connector *rockchip_connector = +to_rockchip_connector (connector); +struct rockchip_drm_display *display = rockchip_connector->display; +struct edid *edid =NULL ; +unsigned int count =0 ; +int ret; + +/* +* if get_edid() exists then get_edid() callback of hdmi side +* is called to get edid data through i2c interface else +* get timing from the FIMD driver(display controller). +* +* P.S. in case of lcd panel, count is always 1 if success +* because lcd panel has only one mode. +*/ +if (display->ops->get_edid) { + edid = display->ops->get_edid (display, connector); +if (IS_ERR_OR_NULL (edid)) { + ret =PTR_ERR (edid); + edid =NULL ; +DRM_ERROR ("Panel operation get_edid failed %d\n" , ret); + goto out; + } + + count =drm_add_edid_modes (connector, edid); +if (!count) { +DRM_ERROR ("Add edid modes failed %d\n" , count); + goto out; + } + +drm_mode_connector_update_edid_property (connector, edid); + }else { +struct rockchip_drm_panel_info *panel; +struct drm_display_mode *mode = +drm_mode_create (connector->dev); +if (!mode) { +DRM_ERROR ("failed to create a new display mode.\n" ); +return 0 ; + } + +if (display->ops->get_panel) + panel = display->ops->get_panel (display); +else { +drm_mode_destroy (connector->dev, mode); +return 0 ; + } + +drm_display_mode_from_videomode (&panel->vm, mode); + mode->width_mm = panel->width_mm; + mode->height_mm = panel->height_mm; + connector->display_info.width_mm = mode->width_mm; + connector->display_info.height_mm = mode->height_mm; + + mode->type =DRM_MODE_TYPE_DRIVER |DRM_MODE_TYPE_PREFERRED ; +drm_mode_set_name (mode); +drm_mode_probed_add (connector, mode); + + count =1 ; + } + +out: +kfree (edid); +return count; +} + +static int rockchip_drm_connector_mode_valid (struct drm_connector *connector, +struct drm_display_mode *mode) +{ +struct rockchip_drm_connector *rockchip_connector = +to_rockchip_connector (connector); +struct rockchip_drm_display *display = rockchip_connector->display; +int ret =MODE_BAD ; + +if (display->ops->check_mode) +if (!display->ops->check_mode (display, mode)) + ret =MODE_OK ; + +return ret; +} + +static struct drm_encoder *rockchip_drm_best_encoder ( +struct drm_connector *connector) +{ +struct drm_device *dev = connector->dev; +struct rockchip_drm_connector *rockchip_connector = +to_rockchip_connector (connector); +struct drm_mode_object *obj; +struct drm_encoder *encoder; + + obj =drm_mode_object_find (dev, rockchip_connector->encoder_id, +DRM_MODE_OBJECT_ENCODER ); +if (!obj) { +DRM_DEBUG_KMS ("Unknown ENCODER ID %d\n" , + rockchip_connector->encoder_id); +return NULL ; + } + + encoder =obj_to_encoder (obj); + +return encoder; +} + +static struct drm_connector_helper_funcs rockchip_connector_helper_funcs = { + .get_modes = rockchip_drm_connector_get_modes, + .mode_valid = rockchip_drm_connector_mode_valid, + .best_encoder = rockchip_drm_best_encoder, +}; + +static int rockchip_drm_connector_fill_modes (struct drm_connector *connector, +unsigned int max_width,unsigned int max_height) +{ +struct rockchip_drm_connector *rockchip_connector = +to_rockchip_connector (connector); +struct rockchip_drm_display *display = rockchip_connector->display; +unsigned int width, height; + + width = max_width; + height = max_height; + +/* +* if specific driver want to find desired_mode using maxmum +* resolution then get max width and height from that driver. +*/ +if (display->ops->get_max_resol) + display->ops->get_max_resol (display, &width, &height); + +return drm_helper_probe_single_connector_modes (connector, width, + height); +} + +/* get detection status of display device. */ +static enum drm_connector_status +rockchip_drm_connector_detect (struct drm_connector *connector,bool force) +{ +struct rockchip_drm_connector *rockchip_connector = +to_rockchip_connector (connector); +struct rockchip_drm_display *display = rockchip_connector->display; +enum drm_connector_status status = connector_status_disconnected; + +if (display->ops->is_connected) { +if (display->ops->is_connected (display)) + status = connector_status_connected; +else + status = connector_status_disconnected; + } + +return status; +} + +static void rockchip_drm_connector_destroy (struct drm_connector *connector) +{ +struct rockchip_drm_connector *rockchip_connector = +to_rockchip_connector (connector); + +drm_sysfs_connector_remove (connector); +drm_connector_cleanup (connector); +kfree (rockchip_connector); +} + +static struct drm_connector_funcs rockchip_connector_funcs = { + .dpms = drm_helper_connector_dpms, + .fill_modes = rockchip_drm_connector_fill_modes, + .detect = rockchip_drm_connector_detect, + .destroy = rockchip_drm_connector_destroy, +}; + +struct drm_connector *rockchip_drm_connector_create (struct drm_device *dev, +struct drm_encoder *encoder) +{ +struct rockchip_drm_connector *rockchip_connector; +struct rockchip_drm_display *display = +rockchip_drm_get_display (encoder); +struct drm_connector *connector; +int type; +int err; + + rockchip_connector =kzalloc (sizeof (*rockchip_connector),GFP_KERNEL ); +if (!rockchip_connector) +return NULL ; + + connector = &rockchip_connector->drm_connector; + +switch (display->type) { +case ROCKCHIP_DISPLAY_TYPE_HDMI : + type =DRM_MODE_CONNECTOR_HDMIA ; + connector->interlace_allowed = true; + connector->polled =DRM_CONNECTOR_POLL_HPD ; +break ; +case ROCKCHIP_DISPLAY_TYPE_LCD : + type =DRM_MODE_CONNECTOR_LVDS ; +break ; +default : + type = DRM_MODE_CONNECTOR_Unknown; +break ; + } + +drm_connector_init (dev, connector, &rockchip_connector_funcs, type); +drm_connector_helper_add (connector, &rockchip_connector_helper_funcs); + + err =drm_sysfs_connector_add (connector); +if (err) + goto err_connector; + + rockchip_connector->encoder_id = encoder->base.id; + rockchip_connector->display = display; + connector->dpms =DRM_MODE_DPMS_OFF ; + 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: +drm_connector_cleanup (connector); +kfree (rockchip_connector); +return NULL ; +}drivers/gpu/drm/rockchip/rockchip_drm_connector.h new file +24
-0@@ -0,0 +1,24 @@ +/* rockchip_drm_connector.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_connector.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_CONNECTOR_H_ +#define _ROCKCHIP_DRM_CONNECTOR_H_ + +struct drm_connector *rockchip_drm_connector_create (struct drm_device *dev, +struct drm_encoder *encoder); + +#endif /* _ROCKCHIP_DRM_CONNECTOR_H_ */ drivers/gpu/drm/rockchip/rockchip_drm_core.c new file +50
-0@@ -0,0 +1,163 @@ +/* rockchip_drm_core.c +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_core.c +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <drm/drmP.h> +#include "rockchip_drm_drv.h" +#include "rockchip_drm_crtc.h" +#include "rockchip_drm_encoder.h" +#include "rockchip_drm_fbdev.h" + +static LIST_HEAD (rockchip_drm_subdrv_list); + +int rockchip_drm_create_enc_conn (struct drm_device *dev, +struct rockchip_drm_display *display) +{ +struct drm_encoder *encoder; +int ret; +unsigned long possible_crtcs =0 ; + + ret =rockchip_drm_crtc_get_pipe_from_type (dev, display->type); +if (ret <0 ) +return ret; + + possible_crtcs |=1 << ret; + +/* create and initialize a encoder for this sub driver. */ + encoder =rockchip_drm_encoder_create (dev, display, possible_crtcs); +if (!encoder) { +DRM_ERROR ("failed to create encoder\n" ); +return -EFAULT ; + } + + display->encoder = encoder; + + ret = display->ops->create_connector (display, encoder); +if (ret) { +DRM_ERROR ("failed to create connector ret = %d\n" , ret); + goto err_destroy_encoder;
drivers/gpu/drm/rockchip/rockchip_drm_core.c line 60
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_core.c new file +10
-0+ } + +return 0 ; + +err_destroy_encoder: + encoder->funcs->destroy (encoder); +return ret; +} + +int rockchip_drm_subdrv_register (struct rockchip_drm_subdrv *subdrv)
hmm.. this does look like it at least could be partially replaced with the 'componentised device support'
see http://lists.freedesktop.org/archives/dri-devel/2014-January/051249.html
Quoted 353 lines
drivers/gpu/drm/rockchip/rockchip_drm_core.c new file +103
-0+{ +if (!subdrv) +return -EINVAL ; + +list_add_tail (&subdrv->list, &rockchip_drm_subdrv_list); + +return 0 ; +} +EXPORT_SYMBOL_GPL (rockchip_drm_subdrv_register); + +int rockchip_drm_subdrv_unregister (struct rockchip_drm_subdrv *subdrv) +{ +if (!subdrv) +return -EINVAL ; + +list_del (&subdrv->list); + +return 0 ; +} +EXPORT_SYMBOL_GPL (rockchip_drm_subdrv_unregister); + +int rockchip_drm_device_subdrv_probe (struct drm_device *dev) +{ +struct rockchip_drm_subdrv *subdrv, *n; +int err; + +if (!dev) +return -EINVAL ; + +list_for_each_entry_safe (subdrv, n, &rockchip_drm_subdrv_list, list) { +if (subdrv->probe) { + subdrv->drm_dev = dev; + +/* +* this probe callback would be called by sub driver +* after setting of all resources to this sub driver, +* such as clock, irq and register map are done. +*/ + err = subdrv->probe (dev, subdrv->dev); +if (err) { +DRM_DEBUG ("rockchip drm subdrv probe fail.\n" ); +list_del (&subdrv->list); +continue ; + } + } + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (rockchip_drm_device_subdrv_probe); + +int rockchip_drm_device_subdrv_remove (struct drm_device *dev) +{ +struct rockchip_drm_subdrv *subdrv; + +if (!dev) { +WARN (1 ,"Unexpected drm device unregister!\n" ); +return -EINVAL ; + } + +list_for_each_entry (subdrv, &rockchip_drm_subdrv_list, list) { +if (subdrv->remove) + subdrv->remove (dev, subdrv->dev); + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (rockchip_drm_device_subdrv_remove); + +int rockchip_drm_subdrv_open (struct drm_device *dev,struct drm_file *file) +{ +struct rockchip_drm_subdrv *subdrv; +int ret; + +list_for_each_entry (subdrv, &rockchip_drm_subdrv_list, list) { +if (subdrv->open) { + ret = subdrv->open (dev, subdrv->dev, file); +if (ret) + goto err; + } + } + +return 0 ; + +err: +list_for_each_entry_reverse (subdrv, &subdrv->list, list) { +if (subdrv->close) + subdrv->close (dev, subdrv->dev, file); + } +return ret; +} +EXPORT_SYMBOL_GPL (rockchip_drm_subdrv_open); + +void rockchip_drm_subdrv_close (struct drm_device *dev,struct drm_file *file) +{ +struct rockchip_drm_subdrv *subdrv; + +list_for_each_entry (subdrv, &rockchip_drm_subdrv_list, list) { +if (subdrv->close) + subdrv->close (dev, subdrv->dev, file); + } +} +EXPORT_SYMBOL_GPL (rockchip_drm_subdrv_close);drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +244
-0@@ -0,0 +1,515 @@ +/* rockchip_drm_crtc.c +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_crtc.c +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <drm/drmP.h> +#include <drm/drm_crtc_helper.h> + +#include "rockchip_drm_crtc.h" +#include "rockchip_drm_drv.h" +#include "rockchip_drm_encoder.h" +#include "rockchip_drm_plane.h" + +#define to_rockchip_crtc (x) container_of(x, struct rockchip_drm_crtc,\ + drm_crtc) + +enum rockchip_crtc_mode { +/* normal mode */ +CRTC_MODE_NORMAL , +/* The private plane of crtc is blank */ +CRTC_MODE_BLANK , +}; + +/* +* Rockchip specific crtc structure. +* +* @drm_crtc: crtc object. +* @drm_plane: pointer of private plane object for this crtc +* @manager: the manager associated with this crtc +* @pipe: a crtc index created at load() with a new crtc object creation +* and the crtc object would be set to private->crtc array +* to get a crtc object corresponding to this pipe from private->crtc +* array when irq interrupt occurred. the reason of using this pipe is that +* drm framework doesn't support multiple irq yet. +* we can refer to the crtc to current hardware interrupt occurred through +* this pipe value. +* @dpms: store the crtc dpms value +* @mode: store the crtc mode value +*/ +struct rockchip_drm_crtc { +struct drm_crtc drm_crtc; +struct drm_plane *plane; +struct rockchip_drm_manager *manager; +wait_queue_head_t pending_flip_queue; +enum rockchip_crtc_mode mode; +atomic_t pending_flip; +unsigned int pipe; +unsigned int dpms; +}; + +static void rockchip_drm_crtc_dpms (struct drm_crtc *crtc,int mode) +{ +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (crtc); +struct rockchip_drm_manager *manager = rockchip_crtc->manager; + +DRM_DEBUG_KMS ("crtc[%d] mode[%d]\n" , crtc->base.id, mode); + +if (rockchip_crtc->dpms == mode) { +DRM_DEBUG_KMS ("desired dpms mode is same as previous one.\n" ); +return ; + } + +if (mode >DRM_MODE_DPMS_ON ) { +/* wait for the completion of page flip. */ +wait_event (rockchip_crtc->pending_flip_queue, +atomic_read (&rockchip_crtc->pending_flip) ==0 ); +drm_vblank_off (crtc->dev, rockchip_crtc->pipe); + } + +if (manager->ops->dpms) + manager->ops->dpms (manager, mode); + + rockchip_crtc->dpms = mode; +} + +static void rockchip_drm_crtc_prepare (struct drm_crtc *crtc) +{ +/* drm framework doesn't check NULL. */ +} + +static void rockchip_drm_crtc_commit (struct drm_crtc *crtc) +{ +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (crtc); +struct rockchip_drm_manager *manager = rockchip_crtc->manager; + +rockchip_drm_crtc_dpms (crtc,DRM_MODE_DPMS_ON ); + +rockchip_plane_commit (rockchip_crtc->plane); + +if (manager->ops->commit) + manager->ops->commit (manager); + +rockchip_plane_dpms (rockchip_crtc->plane,DRM_MODE_DPMS_ON ); +} + +static bool rockchip_drm_crtc_mode_fixup (struct drm_crtc *crtc, +const struct drm_display_mode *mode, +struct drm_display_mode *adjusted_mode) +{ +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (crtc); +struct rockchip_drm_manager *manager = rockchip_crtc->manager; + +if (manager->ops->mode_fixup) +return manager->ops->mode_fixup (manager, mode, adjusted_mode); + +return true; +} + +static int rockchip_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) +{ +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (crtc); +struct rockchip_drm_manager *manager = rockchip_crtc->manager; +struct drm_plane *plane = rockchip_crtc->plane; +unsigned int crtc_w; +unsigned int crtc_h; +int ret; + +/* +* copy the mode data adjusted by mode_fixup() into crtc->mode +* so that hardware can be seet to proper mode. +*/ +memcpy (&crtc->mode, adjusted_mode,sizeof (*adjusted_mode)); + + crtc_w = crtc->primary->fb->width - x; + crtc_h = crtc->primary->fb->height - y; + +if (manager->ops->mode_set) + manager->ops->mode_set (manager, &crtc->mode); + + ret =rockchip_plane_mode_set (plane, crtc, crtc->primary->fb, +0 ,0 , crtc_w, crtc_h, + x, y, crtc_w, crtc_h); +if (ret) +return ret; + + plane->crtc = crtc; + plane->fb = crtc->primary->fb; +drm_framebuffer_reference (plane->fb); + +return 0 ; +} + +static int rockchip_drm_crtc_mode_set_commit (struct drm_crtc *crtc, +int x,int y,struct drm_framebuffer *old_fb) +{ +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (crtc); +struct drm_plane *plane = rockchip_crtc->plane; +unsigned int crtc_w; +unsigned int crtc_h; +int ret; + +/* when framebuffer changing is requested, crtc's dpms should be on */ +if (rockchip_crtc->dpms >DRM_MODE_DPMS_ON ) { +DRM_ERROR ("failed framebuffer changing request.\n" ); +return -EPERM ; + } + + crtc_w = crtc->primary->fb->width - x; + crtc_h = crtc->primary->fb->height - y; + + ret =rockchip_plane_mode_set (plane, crtc, crtc->primary->fb, +0 ,0 , crtc_w, crtc_h, x, y, crtc_w, crtc_h); +if (ret) +return ret; + +rockchip_drm_crtc_commit (crtc); + +return 0 ; +} + +static int rockchip_drm_crtc_mode_set_base (struct drm_crtc *crtc,int x,int y, +struct drm_framebuffer *old_fb) +{ +return rockchip_drm_crtc_mode_set_commit (crtc, x, y, old_fb); +} + +static void rockchip_drm_crtc_disable (struct drm_crtc *crtc) +{ +struct drm_plane *plane; +int ret; + +rockchip_drm_crtc_dpms (crtc,DRM_MODE_DPMS_OFF ); + +drm_for_each_legacy_plane (plane, &crtc->dev->mode_config.plane_list) { +if (plane->crtc != crtc) +continue ; + + ret = plane->funcs->disable_plane (plane); +if (ret) +DRM_ERROR ("Failed to disable plane %d\n" , ret); + } +} + +static struct drm_crtc_helper_funcs rockchip_crtc_helper_funcs = { + .dpms = rockchip_drm_crtc_dpms, + .prepare = rockchip_drm_crtc_prepare, + .commit = rockchip_drm_crtc_commit, + .mode_fixup = rockchip_drm_crtc_mode_fixup, + .mode_set = rockchip_drm_crtc_mode_set, + .mode_set_base = rockchip_drm_crtc_mode_set_base, + .disable = rockchip_drm_crtc_disable, +}; + +static int rockchip_drm_crtc_page_flip (struct drm_crtc *crtc, +struct drm_framebuffer *fb, +struct drm_pending_vblank_event *event, +uint32_t page_flip_flags) +{ +struct drm_device *dev = crtc->dev; +struct rockchip_drm_private *dev_priv = dev->dev_private; +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (crtc); +struct drm_framebuffer *old_fb = crtc->primary->fb; +int ret = -EINVAL ; + +/* when the page flip is requested, crtc's dpms should be on */ +if (rockchip_crtc->dpms >DRM_MODE_DPMS_ON ) { +DRM_ERROR ("failed page flip request.\n" ); +return -EINVAL ; + } + +mutex_lock (&dev->struct_mutex); + +if (event) { +/* +* the pipe from user always is 0 so we can set pipe number +* of current owner to event. +*/ + event->pipe = rockchip_crtc->pipe; +
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c line 254
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +10
-0+ ret =drm_vblank_get (dev, rockchip_crtc->pipe); +if (ret) { +DRM_DEBUG ("failed to acquire vblank counter\n" ); + + goto out; + } + +spin_lock_irq (&dev->event_lock); +list_add_tail (&event->base.link, + &dev_priv->pageflip_event_list);
you don't need a list. Return -EBUSY if userspace tries to queue a flip when there is already one pending
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c line 260
Quoted 6 lines
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +6
-0+atomic_set (&rockchip_crtc->pending_flip,1 ); +spin_unlock_irq (&dev->event_lock); + + crtc->primary->fb = fb; + ret =rockchip_drm_crtc_mode_set_commit (crtc, crtc->x, crtc->y, +NULL );
so.. 'event' could be NULL if userspace doesn't ask for an event. So you probably don't want to ignore the pageflip if !event
Quoted 73 lines
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +73
-0+if (ret) { + crtc->primary->fb = old_fb; + +spin_lock_irq (&dev->event_lock); +drm_vblank_put (dev, rockchip_crtc->pipe); +list_del (&event->base.link); +spin_unlock_irq (&dev->event_lock); + + goto out; + } + } +out: +mutex_unlock (&dev->struct_mutex); +return ret; +} + +static void rockchip_drm_crtc_destroy (struct drm_crtc *crtc) +{ +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (crtc); +struct rockchip_drm_private *private = crtc->dev->dev_private; + + private->crtc[rockchip_crtc->pipe] =NULL ; + +drm_crtc_cleanup (crtc); +kfree (rockchip_crtc); +} + +static int rockchip_drm_crtc_set_property (struct drm_crtc *crtc, +struct drm_property *property, +uint64_t val) +{ +struct drm_device *dev = crtc->dev; +struct rockchip_drm_private *dev_priv = dev->dev_private; +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (crtc); + +if (property == dev_priv->crtc_mode_property) { +enum rockchip_crtc_mode mode = val; + +if (mode == rockchip_crtc->mode) +return 0 ; + + rockchip_crtc->mode = mode; + +switch (mode) { +case CRTC_MODE_NORMAL : +rockchip_drm_crtc_commit (crtc); +break ; +case CRTC_MODE_BLANK : +rockchip_plane_dpms (rockchip_crtc->plane, +DRM_MODE_DPMS_OFF ); +break ; +default : +break ; + } + +return 0 ; + } + +return -EINVAL ; +} + +static struct drm_crtc_funcs rockchip_crtc_funcs = { + .set_config = drm_crtc_helper_set_config, + .page_flip = rockchip_drm_crtc_page_flip, + .destroy = rockchip_drm_crtc_destroy, + .set_property = rockchip_drm_crtc_set_property, +}; + +static const struct drm_prop_enum_list mode_names[] = { + {CRTC_MODE_NORMAL ,"normal" }, + {CRTC_MODE_BLANK ,"blank" }, +}; +
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c line 343
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +10
-0+static void rockchip_drm_crtc_attach_mode_property (struct drm_crtc *crtc) +{ +struct drm_device *dev = crtc->dev; +struct rockchip_drm_private *dev_priv = dev->dev_private; +struct drm_property *prop; + + prop = dev_priv->crtc_mode_property; +if (!prop) { + prop =drm_property_create_enum (dev,0 ,"mode" , mode_names, +ARRAY_SIZE (mode_names));
ok, this looks a bit sketchy. If you need a custom property to do what the DPMS property on the connector does, it really seems like you are probably doing something wrong.
Also, for driver custom properties, they need to be documented in Documentation/DocBook/drm.tmpl.
But I'd really prefer if new drivers started out without any custom properties, and then added properties as follow-on patches to make sure userspace facing interfaces get properly reviewed.
Quoted 47 lines
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +47
-0+if (!prop) +return ; + + dev_priv->crtc_mode_property = prop; + } + +drm_object_attach_property (&crtc->base, prop,0 ); +} + +int rockchip_drm_crtc_create (struct rockchip_drm_manager *manager) +{ +struct rockchip_drm_crtc *rockchip_crtc; +struct rockchip_drm_private *private = manager->drm_dev->dev_private; +struct drm_crtc *crtc; + + rockchip_crtc =kzalloc (sizeof (*rockchip_crtc),GFP_KERNEL ); +if (!rockchip_crtc) +return -ENOMEM ; + +init_waitqueue_head (&rockchip_crtc->pending_flip_queue); +atomic_set (&rockchip_crtc->pending_flip,0 ); + + rockchip_crtc->dpms =DRM_MODE_DPMS_OFF ; + rockchip_crtc->manager = manager; + rockchip_crtc->pipe = manager->pipe; + rockchip_crtc->plane =rockchip_plane_init (manager->drm_dev, +1 << manager->pipe, true); +if (!rockchip_crtc->plane) { +kfree (rockchip_crtc); +return -ENOMEM ; + } + + manager->crtc = &rockchip_crtc->drm_crtc; + crtc = &rockchip_crtc->drm_crtc; + + private->crtc[manager->pipe] = crtc; + +drm_crtc_init (manager->drm_dev, crtc, &rockchip_crtc_funcs); +drm_crtc_helper_add (crtc, &rockchip_crtc_helper_funcs); + +rockchip_drm_crtc_attach_mode_property (crtc); + +return 0 ; +} + +int rockchip_drm_crtc_enable_vblank (struct drm_device *dev,int pipe) +{
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c line 400
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +10
-0+struct rockchip_drm_private *private = dev->dev_private; +struct rockchip_drm_crtc *rockchip_crtc = +to_rockchip_crtc (private->crtc[pipe]); +struct rockchip_drm_manager *manager = rockchip_crtc->manager; + +if (rockchip_crtc->dpms !=DRM_MODE_DPMS_ON ) +return -EPERM ; + +if (manager->ops->enable_vblank) + manager->ops->enable_vblank (manager);
if mgr doesn't support vblank, maybe you should return -EINVAL?
Quoted 349 lines
drivers/gpu/drm/rockchip/rockchip_drm_crtc.c new file +115
-0+ +return 0 ; +} + +void rockchip_drm_crtc_disable_vblank (struct drm_device *dev,int pipe) +{ +struct rockchip_drm_private *private = dev->dev_private; +struct rockchip_drm_crtc *rockchip_crtc = +to_rockchip_crtc (private->crtc[pipe]); +struct rockchip_drm_manager *manager = rockchip_crtc->manager; + +if (rockchip_crtc->dpms !=DRM_MODE_DPMS_ON ) +return ; + +if (manager->ops->disable_vblank) + manager->ops->disable_vblank (manager); +} + +void rockchip_drm_crtc_finish_pageflip (struct drm_device *dev,int pipe) +{ +struct rockchip_drm_private *dev_priv = dev->dev_private; +struct drm_pending_vblank_event *e, *t; +struct drm_crtc *drm_crtc = dev_priv->crtc[pipe]; +struct rockchip_drm_crtc *rockchip_crtc =to_rockchip_crtc (drm_crtc); +unsigned long flags; + +spin_lock_irqsave (&dev->event_lock, flags); + +list_for_each_entry_safe (e, t, &dev_priv->pageflip_event_list, + base.link) { +/* if event's pipe isn't same as crtc then ignore it. */ +if (pipe != e->pipe) +continue ; + +list_del (&e->base.link); +drm_send_vblank_event (dev,-1 , e); +drm_vblank_put (dev, pipe); +atomic_set (&rockchip_crtc->pending_flip,0 ); +wake_up (&rockchip_crtc->pending_flip_queue); + } + +spin_unlock_irqrestore (&dev->event_lock, flags); +} + +void rockchip_drm_crtc_plane_mode_set (struct drm_crtc *crtc, +struct rockchip_drm_overlay *overlay) +{ +struct rockchip_drm_manager *manager =to_rockchip_crtc (crtc)->manager; + +if (manager->ops->win_mode_set) + manager->ops->win_mode_set (manager, overlay); +} + +void rockchip_drm_crtc_plane_commit (struct drm_crtc *crtc,int zpos) +{ +struct rockchip_drm_manager *manager =to_rockchip_crtc (crtc)->manager; + +if (manager->ops->win_commit) + manager->ops->win_commit (manager, zpos); +} + +void rockchip_drm_crtc_plane_enable (struct drm_crtc *crtc,int zpos) +{ +struct rockchip_drm_manager *manager =to_rockchip_crtc (crtc)->manager; + +if (manager->ops->win_enable) + manager->ops->win_enable (manager, zpos); +} + +void rockchip_drm_crtc_plane_disable (struct drm_crtc *crtc,int zpos) +{ +struct rockchip_drm_manager *manager =to_rockchip_crtc (crtc)->manager; + +if (manager->ops->win_disable) + manager->ops->win_disable (manager, zpos); +} + +void rockchip_drm_crtc_complete_scanout (struct drm_framebuffer *fb) +{ +struct rockchip_drm_manager *manager; +struct drm_device *dev = fb->dev; +struct drm_crtc *crtc; + +/* +* make sure that overlay data are updated to real hardware +* for all encoders. +*/ +list_for_each_entry (crtc, &dev->mode_config.crtc_list, head) { + manager =to_rockchip_crtc (crtc)->manager; + +/* +* wait for vblank interrupt +* - this makes sure that overlay data are updated to +* real hardware. +*/ +if (manager->ops->wait_for_vblank) + manager->ops->wait_for_vblank (manager); + } +} + +int rockchip_drm_crtc_get_pipe_from_type (struct drm_device *drm_dev, +unsigned int out_type) +{ +struct drm_crtc *crtc; + +list_for_each_entry (crtc, &drm_dev->mode_config.crtc_list, head) { +struct rockchip_drm_crtc *rockchip_crtc; + + rockchip_crtc =to_rockchip_crtc (crtc); +if (rockchip_crtc->manager->type == out_type) +return rockchip_crtc->manager->pipe; + } + +return -EPERM ; +}drivers/gpu/drm/rockchip/rockchip_drm_crtc.h new file +42
-0@@ -0,0 +1,42 @@ +/* rockchip_drm_crtc.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_crtc.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_CRTC_H_ +#define _ROCKCHIP_DRM_CRTC_H_ + +struct drm_device ; +struct drm_crtc ; +struct rockchip_drm_manager ; +struct rockchip_drm_overlay ; + +int rockchip_drm_crtc_create (struct rockchip_drm_manager *manager); +int rockchip_drm_crtc_enable_vblank (struct drm_device *dev,int pipe); +void rockchip_drm_crtc_disable_vblank (struct drm_device *dev,int pipe); +void rockchip_drm_crtc_finish_pageflip (struct drm_device *dev,int pipe); +void rockchip_drm_crtc_complete_scanout (struct drm_framebuffer *fb); + +void rockchip_drm_crtc_plane_mode_set (struct drm_crtc *crtc, +struct rockchip_drm_overlay *overlay); +void rockchip_drm_crtc_plane_commit (struct drm_crtc *crtc,int zpos); +void rockchip_drm_crtc_plane_enable (struct drm_crtc *crtc,int zpos); +void rockchip_drm_crtc_plane_disable (struct drm_crtc *crtc,int zpos); + +/* This function gets pipe value to crtc device matched with out_type. */ +int rockchip_drm_crtc_get_pipe_from_type (struct drm_device *drm_dev, +unsigned int out_type); + +#endif /* _ROCKCHIP_DRM_CRTC_H_ */ drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c new file +180
-0@@ -0,0 +1,290 @@ +/* rockchip_drm_dmabuf.c +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_dmabuf.c +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/dma-buf.h> +#include <drm/drmP.h> +#include <drm/rockchip_drm.h> + +#include "rockchip_drm_dmabuf.h" +#include "rockchip_drm_drv.h" +#include "rockchip_drm_gem.h" + + +struct rockchip_drm_dmabuf_attachment { +struct sg_table sgt; +enum dma_data_direction dir; +bool is_mapped; +}; + +static struct rockchip_drm_gem_obj *dma_buf_to_obj (struct dma_buf *buf) +{ +return to_rockchip_gem_obj (buf->priv); +} + +static int rockchip_gem_attach_dma_buf (struct dma_buf *dmabuf, +struct device *dev, +struct dma_buf_attachment *attach) +{ +struct rockchip_drm_dmabuf_attachment *rockchip_attach; + + rockchip_attach =kzalloc (sizeof (*rockchip_attach),GFP_KERNEL ); +if (!rockchip_attach) +return -ENOMEM ; + + rockchip_attach->dir =DMA_NONE ; + attach->priv = rockchip_attach; + +return 0 ; +} + +static void rockchip_gem_detach_dma_buf (struct dma_buf *dmabuf, +struct dma_buf_attachment *attach) +{ +struct rockchip_drm_dmabuf_attachment *rockchip_attach = attach->priv; +struct sg_table *sgt; + +if (!rockchip_attach) +return ; + + sgt = &rockchip_attach->sgt; + +if (rockchip_attach->dir !=DMA_NONE ) +dma_unmap_sg (attach->dev, sgt->sgl, sgt->nents, + rockchip_attach->dir); + +sg_free_table (sgt); +kfree (rockchip_attach); + attach->priv =NULL ; +} + +static struct sg_table * +rockchip_gem_map_dma_buf (struct dma_buf_attachment *attach, +enum dma_data_direction dir) +{ +struct rockchip_drm_dmabuf_attachment *rockchip_attach = attach->priv; +struct rockchip_drm_gem_obj *gem_obj =dma_buf_to_obj (attach->dmabuf); +struct drm_device *dev = gem_obj->base.dev; +struct rockchip_drm_gem_buf *buf; +struct scatterlist *rd, *wr; +struct sg_table *sgt =NULL ; +unsigned int i; +int nents, ret; + +/* just return current sgt if already requested. */ +if (rockchip_attach->dir == dir && rockchip_attach->is_mapped) +return &rockchip_attach->sgt; + + buf = gem_obj->buffer; +if (!buf) { +DRM_ERROR ("buffer is null.\n" ); +return ERR_PTR (-ENOMEM ); + } + + sgt = &rockchip_attach->sgt; + + ret =sg_alloc_table (sgt, buf->sgt->orig_nents,GFP_KERNEL ); +if (ret) { +DRM_ERROR ("failed to alloc sgt.\n" ); +return ERR_PTR (-ENOMEM ); + } + +mutex_lock (&dev->struct_mutex); + + rd = buf->sgt->sgl; + wr = sgt->sgl; +for (i =0 ; i < sgt->orig_nents; ++i) { +sg_set_page (wr,sg_page (rd), rd->length, rd->offset); + rd =sg_next (rd); + wr =sg_next (wr); + } + +if (dir !=DMA_NONE ) { + nents =dma_map_sg (attach->dev, sgt->sgl, + sgt->orig_nents, dir); +if (!nents) { +DRM_ERROR ("failed to map sgl with iommu.\n" ); +sg_free_table (sgt); + sgt =ERR_PTR (-EIO ); + goto err_unlock; + } + } + + rockchip_attach->is_mapped = true; + rockchip_attach->dir = dir; + attach->priv = rockchip_attach; + +DRM_DEBUG_PRIME ("buffer size = 0x%lx\n" , buf->size); + +err_unlock: +mutex_unlock (&dev->struct_mutex); +return sgt; +} + +static void rockchip_gem_unmap_dma_buf (struct dma_buf_attachment *attach, +struct sg_table *sgt, +enum dma_data_direction dir) +{ +/* Nothing to do. */ +} + +static void *rockchip_gem_dmabuf_kmap_atomic (struct dma_buf *dma_buf, +unsigned long page_num) +{ +/* TODO */ + +return NULL ; +} + +static void rockchip_gem_dmabuf_kunmap_atomic (struct dma_buf *dma_buf, +unsigned long page_num, +void *addr) +{ +/* TODO */ +} + +static void *rockchip_gem_dmabuf_kmap (struct dma_buf *dma_buf, +unsigned long page_num) +{ +/* TODO */ + +return NULL ; +} + +static void rockchip_gem_dmabuf_kunmap (struct dma_buf *dma_buf, +unsigned long page_num,void *addr) +{ +/* TODO */ +} + +static int rockchip_gem_dmabuf_mmap (struct dma_buf *dma_buf, +struct vm_area_struct *vma) +{ +return -ENOTTY ; +} + +static struct dma_buf_ops rockchip_dmabuf_ops = { + .attach = rockchip_gem_attach_dma_buf,
drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c line 190
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c new file +10
-0+ .detach = rockchip_gem_detach_dma_buf, + .map_dma_buf = rockchip_gem_map_dma_buf, + .unmap_dma_buf = rockchip_gem_unmap_dma_buf, + .kmap = rockchip_gem_dmabuf_kmap, + .kmap_atomic = rockchip_gem_dmabuf_kmap_atomic, + .kunmap = rockchip_gem_dmabuf_kunmap, + .kunmap_atomic = rockchip_gem_dmabuf_kunmap_atomic, + .mmap = rockchip_gem_dmabuf_mmap, + .release = drm_gem_dmabuf_release, +};
Hmm, you probably should have a look at the prime-helpers (ie. drm_gem_prime_export(), etc).. I guess the exynos dmabuf code pre-dates the helpers, if that was the example you are working off of. At least for drm/msm, they made my dmabuf implementation somewhat more simple.
Quoted 625 lines
drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.c new file +99
-0+struct dma_buf *rockchip_dmabuf_prime_export (struct drm_device *drm_dev, +struct drm_gem_object *obj,int flags) +{ +struct rockchip_drm_gem_obj *rockchip_gem_obj = +to_rockchip_gem_obj (obj); + +return dma_buf_export (obj, &rockchip_dmabuf_ops, + rockchip_gem_obj->base.size, flags); +} + +struct drm_gem_object *rockchip_dmabuf_prime_import (struct drm_device *drm_dev, +struct dma_buf *dma_buf) +{ +struct dma_buf_attachment *attach; +struct sg_table *sgt; +struct scatterlist *sgl; +struct rockchip_drm_gem_obj *rockchip_gem_obj; +struct rockchip_drm_gem_buf *buffer; +int ret; + +/* is this one of own objects? */ +if (dma_buf->ops == &rockchip_dmabuf_ops) { +struct drm_gem_object *obj; + + obj = dma_buf->priv; + +/* is it from our device? */ +if (obj->dev == drm_dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_reference (obj); +return obj; + } + } + + attach =dma_buf_attach (dma_buf, drm_dev->dev); +if (IS_ERR (attach)) +return ERR_PTR (-EINVAL ); + +get_dma_buf (dma_buf); + + sgt =dma_buf_map_attachment (attach,DMA_BIDIRECTIONAL ); +if (IS_ERR (sgt)) { + ret =PTR_ERR (sgt); + goto err_buf_detach; + } + + buffer =kzalloc (sizeof (*buffer),GFP_KERNEL ); +if (!buffer) { + ret = -ENOMEM ; + goto err_unmap_attach; + } + + rockchip_gem_obj =rockchip_drm_gem_init (drm_dev, dma_buf->size); +if (!rockchip_gem_obj) { + ret = -ENOMEM ; + goto err_free_buffer; + } + + sgl = sgt->sgl; + + buffer->size = dma_buf->size; + buffer->dma_addr =sg_dma_address (sgl); + +if (sgt->nents ==1 ) { +/* always physically continuous memory if sgt->nents is 1. */ + rockchip_gem_obj->flags |=ROCKCHIP_BO_CONTIG ; + }else { +/* +* this case could be CONTIG or NONCONTIG type but for now +* sets NONCONTIG. +* TODO. we have to find a way that exporter can notify +* the type of its own buffer to importer. +*/ + rockchip_gem_obj->flags |=ROCKCHIP_BO_NONCONTIG ; + } + + rockchip_gem_obj->buffer = buffer; + buffer->sgt = sgt; + rockchip_gem_obj->base.import_attach = attach; + +DRM_DEBUG_PRIME ("dma_addr = %pad, size = 0x%lx\n" , &buffer->dma_addr, + buffer->size); + +return &rockchip_gem_obj->base; + +err_free_buffer: +kfree (buffer); + buffer =NULL ; +err_unmap_attach: +dma_buf_unmap_attachment (attach, sgt,DMA_BIDIRECTIONAL ); +err_buf_detach: +dma_buf_detach (dma_buf, attach); +dma_buf_put (dma_buf); + +return ERR_PTR (ret); +}drivers/gpu/drm/rockchip/rockchip_drm_dmabuf.h new file +32
-0@@ -0,0 +1,32 @@ +/* rockchip_drm_dmabuf.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_dmabuf.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_DMABUF_H_ +#define _ROCKCHIP_DRM_DMABUF_H_ + +#ifdef CONFIG_DRM_ROCKCHIP_DMABUF +struct dma_buf *rockchip_dmabuf_prime_export (struct drm_device *drm_dev, +struct drm_gem_object *obj,int flags); + +struct drm_gem_object *rockchip_dmabuf_prime_import (struct drm_device *drm_dev, +struct dma_buf *dma_buf); +#else +#define rockchip_dmabuf_prime_export NULL +#define rockchip_dmabuf_prime_import NULL +#endif + +#endif /* _ROCKCHIP_DRM_DMABUF_H_ */ drivers/gpu/drm/rockchip/rockchip_drm_drv.c new file +482
-0@@ -0,0 +1,618 @@ +/* rockchip_drm_drv.c +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_drv.c +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/pm_runtime.h> +#include <drm/drmP.h> +#include <drm/drm_crtc_helper.h> + +#include <linux/anon_inodes.h> +#include <linux/component.h> + +#include <drm/rockchip_drm.h> + +#include "rockchip_drm_drv.h" +#include "rockchip_drm_crtc.h" +#include "rockchip_drm_encoder.h" +#include "rockchip_drm_fbdev.h" +#include "rockchip_drm_fb.h" +#include "rockchip_drm_gem.h" +#include "rockchip_drm_plane.h" +#include "rockchip_drm_dmabuf.h" +#include "rockchip_drm_iommu.h" + +#define DRIVER_NAME "rockchip" +#define DRIVER_DESC "rockchip Soc DRM" +#define DRIVER_DATE "20140623" +#define DRIVER_MAJOR 1 +#define DRIVER_MINOR 0 + +#define VBLANK_OFF_DELAY 50000 + +static struct platform_device *rockchip_drm_pdev; + +static DEFINE_MUTEX (drm_component_lock); +static LIST_HEAD (drm_component_list); + +struct component_dev { +struct list_head list; +struct device *crtc_dev; +struct device *conn_dev; +enum rockchip_drm_output_type out_type; +unsigned int dev_type_flag; +}; + +static int rockchip_drm_load (struct drm_device *dev,unsigned long flags) +{ +struct rockchip_drm_private *private; +int ret; +int nr; + + private =kzalloc (sizeof (struct rockchip_drm_private ),GFP_KERNEL ); +if (!private) +return -ENOMEM ; + +INIT_LIST_HEAD (&private->pageflip_event_list); +dev_set_drvdata (dev->dev, dev); + dev->dev_private = (void *)private; + +/* +* create mapping to manage iommu table and set a pointer to iommu +* mapping structure to iommu_mapping of private data. +* also this iommu_mapping can be used to check if iommu is supported +* or not. +*/ + ret =drm_create_iommu_mapping (dev); +if (ret <0 ) { +DRM_ERROR ("failed to create iommu mapping.\n" ); + goto err_free_private; + } + +drm_mode_config_init (dev); + +rockchip_drm_mode_config_init (dev); + +for (nr =0 ; nr <MAX_PLANE ; nr++) { +struct drm_plane *plane; +unsigned long possible_crtcs = (1 <<MAX_CRTC ) -1 ; + + plane =rockchip_plane_init (dev, possible_crtcs, false); +if (!plane) + goto err_mode_config_cleanup; + } + +/* init kms poll for handling hpd */ +drm_kms_helper_poll_init (dev); + + ret =drm_vblank_init (dev,MAX_CRTC ); +if (ret) + goto err_mode_config_cleanup; + +/* setup possible_clones. */ +rockchip_drm_encoder_setup (dev); + + drm_vblank_offdelay =VBLANK_OFF_DELAY ; + +platform_set_drvdata (dev->platformdev, dev); + +/* Try to bind all sub drivers. */ + ret =component_bind_all (dev->dev, dev); +if (ret) + goto err_cleanup_vblank; + +/* Probe non kms sub drivers and virtual display driver. */ + ret =rockchip_drm_device_subdrv_probe (dev); +if (ret) + goto err_unbind_all; + +/* force connectors detection */ +drm_helper_hpd_irq_event (dev); + +return 0 ; + +err_unbind_all: +component_unbind_all (dev->dev, dev); +err_cleanup_vblank: +drm_vblank_cleanup (dev); +err_mode_config_cleanup: +drm_mode_config_cleanup (dev); +drm_release_iommu_mapping (dev); +err_free_private: +kfree (private); + +return ret; +} + +static int rockchip_drm_unload (struct drm_device *dev) +{ +rockchip_drm_device_subdrv_remove (dev); + +rockchip_drm_fbdev_fini (dev); +drm_vblank_cleanup (dev); +drm_kms_helper_poll_fini (dev); +drm_mode_config_cleanup (dev); + +drm_release_iommu_mapping (dev); +kfree (dev->dev_private); + +component_unbind_all (dev->dev, dev); + dev->dev_private =NULL ; + +return 0 ; +} + +static const struct file_operations rockchip_drm_gem_fops = { + .mmap = rockchip_drm_gem_mmap_buffer, +}; + +static int rockchip_drm_suspend (struct drm_device *dev,pm_message_t state) +{ +struct drm_connector *connector; + +drm_modeset_lock_all (dev); +list_for_each_entry (connector, &dev->mode_config.connector_list, head) { +int old_dpms = connector->dpms; + +if (connector->funcs->dpms) + connector->funcs->dpms (connector,DRM_MODE_DPMS_OFF ); + +/* Set the old mode back to the connector for resume */ + connector->dpms = old_dpms; + } +drm_modeset_unlock_all (dev); + +return 0 ; +} + +static int rockchip_drm_resume (struct drm_device *dev) +{ +struct drm_connector *connector; + +drm_modeset_lock_all (dev); +list_for_each_entry (connector, &dev->mode_config.connector_list, head) { +if (connector->funcs->dpms) + connector->funcs->dpms (connector, connector->dpms); + } +drm_modeset_unlock_all (dev); + +drm_helper_resume_force_mode (dev); + +return 0 ; +} + +static int rockchip_drm_open (struct drm_device *dev,struct drm_file *file) +{ +struct drm_rockchip_file_private *file_priv; +struct file *anon_filp; +int ret; + + file_priv =kzalloc (sizeof (*file_priv),GFP_KERNEL ); +if (!file_priv) +return -ENOMEM ; + + file->driver_priv = file_priv; + + ret =rockchip_drm_subdrv_open (dev, file); +if (ret) + goto err_file_priv_free; + + anon_filp =anon_inode_getfile ("rockchip_gem" , &rockchip_drm_gem_fops, +NULL ,0 ); +if (IS_ERR (anon_filp)) { + ret =PTR_ERR (anon_filp); + goto err_subdrv_close; + } + + anon_filp->f_mode =FMODE_READ |FMODE_WRITE ; + file_priv->anon_filp = anon_filp; + +return ret; + +err_subdrv_close: +rockchip_drm_subdrv_close (dev, file); + +err_file_priv_free: +kfree (file_priv); + file->driver_priv =NULL ; +return ret; +} + +static void rockchip_drm_preclose (struct drm_device *dev, +struct drm_file *file) +{ +rockchip_drm_subdrv_close (dev, file); +} + +static void rockchip_drm_postclose (struct drm_device *dev, +struct drm_file *file) +{ +struct rockchip_drm_private *private = dev->dev_private; +struct drm_rockchip_file_private *file_priv; +struct drm_pending_vblank_event *v, *vt; +struct drm_pending_event *e, *et; +unsigned long flags; + +if (!file->driver_priv) +return ; + +/* Release all events not unhandled by page flip handler. */ +spin_lock_irqsave (&dev->event_lock, flags); +list_for_each_entry_safe (v, vt, &private->pageflip_event_list, + base.link) { +if (v->base.file_priv == file) { +list_del (&v->base.link); +drm_vblank_put (dev, v->pipe); + v->base.destroy (&v->base); + } + } + +/* Release all events handled by page flip handler but not freed. */ +list_for_each_entry_safe (e, et, &file->event_list, link) { +list_del (&e->link); + e->destroy (e); + } +spin_unlock_irqrestore (&dev->event_lock, flags); + + file_priv = file->driver_priv; +if (file_priv->anon_filp) +fput (file_priv->anon_filp); + +kfree (file->driver_priv); + file->driver_priv =NULL ; +} + +static void rockchip_drm_lastclose (struct drm_device *dev) +{ +rockchip_drm_fbdev_restore_mode (dev); +} + +static const struct vm_operations_struct rockchip_drm_gem_vm_ops = { + .fault = rockchip_drm_gem_fault, + .open = drm_gem_vm_open, + .close = drm_gem_vm_close, +}; + +static const struct drm_ioctl_desc rockchip_ioctls[] = { +DRM_IOCTL_DEF_DRV (ROCKCHIP_GEM_CREATE , rockchip_drm_gem_create_ioctl, +DRM_UNLOCKED |DRM_AUTH ), +DRM_IOCTL_DEF_DRV (ROCKCHIP_GEM_MAP_OFFSET , + rockchip_drm_gem_map_offset_ioctl,DRM_UNLOCKED | +DRM_AUTH ), +DRM_IOCTL_DEF_DRV (ROCKCHIP_GEM_MMAP , + rockchip_drm_gem_mmap_ioctl,DRM_UNLOCKED |DRM_AUTH ), +DRM_IOCTL_DEF_DRV (ROCKCHIP_GEM_GET , + rockchip_drm_gem_get_ioctl,DRM_UNLOCKED ), +}; + +static const struct file_operations rockchip_drm_driver_fops = { + .owner =THIS_MODULE , + .open = drm_open, + .mmap = rockchip_drm_gem_mmap, + .poll = drm_poll, + .read = drm_read, + .unlocked_ioctl = drm_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = drm_compat_ioctl, +#endif + .release = drm_release, +}; + +static struct drm_driver rockchip_drm_driver = { + .driver_features =DRIVER_MODESET |DRIVER_GEM |DRIVER_PRIME , + .load = rockchip_drm_load, + .unload = rockchip_drm_unload, + .suspend = rockchip_drm_suspend, + .resume = rockchip_drm_resume, + .open = rockchip_drm_open, + .preclose = rockchip_drm_preclose, + .lastclose = rockchip_drm_lastclose, + .postclose = rockchip_drm_postclose, + .get_vblank_counter = drm_vblank_count, + .enable_vblank = rockchip_drm_crtc_enable_vblank, + .disable_vblank = rockchip_drm_crtc_disable_vblank, + .gem_free_object = rockchip_drm_gem_free_object, + .gem_vm_ops = &rockchip_drm_gem_vm_ops, + .dumb_create = rockchip_drm_gem_dumb_create, + .dumb_map_offset = rockchip_drm_gem_dumb_map_offset, + .dumb_destroy = drm_gem_dumb_destroy, + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, + .gem_prime_export = rockchip_dmabuf_prime_export, + .gem_prime_import = rockchip_dmabuf_prime_import, + .ioctls = rockchip_ioctls, + .num_ioctls =ARRAY_SIZE (rockchip_ioctls), + .fops = &rockchip_drm_driver_fops, + .name =DRIVER_NAME , + .desc =DRIVER_DESC , + .date =DRIVER_DATE , + .major =DRIVER_MAJOR , + .minor =DRIVER_MINOR , +}; + +#ifdef CONFIG_PM_SLEEP +static int rockchip_drm_sys_suspend (struct device *dev) +{ +struct drm_device *drm_dev =dev_get_drvdata (dev); +pm_message_t message; + +if (pm_runtime_suspended (dev)) +return 0 ; + + message.event =PM_EVENT_SUSPEND ; + +return rockchip_drm_suspend (drm_dev, message); +} + +static int rockchip_drm_sys_resume (struct device *dev) +{ +struct drm_device *drm_dev =dev_get_drvdata (dev); + +if (pm_runtime_suspended (dev)) +return 0 ; + +return rockchip_drm_resume (drm_dev); +} +#endif + +static const struct dev_pm_ops rockchip_drm_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (rockchip_drm_sys_suspend, + rockchip_drm_sys_resume) +}; + +int rockchip_drm_component_add (struct device *dev, +enum rockchip_drm_device_type dev_type, +enum rockchip_drm_output_type out_type) +{ +struct component_dev *cdev; + +if (dev_type !=ROCKCHIP_DEVICE_TYPE_CRTC && + dev_type !=ROCKCHIP_DEVICE_TYPE_CONNECTOR ) { +DRM_ERROR ("invalid device type.\n" ); +return -EINVAL ; + } + +mutex_lock (&drm_component_lock); + +/* +* Make sure to check if there is a component which has two device +* objects, for connector and for encoder/connector. +* It should make sure that crtc and encoder/connector drivers are +* ready before rockchip drm core binds them. +*/ +list_for_each_entry (cdev, &drm_component_list, list) { +if (cdev->out_type == out_type) { +/* +* If crtc and encoder/connector device objects are +* added already just return. +*/ +if (cdev->dev_type_flag == (ROCKCHIP_DEVICE_TYPE_CRTC | +ROCKCHIP_DEVICE_TYPE_CONNECTOR )) { +mutex_unlock (&drm_component_lock); +return 0 ; + } + +if (dev_type ==ROCKCHIP_DEVICE_TYPE_CRTC ) { + cdev->crtc_dev = dev; + cdev->dev_type_flag |= dev_type; + } + +if (dev_type ==ROCKCHIP_DEVICE_TYPE_CONNECTOR ) { + cdev->conn_dev = dev; + cdev->dev_type_flag |= dev_type; + } + +mutex_unlock (&drm_component_lock); +return 0 ; + } + } + +mutex_unlock (&drm_component_lock); + + cdev =kzalloc (sizeof (*cdev),GFP_KERNEL ); +if (!cdev) +return -ENOMEM ; + +if (dev_type ==ROCKCHIP_DEVICE_TYPE_CRTC ) + cdev->crtc_dev = dev; +if (dev_type ==ROCKCHIP_DEVICE_TYPE_CONNECTOR ) + cdev->conn_dev = dev; + + cdev->out_type = out_type; + cdev->dev_type_flag = dev_type; + +mutex_lock (&drm_component_lock); +list_add_tail (&cdev->list, &drm_component_list); +mutex_unlock (&drm_component_lock); + +return 0 ; +} + +void rockchip_drm_component_del (struct device *dev, +enum rockchip_drm_device_type dev_type) +{ +struct component_dev *cdev, *next; + +mutex_lock (&drm_component_lock); + +list_for_each_entry_safe (cdev, next, &drm_component_list, list) { +if (dev_type ==ROCKCHIP_DEVICE_TYPE_CRTC ) { +if (cdev->crtc_dev == dev) { + cdev->crtc_dev =NULL ; + cdev->dev_type_flag &= ~dev_type; + } + } + +if (dev_type ==ROCKCHIP_DEVICE_TYPE_CONNECTOR ) { +if (cdev->conn_dev == dev) { + cdev->conn_dev =NULL ; + cdev->dev_type_flag &= ~dev_type; + } + } + +/* +* Release cdev object only in case that both of crtc and +* encoder/connector device objects are NULL. +*/ +if (!cdev->crtc_dev && !cdev->conn_dev) { +list_del (&cdev->list); +kfree (cdev); + } + +break ; + } + +mutex_unlock (&drm_component_lock); +} + +static int compare_of (struct device *dev,void *data) +{ +return dev == (struct device *)data;
drivers/gpu/drm/rockchip/rockchip_drm_drv.c line 492
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_drv.c new file +10
-0+} + +static int rockchip_drm_add_components (struct device *dev,struct master *m) +{ +struct component_dev *cdev; +unsigned int attach_cnt =0 ; + +mutex_lock (&drm_component_lock); + +list_for_each_entry (cdev, &drm_component_list, list) {
hmm.. ok.. so you are kinda using the componentised device support. But really the intention behind that was to get *rid* of global lists like drm_component_list. Also, since you only add things that are already in drm_component_list, it is sort of defeating the point.
drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c
Quoted 1,360 lines
drivers/gpu/drm/rockchip/rockchip_drm_drv.c new file +126
-0+int ret; + +/* +* Add components to master only in case that crtc and +* encoder/connector device objects exist. +*/ +if (!cdev->crtc_dev || !cdev->conn_dev) +continue ; + + attach_cnt++; + +mutex_unlock (&drm_component_lock); + +/* +* lcdc and dp modules have same device object so add +* only crtc device object in this case. +* +* TODO. if dp module follows driver-model driver then +* below codes can be removed. +*/ +if (cdev->crtc_dev == cdev->conn_dev) { + ret =component_master_add_child (m, compare_of, + cdev->crtc_dev); +if (ret <0 ) +return ret; + + goto out_lock; + } + +/* +* Do not chage below call order. +* crtc device first should be added to master because +* connector/encoder need pipe number of crtc when they +* are created. +*/ + ret =component_master_add_child (m, compare_of, cdev->crtc_dev); + ret |=component_master_add_child (m, compare_of, + cdev->conn_dev); +if (ret <0 ) +return ret; + +out_lock: +mutex_lock (&drm_component_lock); + } + +mutex_unlock (&drm_component_lock); + +return attach_cnt ?0 : -ENODEV ; +} + +static int rockchip_drm_bind (struct device *dev) +{ +return drm_platform_init (&rockchip_drm_driver,to_platform_device (dev)); +} + +static void rockchip_drm_unbind (struct device *dev) +{ +drm_put_dev (dev_get_drvdata (dev)); +} + +static const struct component_master_ops rockchip_drm_ops = { + .add_components = rockchip_drm_add_components, + .bind = rockchip_drm_bind, + .unbind = rockchip_drm_unbind, +}; + +static int rockchip_drm_platform_probe (struct platform_device *pdev) +{ +int ret; + + pdev->dev.coherent_dma_mask =DMA_BIT_MASK (32 ); + rockchip_drm_driver.num_ioctls =ARRAY_SIZE (rockchip_ioctls); + + ret =component_master_add (&pdev->dev, &rockchip_drm_ops); +if (ret <0 ) +DRM_DEBUG_KMS ("re-tried by last sub driver probed later.\n" ); + +return 0 ; +} + +static int rockchip_drm_platform_remove (struct platform_device *pdev) +{ +component_master_del (&pdev->dev, &rockchip_drm_ops); + +return 0 ; +} + +static struct platform_driver rockchip_drm_platform_driver = { + .probe = rockchip_drm_platform_probe, + .remove = rockchip_drm_platform_remove, + .driver = { + .owner =THIS_MODULE , + .name ="rockchip-drm" , + .pm = &rockchip_drm_pm_ops, + }, +}; + +static int rockchip_drm_init (void ) +{ +int ret; + + rockchip_drm_pdev =platform_device_register_simple ("rockchip-drm" ,-1 , +NULL ,0 ); +if (IS_ERR (rockchip_drm_pdev)) +return PTR_ERR (rockchip_drm_pdev); + + ret =platform_driver_register (&rockchip_drm_platform_driver); +if (ret) + goto err_unregister_pd; + +return 0 ; + +err_unregister_pd: +platform_device_unregister (rockchip_drm_pdev); + +return ret; +} + +static void rockchip_drm_exit (void ) +{ +platform_device_unregister (rockchip_drm_pdev); +platform_driver_unregister (&rockchip_drm_platform_driver); +} + +module_init (rockchip_drm_init); +module_exit (rockchip_drm_exit);drivers/gpu/drm/rockchip/rockchip_drm_drv.h new file +319
-0@@ -0,0 +1,319 @@ +/* rockchip_drm_drv.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_drv.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_DRV_H_ +#define _ROCKCHIP_DRM_DRV_H_ + +#include <linux/module.h> + +#define MAX_CRTC 3 +#define MAX_PLANE 5 +#define MAX_FB_BUFFER 4 +#define DEFAULT_ZPOS -1 + +#define _wait_for (COND ,MS ) ({ \ + unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \ + int ret__ = 0; \ + while (!(COND)) { \ + if (time_after(jiffies, timeout__)) { \ + ret__ = -ETIMEDOUT; \ + break; \ + } \ + } \ + ret__; \ +}) + +#define wait_for (COND ,MS ) _wait_for(COND, MS) + +struct drm_device ; +struct drm_connector ; +struct rockchip_drm_overlay ; +struct rockchip_drm_manager ; + +extern unsigned int drm_vblank_offdelay; + +/* This enumerates device type. */ +enum rockchip_drm_device_type { +ROCKCHIP_DEVICE_TYPE_NONE , +ROCKCHIP_DEVICE_TYPE_CRTC , +ROCKCHIP_DEVICE_TYPE_CONNECTOR , +}; + +/* this enumerates display type. */ +enum rockchip_drm_output_type { +ROCKCHIP_DISPLAY_TYPE_NONE , +/* RGB or CPU Interface. */ +ROCKCHIP_DISPLAY_TYPE_LCD , +/* HDMI Interface. */ +ROCKCHIP_DISPLAY_TYPE_HDMI , +/* Virtual Display Interface. */ +ROCKCHIP_DISPLAY_TYPE_VIDI , +}; + +/* +* Rockchip drm common overlay structure. +* +* @fb_x: offset x on a framebuffer to be displayed. +* - the unit is screen coordinates. +* @fb_y: offset y on a framebuffer to be displayed. +* - the unit is screen coordinates. +* @fb_width: width of a framebuffer. +* @fb_height: height of a framebuffer. +* @src_width: width of a partial image to be displayed from framebuffer. +* @src_height: height of a partial image to be displayed from framebuffer. +* @crtc_x: offset x on hardware screen. +* @crtc_y: offset y on hardware screen. +* @crtc_width: window width to be displayed (hardware screen). +* @crtc_height: window height to be displayed (hardware screen). +* @mode_width: width of screen mode. +* @mode_height: height of screen mode. +* @refresh: refresh rate. +* @scan_flag: interlace or progressive way. +* (it could be DRM_MODE_FLAG_*) +* @bpp: pixel size.(in bit) +* @pixel_format: fourcc pixel format of this overlay +* @dma_addr: array of bus(accessed by dma) address to the memory region +* allocated for a overlay. +* @zpos: order of overlay layer(z position). +* @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. +* +* this structure is common to rockchip SoC and its contents would be copied +* to hardware specific overlay info. +*/ +struct rockchip_drm_overlay { +unsigned int fb_x; +unsigned int fb_y; +unsigned int fb_width; +unsigned int fb_height; +unsigned int src_width; +unsigned int src_height; +unsigned int crtc_x; +unsigned int crtc_y; +unsigned int crtc_width; +unsigned int crtc_height; +unsigned int mode_width; +unsigned int mode_height; +unsigned int refresh; +unsigned int scan_flag; +unsigned int bpp; +unsigned int pitch; +uint32_t pixel_format; +dma_addr_t dma_addr[MAX_FB_BUFFER ]; +int zpos; + +bool default_win; +bool color_key; +unsigned int index_color; +bool local_path; +bool transparency; +bool activated; +}; + +/* +* Rockchip DRM Display Structure. +* - this structure is common to analog tv, digital tv and lcd panel. +* +* @remove: cleans up the display for removal +* @mode_fixup: fix mode data comparing to hw specific display mode. +* @mode_set: convert drm_display_mode to hw specific display mode and +* would be called by encoder->mode_set(). +* @check_mode: check if mode is valid or not. +* @dpms: display device on or off. +* @commit: apply changes to hw +*/ +struct rockchip_drm_display ; +struct rockchip_drm_display_ops { +int (*create_connector)(struct rockchip_drm_display *display, +struct drm_encoder *encoder); +void (*remove)(struct rockchip_drm_display *display); +void (*mode_fixup)(struct rockchip_drm_display *display, +struct drm_connector *connector, +const struct drm_display_mode *mode, +struct drm_display_mode *adjusted_mode); +void (*mode_set)(struct rockchip_drm_display *display, +struct drm_display_mode *mode); +int (*check_mode)(struct rockchip_drm_display *display, +struct drm_display_mode *mode); +void (*dpms)(struct rockchip_drm_display *display,int mode); +void (*commit)(struct rockchip_drm_display *display); +}; + +/* +* Rockchip drm display structure, maps 1:1 with an encoder/connector +* +* @list: the list entry for this manager +* @type: one of ROCKCHIP_DISPLAY_TYPE_LCD and HDMI. +* @encoder: encoder object this display maps to +* @connector: connector object this display maps to +* @ops: pointer to callbacks for rockchip drm specific functionality +* @ctx: A pointer to the display's implementation specific context +*/ +struct rockchip_drm_display { +struct list_head list; +enum rockchip_drm_output_type type; +struct drm_encoder *encoder; +struct drm_connector *connector; +struct rockchip_drm_display_ops *ops; +void *ctx; +}; + +/* +* Rockchip drm manager ops +* +* @dpms: control device power. +* @mode_fixup: fix mode data before applying it +* @mode_set: set the given mode to the manager +* @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. +* @wait_for_vblank: wait for vblank interrupt to make sure that +* hardware overlay is updated. +* @win_mode_set: copy drm overlay info to hw specific overlay info. +* @win_commit: apply hardware specific overlay data to registers. +* @win_enable: enable hardware specific overlay. +* @win_disable: disable hardware specific overlay. +*/ +struct rockchip_drm_manager_ops { +void (*dpms)(struct rockchip_drm_manager *mgr,int mode); +bool (*mode_fixup)(struct rockchip_drm_manager *mgr, +const struct drm_display_mode *mode, +struct drm_display_mode *adjusted_mode); +void (*mode_set)(struct rockchip_drm_manager *mgr, +const struct drm_display_mode *mode); +void (*commit)(struct rockchip_drm_manager *mgr); +int (*enable_vblank)(struct rockchip_drm_manager *mgr); +void (*disable_vblank)(struct rockchip_drm_manager *mgr); +void (*wait_for_vblank)(struct rockchip_drm_manager *mgr); +void (*win_mode_set)(struct rockchip_drm_manager *mgr, +struct rockchip_drm_overlay *overlay); +void (*win_commit)(struct rockchip_drm_manager *mgr,int zpos); +void (*win_enable)(struct rockchip_drm_manager *mgr,int zpos); +void (*win_disable)(struct rockchip_drm_manager *mgr,int zpos); +}; + +/* +* Rockchip drm common manager structure, maps 1:1 with a crtc +* +* @list: the list entry for this manager +* @type: one of ROCKCHIP_DISPLAY_TYPE_LCD and HDMI. +* @drm_dev: pointer to the drm device +* @crtc: crtc object. +* @pipe: the pipe number for this crtc/manager +* @ops: pointer to callbacks for rockchip drm specific functionality +* @ctx: A pointer to the manager's implementation specific context +*/ +struct rockchip_drm_manager { +struct list_head list; +enum rockchip_drm_output_type type; +struct drm_device *drm_dev; +struct drm_crtc *crtc; +int pipe; +struct rockchip_drm_manager_ops *ops; +void *ctx; +}; + +struct drm_rockchip_file_private { +struct file *anon_filp; +}; + +/* +* Rockchip drm private structure. +* +* @da_start: start address to device address space. +* with iommu, device address space starts from this address +* otherwise default one. +* @da_space_size: size of device address space. +* if 0 then default value is used for it. +* @pipe: the pipe number for this crtc/manager. +*/ +struct rockchip_drm_private { +struct drm_fb_helper *fb_helper; + +/* list head for new event to be added. */ +struct list_head pageflip_event_list; + +/* +* created crtc object would be contained at this array and +* this array is used to be aware of which crtc did it request vblank. +*/ +struct drm_crtc *crtc[MAX_CRTC ]; +struct drm_property *plane_zpos_property; +struct drm_property *crtc_mode_property; + +unsigned long da_start; +unsigned long da_space_size; + +unsigned int pipe; +}; + +/* +* Rockchip drm sub driver structure. +* +* @list: sub driver has its own list object to register to rockchip drm driver. +* @dev: pointer to device object for subdrv device driver. +* @drm_dev: pointer to drm_device and this pointer would be set +* when sub driver calls rockchip_drm_subdrv_register(). +* @manager: subdrv has its own manager to control a hardware appropriately +* and we can access a hardware drawing on this manager. +* @probe: this callback would be called by rockchip drm driver after +* subdrv is registered to it. +* @remove: this callback is used to release resources created +* by probe callback. +* @open: this would be called with drm device file open. +* @close: this would be called with drm device file close. +*/ +struct rockchip_drm_subdrv { +struct list_head list; +struct device *dev; +struct drm_device *drm_dev; + +int (*probe)(struct drm_device *drm_dev,struct device *dev); +void (*remove)(struct drm_device *drm_dev,struct device *dev); +int (*open)(struct drm_device *drm_dev,struct device *dev, +struct drm_file *file); +void (*close)(struct drm_device *drm_dev,struct device *dev, +struct drm_file *file); +}; + +/* This function would be called by non kms drivers. */ +int rockchip_drm_subdrv_register (struct rockchip_drm_subdrv *drm_subdrv); + +/* this function removes subdrv list from rockchip drm driver */ +int rockchip_drm_subdrv_unregister (struct rockchip_drm_subdrv *drm_subdrv); + +int rockchip_drm_device_subdrv_probe (struct drm_device *dev); +int rockchip_drm_device_subdrv_remove (struct drm_device *dev); +int rockchip_drm_subdrv_open (struct drm_device *dev,struct drm_file *file); +void rockchip_drm_subdrv_close (struct drm_device *dev,struct drm_file *file); + +/* This function creates a encoder and a connector, and initializes them. */ +int rockchip_drm_create_enc_conn (struct drm_device *dev, +struct rockchip_drm_display *display); + +int rockchip_drm_component_add (struct device *dev, +enum rockchip_drm_device_type dev_type, +enum rockchip_drm_output_type out_type); + +void rockchip_drm_component_del (struct device *dev, +enum rockchip_drm_device_type dev_type); +#endif /* _ROCKCHIP_DRM_DRV_H_ */ drivers/gpu/drm/rockchip/rockchip_drm_encoder.c new file +206
-0@@ -0,0 +1,206 @@ +/* rockchip_drm_encoder.c +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_encoder.c +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <drm/drmP.h> +#include <drm/drm_crtc_helper.h> + +#include "rockchip_drm_drv.h" +#include "rockchip_drm_encoder.h" + +#define to_rockchip_encoder (x) container_of(x, struct rockchip_drm_encoder,\ + drm_encoder) + +/* +* rockchip specific encoder structure. +* +* @drm_encoder: encoder object. +* @display: the display structure that maps to this encoder +*/ +struct rockchip_drm_encoder { +struct drm_encoder drm_encoder; +struct rockchip_drm_display *display; +}; + +static void rockchip_drm_encoder_dpms (struct drm_encoder *encoder,int mode) +{ +struct rockchip_drm_encoder *rockchip_encoder = +to_rockchip_encoder (encoder); +struct rockchip_drm_display *display = rockchip_encoder->display; + +DRM_DEBUG_KMS ("encoder dpms: %d\n" , mode); + +if (display->ops->dpms) + display->ops->dpms (display, mode); +} + +static bool +rockchip_drm_encoder_mode_fixup (struct drm_encoder *encoder, +const struct drm_display_mode *mode, +struct drm_display_mode *adjusted_mode) +{ +struct drm_device *dev = encoder->dev; +struct rockchip_drm_encoder *rockchip_encoder = +to_rockchip_encoder (encoder); +struct rockchip_drm_display *display = rockchip_encoder->display; +struct drm_connector *connector; + +list_for_each_entry (connector, &dev->mode_config.connector_list, head) { +if (connector->encoder != encoder) +continue ; + +if (display->ops->mode_fixup) + display->ops->mode_fixup (display, connector, mode, + adjusted_mode); + } + +return true; +} + +static void rockchip_drm_encoder_mode_set (struct drm_encoder *encoder, +struct drm_display_mode *mode, +struct drm_display_mode *adjusted_mode) +{ +struct rockchip_drm_encoder *rockchip_encoder = +to_rockchip_encoder (encoder); +struct rockchip_drm_display *display = rockchip_encoder->display; + +if (display->ops->mode_set) + display->ops->mode_set (display, adjusted_mode); +} + +static void rockchip_drm_encoder_prepare (struct drm_encoder *encoder) +{ +/* drm framework doesn't check NULL. */ +} + +static void rockchip_drm_encoder_commit (struct drm_encoder *encoder) +{ +struct rockchip_drm_encoder *rockchip_encoder = +to_rockchip_encoder (encoder); +struct rockchip_drm_display *display = rockchip_encoder->display; + +if (display->ops->dpms) + display->ops->dpms (display,DRM_MODE_DPMS_ON ); + +if (display->ops->commit) + display->ops->commit (display); +} + +static void rockchip_drm_encoder_disable (struct drm_encoder *encoder) +{ +struct drm_plane *plane; +struct drm_device *dev = encoder->dev; + +rockchip_drm_encoder_dpms (encoder,DRM_MODE_DPMS_OFF ); + +/* all planes connected to this encoder should be also disabled. */ +drm_for_each_legacy_plane (plane, &dev->mode_config.plane_list) { +if (plane->crtc == encoder->crtc) + plane->funcs->disable_plane (plane); + } +} + +static struct drm_encoder_helper_funcs rockchip_encoder_helper_funcs = { + .dpms = rockchip_drm_encoder_dpms, + .mode_fixup = rockchip_drm_encoder_mode_fixup, + .mode_set = rockchip_drm_encoder_mode_set, + .prepare = rockchip_drm_encoder_prepare, + .commit = rockchip_drm_encoder_commit, + .disable = rockchip_drm_encoder_disable, +}; + +static void rockchip_drm_encoder_destroy (struct drm_encoder *encoder) +{ +struct rockchip_drm_encoder *rockchip_encoder = +to_rockchip_encoder (encoder); + +drm_encoder_cleanup (encoder); +kfree (rockchip_encoder); +} + +static struct drm_encoder_funcs rockchip_encoder_funcs = { + .destroy = rockchip_drm_encoder_destroy, +}; + +static unsigned int rockchip_drm_encoder_clones (struct drm_encoder *encoder) +{ +struct drm_encoder *clone; +struct drm_device *dev = encoder->dev; +struct rockchip_drm_encoder *rockchip_encoder = +to_rockchip_encoder (encoder); +struct rockchip_drm_display *display = rockchip_encoder->display; +unsigned int clone_mask =0 ; +int cnt =0 ; + +list_for_each_entry (clone, &dev->mode_config.encoder_list, head) { +switch (display->type) { +case ROCKCHIP_DISPLAY_TYPE_LCD : +case ROCKCHIP_DISPLAY_TYPE_HDMI : + clone_mask |= (1 << (cnt++)); +break ; +default : +continue ; + } + } + +return clone_mask; +} + +void rockchip_drm_encoder_setup (struct drm_device *dev) +{ +struct drm_encoder *encoder; + +list_for_each_entry (encoder, &dev->mode_config.encoder_list, head) + encoder->possible_clones = +rockchip_drm_encoder_clones (encoder); +} + +struct drm_encoder *rockchip_drm_encoder_create (struct drm_device *dev, +struct rockchip_drm_display *display, +unsigned long possible_crtcs) +{ +struct drm_encoder *encoder; +struct rockchip_drm_encoder *rockchip_encoder; + +if (!possible_crtcs) +return NULL ; + + rockchip_encoder =kzalloc (sizeof (*rockchip_encoder),GFP_KERNEL ); +if (!rockchip_encoder) +return NULL ; + + rockchip_encoder->display = display; + encoder = &rockchip_encoder->drm_encoder; + encoder->possible_crtcs = possible_crtcs; + +DRM_DEBUG_KMS ("possible_crtcs = 0x%x\n" , encoder->possible_crtcs); + +drm_encoder_init (dev, encoder, &rockchip_encoder_funcs, +DRM_MODE_ENCODER_TMDS ); + +drm_encoder_helper_add (encoder, &rockchip_encoder_helper_funcs); + +DRM_DEBUG_KMS ("encoder has been created\n" ); + +return encoder; +} + +struct rockchip_drm_display * +rockchip_drm_get_display (struct drm_encoder *encoder) +{ +return to_rockchip_encoder (encoder)->display; +}drivers/gpu/drm/rockchip/rockchip_drm_encoder.h new file +30
-0@@ -0,0 +1,30 @@ +/* rockchip_drm_encoder.h +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_encoder.h +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ROCKCHIP_DRM_ENCODER_H_ +#define _ROCKCHIP_DRM_ENCODER_H_ + +struct rockchip_drm_manager ; + +void rockchip_drm_encoder_setup (struct drm_device *dev); +struct drm_encoder *rockchip_drm_encoder_create (struct drm_device *dev, +struct rockchip_drm_display *mgr, +unsigned long possible_crtcs); +struct rockchip_drm_display * +rockchip_drm_get_display (struct drm_encoder *encoder); + +#endif /* _ROCKCHIP_DRM_ENCODER_H_ */ drivers/gpu/drm/rockchip/rockchip_drm_fb.c new file +333
-0@@ -0,0 +1,333 @@ +/* rockchip_drm_fb.c +* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* Author:mark yao <[email protected]> +* +* based on exynos_drm_fb.c +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <drm/drmP.h> +#include <drm/drm_crtc.h> +#include <drm/drm_crtc_helper.h> +#include <drm/drm_fb_helper.h> +#include <uapi/drm/rockchip_drm.h> + +#include "rockchip_drm_drv.h" +#include "rockchip_drm_fb.h" +#include "rockchip_drm_fbdev.h" +#include "rockchip_drm_gem.h" +#include "rockchip_drm_iommu.h" +#include "rockchip_drm_crtc.h" + +#define to_rockchip_fb (x) container_of(x, struct rockchip_drm_fb, fb) + +/* +* rockchip specific framebuffer structure. +* +* @fb: drm framebuffer obejct. +* @buf_cnt: a buffer count to drm framebuffer. +* @rockchip_gem_obj: array of rockchip specific +* gem object containing a gem object. +*/ +struct rockchip_drm_fb { +struct drm_framebuffer fb; +unsigned int buf_cnt; +struct rockchip_drm_gem_obj *rockchip_gem_obj[MAX_FB_BUFFER ]; +}; + +static int check_fb_gem_memory_type (struct drm_device *drm_dev, +struct rockchip_drm_gem_obj *rockchip_gem_obj) +{ +unsigned int flags; + +/* +* if rockchip drm driver supports iommu then framebuffer can use +* all the buffer types. +*/ +if (is_drm_iommu_supported (drm_dev)) +return 0 ; + + flags = rockchip_gem_obj->flags; + +/* +* without iommu support, not support physically non-continuous memory +* for framebuffer. +*/ +if (IS_NONCONTIG_BUFFER (flags)) { +DRM_ERROR ("cannot use this gem memory type for fb.\n" ); +return -EINVAL ; + } + +return 0 ; +} + +static void rockchip_drm_fb_destroy (struct drm_framebuffer *fb) +{ +struct rockchip_drm_fb *rockchip_fb =to_rockchip_fb (fb); +unsigned int i; + +/* make sure that overlay data are updated before relesing fb. */ +rockchip_drm_crtc_complete_scanout (fb); + +drm_framebuffer_cleanup (fb); + +for (i =0 ; i <ARRAY_SIZE (rockchip_fb->rockchip_gem_obj); i++) { +struct drm_gem_object *obj; + +if (rockchip_fb->rockchip_gem_obj[i] ==NULL ) +continue ; + + obj = &rockchip_fb->rockchip_gem_obj[i]->base; +drm_gem_object_unreference_unlocked (obj); + } + +kfree (rockchip_fb); + rockchip_fb =NULL ; +} + +static int rockchip_drm_fb_create_handle (struct drm_framebuffer *fb, +struct drm_file *file_priv, +unsigned int *handle) +{ +struct rockchip_drm_fb *rockchip_fb =to_rockchip_fb (fb); + +/* This fb should have only one gem object. */ +if (WARN_ON (rockchip_fb->buf_cnt !=1 )) +return -EINVAL ; + +return drm_gem_handle_create (file_priv, + &rockchip_fb->rockchip_gem_obj[0 ]->base, handle); +} + +static int rockchip_drm_fb_dirty (struct drm_framebuffer *fb, +struct drm_file *file_priv,unsigned flags, +unsigned color,struct drm_clip_rect *clips, +unsigned num_clips) +{ +/* TODO */ + +return 0 ; +} + +static struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { + .destroy = rockchip_drm_fb_destroy, + .create_handle = rockchip_drm_fb_create_handle, + .dirty = rockchip_drm_fb_dirty, +}; + +void rockchip_drm_fb_set_buf_cnt (struct drm_framebuffer *fb, +unsigned int cnt) +{ +struct rockchip_drm_fb *rockchip_fb; + + rockchip_fb =to_rockchip_fb (fb); + + rockchip_fb->buf_cnt = cnt; +} + +unsigned int rockchip_drm_fb_get_buf_cnt (struct drm_framebuffer *fb) +{ +struct rockchip_drm_fb *rockchip_fb; + + rockchip_fb =to_rockchip_fb (fb); + +return rockchip_fb->buf_cnt; +} + +struct drm_framebuffer * +rockchip_drm_framebuffer_init (struct drm_device *dev, +struct drm_mode_fb_cmd2 *mode_cmd, +struct drm_gem_object *obj) +{ +struct rockchip_drm_fb *rockchip_fb; +struct rockchip_drm_gem_obj *rockchip_gem_obj; +int ret; + + rockchip_gem_obj =to_rockchip_gem_obj (obj); + + ret =check_fb_gem_memory_type (dev, rockchip_gem_obj); +if (ret <0 ) { +DRM_ERROR ("cannot use this gem memory type for fb.\n" ); +return ERR_PTR (-EINVAL ); + } + + rockchip_fb =kzalloc (sizeof (*rockchip_fb),GFP_KERNEL ); +if (!rockchip_fb) +return ERR_PTR (-ENOMEM ); + +drm_helper_mode_fill_fb_struct (&rockchip_fb->fb, mode_cmd); + rockchip_fb->rockchip_gem_obj[0 ] = rockchip_gem_obj; + + ret =drm_framebuffer_init (dev, &rockchip_fb->fb, + &rockchip_drm_fb_funcs); +if (ret) { +DRM_ERROR ("failed to initialize framebuffer\n" ); +return ERR_PTR (ret); + } + +return &rockchip_fb->fb; +} + +static u32 rockchip_drm_format_num_buffers (struct drm_mode_fb_cmd2 *mode_cmd) +{ +unsigned int cnt =0 ; + +if (mode_cmd->pixel_format !=DRM_FORMAT_NV12 ) +return drm_format_num_planes (mode_cmd->pixel_format); + +while (cnt !=MAX_FB_BUFFER ) { +if (!mode_cmd->handles[cnt]) +break ; + cnt++; + } + +/* +* check if NV12 or NV12M. +* +* NV12 +* handles[0] = base1, offsets[0] = 0 +* handles[1] = base1, offsets[1] = Y_size +* +* NV12M +* handles[0] = base1, offsets[0] = 0 +* handles[1] = base2, offsets[1] = 0 +*/ +if (cnt ==2 ) { +/* +* in case of NV12 format, offsets[1] is not 0 and +* handles[0] is same as handles[1]. Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_fb.h new file +39
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c new file +271
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
well, this is at least *different* from how the other drivers operate. I guess it avoids getting stuck with a 1024x768 fb console if nothing connected at boot. But it also means the fbdev device won't show up. Which doesn't seem desirable.
drivers/gpu/drm/rockchip/rockchip_drm_gem.c
Quoted 617 lines
drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c new file +109
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h new file +26
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_gem.c new file +470
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
I guess this get/put_vma stuff is just copy/pasta from exynos userptr stuff. Please drop it, since it isn't needed.
drivers/gpu/drm/rockchip/rockchip_drm_gem.h
Quoted 410 lines
drivers/gpu/drm/rockchip/rockchip_drm_gem.c new file +268
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_gem.h new file +136
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
really.. please, no userptr!
drivers/gpu/drm/rockchip/rockchip_drm_iommu.c
Quoted 115 lines
drivers/gpu/drm/rockchip/rockchip_drm_gem.h new file +61
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_iommu.c new file +48
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
using arm_iommu_* APIs directly looks a bit strange..
is there a reason for not using iommu_* API's directly?
include/uapi/drm/rockchip_drm.h
Quoted 617 lines
drivers/gpu/drm/rockchip/rockchip_drm_iommu.c new file +101
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_iommu.h new file +76
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_plane.c new file +290
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/rockchip/rockchip_drm_plane.h new file +30
-0Lines of this file are not shown. View the raw message.
include/uapi/drm/rockchip_drm.h new file +96
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
for userspace facing interfaces, I think you should stick with #define's
BR,
-R
Quoted 68 lines
include/uapi/drm/rockchip_drm.h new file +59
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Part of the diff is not shown here. View the raw message.