Skip to contentSkip to conversation

Add Unisoc's drm kms module

RFC PATCH Superseded Kevin Tang 2 participants 12 messages Dec 16, 2019 – Jan 15, 2020

Subsystems (4)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Kevin Tang

author
#0 lore raw

cover Add Unisoc's drm kms module

Hi all,
This patch is our Unisoc's new drm display driver, This driver provides support for the Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher

ChangeList:
v1:
1. upstream modeset and atomic at first commit
2. remove some unused code
3. use alpha and blend_mode properties
4. add yaml support
5. remove auto-adaptive panel driver
6. remove CMA keywords from gem driver

Best,
Kevin Tang

Kevin Tang (6):
dt-bindings: display: add Unisoc's drm master bindings drm/sprd: add Unisoc's drm kms master
dt-bindings: display: add Unisoc's dpu bindings drm/sprd: add Unisoc's drm display controller driver
dt-bindings: display: add Unisoc's mipi dsi&dphy bindings drm/sprd: add Unisoc's drm mipi dsi&dphy driver

 .../devicetree/bindings/display/sprd/dphy.yaml     |   78 ++
 .../devicetree/bindings/display/sprd/dpu.yaml      |   85 ++
 .../devicetree/bindings/display/sprd/drm.yaml      |   38 +
 .../devicetree/bindings/display/sprd/dsi.yaml      |  101 ++
 drivers/gpu/drm/Kconfig                            |    2 +
 drivers/gpu/drm/Makefile                           |    1 +
 drivers/gpu/drm/sprd/Kconfig                       |   14 +
 drivers/gpu/drm/sprd/Makefile                      |   16 +
 drivers/gpu/drm/sprd/disp_lib.c                    |   93 ++
 drivers/gpu/drm/sprd/disp_lib.h                    |   34 +
 drivers/gpu/drm/sprd/dphy/Makefile                 |    7 +
 drivers/gpu/drm/sprd/dphy/pll/Makefile             |    3 +
 drivers/gpu/drm/sprd/dphy/pll/megacores_sharkle.c  |  640 +++++++++
 drivers/gpu/drm/sprd/dphy/sprd_dphy_api.c          |  254 ++++
 drivers/gpu/drm/sprd/dphy/sprd_dphy_hal.h          |  329 +++++
 drivers/gpu/drm/sprd/dpu/Makefile                  |    8 +
 drivers/gpu/drm/sprd/dpu/dpu_r2p0.c                |  798 +++++++++++
 drivers/gpu/drm/sprd/dsi/Makefile                  |    7 +
 drivers/gpu/drm/sprd/dsi/core/Makefile             |    3 +
 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.c      | 1186 ++++++++++++++++
 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.h      | 1417 ++++++++++++++++++++
 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0_ppi.c  |  392 ++++++
 drivers/gpu/drm/sprd/dsi/sprd_dsi_api.c            |  544 ++++++++
 drivers/gpu/drm/sprd/dsi/sprd_dsi_api.h            |   28 +
 drivers/gpu/drm/sprd/dsi/sprd_dsi_hal.h            | 1102 +++++++++++++++
 drivers/gpu/drm/sprd/sprd_dphy.c                   |  218 +++
 drivers/gpu/drm/sprd/sprd_dphy.h                   |  106 ++
 drivers/gpu/drm/sprd/sprd_dpu.c                    |  671 +++++++++
 drivers/gpu/drm/sprd/sprd_dpu.h                    |  138 ++
 drivers/gpu/drm/sprd/sprd_drm.c                    |  286 ++++
 drivers/gpu/drm/sprd/sprd_drm.h                    |   18 +
 drivers/gpu/drm/sprd/sprd_dsi.c                    |  606 +++++++++
 drivers/gpu/drm/sprd/sprd_dsi.h                    |  195 +++
 drivers/gpu/drm/sprd/sprd_gem.c                    |  178 +++
 drivers/gpu/drm/sprd/sprd_gem.h                    |   30 +
 35 files changed, 9626 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sprd/dphy.yaml
 create mode 100644 Documentation/devicetree/bindings/display/sprd/dpu.yaml
 create mode 100644 Documentation/devicetree/bindings/display/sprd/drm.yaml
 create mode 100644 Documentation/devicetree/bindings/display/sprd/dsi.yaml
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/disp_lib.c
 create mode 100644 drivers/gpu/drm/sprd/disp_lib.h
 create mode 100644 drivers/gpu/drm/sprd/dphy/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dphy/pll/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dphy/pll/megacores_sharkle.c
 create mode 100644 drivers/gpu/drm/sprd/dphy/sprd_dphy_api.c
 create mode 100644 drivers/gpu/drm/sprd/dphy/sprd_dphy_hal.h
 create mode 100644 drivers/gpu/drm/sprd/dpu/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dpu/dpu_r2p0.c
 create mode 100644 drivers/gpu/drm/sprd/dsi/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dsi/core/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.c
 create mode 100644 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.h
 create mode 100644 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0_ppi.c
 create mode 100644 drivers/gpu/drm/sprd/dsi/sprd_dsi_api.c
 create mode 100644 drivers/gpu/drm/sprd/dsi/sprd_dsi_api.h
 create mode 100644 drivers/gpu/drm/sprd/dsi/sprd_dsi_hal.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_dphy.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dphy.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.h
Signature · 1 line
2.7.4
author
#1 lore raw

RFC PATCH 1/6 dt-bindings: display: add Unisoc's drm master bindings

From: Kevin Tang <[email protected]>

The Unisoc DRM master device is a virtual device needed to list all DPU devices or other display interface nodes that comprise the graphics subsystem

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 .../devicetree/bindings/display/sprd/drm.yaml      | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sprd/drm.yaml
Documentation/devicetree/bindings/display/sprd/drm.yaml new file +38 -0
new file mode 100644
index 0000000..1614ca6
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sprd/drm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc DRM master device
+
+maintainers:
+  - David Airlie <[email protected]>
+  - Daniel Vetter <[email protected]>
+  - Rob Herring <[email protected]>
+  - Mark Rutland <[email protected]>
+
+description: |
+  The Unisoc DRM master device is a virtual device needed to list all
+  DPU devices or other display interface nodes that comprise the
+  graphics subsystem.
+
+properties:
+  compatible:
+    const: sprd,display-subsystem
+
+  ports:
+    description:
+      Should contain a list of phandles pointing to display interface port
+      of DPU devices.
+
+required:
+  - compatible
+  - ports
+
+examples:
+  - |
+    display-subsystem {
+        compatible = "sprd,display-subsystem";
+        ports = <&dpu_out>;
+    };
\ No newline at end of file
Signature · 1 line
2.7.4
author
#2 lore raw

RFC PATCH 2/6 drm/sprd: add Unisoc's drm kms master

In reply to Kevin Tang

From: Kevin Tang <[email protected]>

Adds drm support for the Unisoc's display subsystem.

This is drm device and gem driver. This driver provides support for the Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 drivers/gpu/drm/Kconfig         |   2 +
 drivers/gpu/drm/Makefile        |   1 +
 drivers/gpu/drm/sprd/Kconfig    |  14 ++
 drivers/gpu/drm/sprd/Makefile   |   8 ++
 drivers/gpu/drm/sprd/sprd_drm.c | 286 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
 drivers/gpu/drm/sprd/sprd_gem.c | 178 +++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_gem.h |  30 +++++
 8 files changed, 535 insertions(+)
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.h
drivers/gpu/drm/Kconfig +2 -0
index bfdadc3..cead12c 100644
@@ -387,6 +387,8 @@ source "drivers/gpu/drm/aspeed/Kconfig"
 
 source "drivers/gpu/drm/mcde/Kconfig"
 
+source "drivers/gpu/drm/sprd/Kconfig"
+
 # Keep legacy drivers last
 
 menuconfig DRM_LEGACY
drivers/gpu/drm/Makefile +1 -0
index 9f1c7c4..85ca211 100644
@@ -122,3 +122,4 @@ obj-$(CONFIG_DRM_LIMA)  += lima/
 obj-$(CONFIG_DRM_PANFROST) += panfrost/
 obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/
 obj-$(CONFIG_DRM_MCDE) += mcde/
+obj-$(CONFIG_DRM_SPRD) += sprd/
drivers/gpu/drm/sprd/Kconfig new file +14 -0
new file mode 100644
index 0000000..79f286b
@@ -0,0 +1,14 @@
+config DRM_SPRD
+	tristate "DRM Support for Unisoc SoCs Platform"
+	depends on ARCH_SPRD
+	depends on DRM && OF
+	select DRM_KMS_HELPER
+	select DRM_GEM_CMA_HELPER
+	select DRM_KMS_CMA_HELPER
+	select DRM_MIPI_DSI
+	select DRM_PANEL
+	select VIDEOMODE_HELPERS
+	select BACKLIGHT_CLASS_DEVICE
+	help
+	  Choose this option if you have a Unisoc chipsets.
+	  If M is selected the module will be called sprd-drm.
\ No newline at end of file
drivers/gpu/drm/sprd/Makefile new file +8 -0
new file mode 100644
index 0000000..df0b316
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ccflags-y += -Iinclude/drm
+
+subdir-ccflags-y += -I$(src)
+
+obj-y := sprd_drm.o \
+	sprd_gem.o
\ No newline at end of file
drivers/gpu/drm/sprd/sprd_drm.c new file +286 -0

286 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_drm.h new file +16 -0
new file mode 100644
index 0000000..137cb27
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _SPRD_DRM_H_
+#define _SPRD_DRM_H_
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_print.h>
+
+struct sprd_drm {
+	struct drm_device *drm;
+};
+
+#endif /* _SPRD_DRM_H_ */
drivers/gpu/drm/sprd/sprd_gem.c new file +178 -0

178 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_gem.h new file +30 -0
new file mode 100644
index 0000000..b6740bd
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _SPRD_GEM_H_
+#define _SPRD_GEM_H_
+
+#include <drm/drm_gem.h>
+
+struct sprd_gem_obj {
+	struct drm_gem_object	base;
+	dma_addr_t		dma_addr;
+	struct sg_table		*sgtb;
+	void			*vaddr;
+};
+
+#define to_sprd_gem_obj(x)	container_of(x, struct sprd_gem_obj, base)
+
+void sprd_gem_free_object(struct drm_gem_object *gem);
+int sprd_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
+			    struct drm_mode_create_dumb *args);
+int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma);
+int sprd_gem_prime_mmap(struct drm_gem_object *obj,
+			 struct vm_area_struct *vma);
+struct sg_table *sprd_gem_prime_get_sg_table(struct drm_gem_object *obj);
+struct drm_gem_object *sprd_gem_prime_import_sg_table(struct drm_device *dev,
+		struct dma_buf_attachment *attach, struct sg_table *sgtb);
+
+#endif
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH RFC v1 2/6] drm/sprd: add Unisoc's drm kms master

Hi Kevin

Am 16.12.19 um 12:40 schrieb Kevin Tang:

Quoted 470 lines

From: Kevin Tang <[email protected]>

Adds drm support for the Unisoc's display subsystem.

This is drm device and gem driver. This driver provides support for the Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 drivers/gpu/drm/Kconfig         |   2 +
 drivers/gpu/drm/Makefile        |   1 +
 drivers/gpu/drm/sprd/Kconfig    |  14 ++
 drivers/gpu/drm/sprd/Makefile   |   8 ++
 drivers/gpu/drm/sprd/sprd_drm.c | 286 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
 drivers/gpu/drm/sprd/sprd_gem.c | 178 +++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_gem.h |  30 +++++
 8 files changed, 535 insertions(+)
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.h
drivers/gpu/drm/Kconfig +2 -0
index bfdadc3..cead12c 100644
@@ -387,6 +387,8 @@ source "drivers/gpu/drm/aspeed/Kconfig"
 
 source "drivers/gpu/drm/mcde/Kconfig"
 
+source "drivers/gpu/drm/sprd/Kconfig"
+
 # Keep legacy drivers last
 
 menuconfig DRM_LEGACY
drivers/gpu/drm/Makefile +1 -0
index 9f1c7c4..85ca211 100644
@@ -122,3 +122,4 @@ obj-$(CONFIG_DRM_LIMA)  += lima/
 obj-$(CONFIG_DRM_PANFROST) += panfrost/
 obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/
 obj-$(CONFIG_DRM_MCDE) += mcde/
+obj-$(CONFIG_DRM_SPRD) += sprd/
drivers/gpu/drm/sprd/Kconfig new file +14 -0
new file mode 100644
index 0000000..79f286b
@@ -0,0 +1,14 @@
+config DRM_SPRD
+	tristate "DRM Support for Unisoc SoCs Platform"
+	depends on ARCH_SPRD
+	depends on DRM && OF
+	select DRM_KMS_HELPER
+	select DRM_GEM_CMA_HELPER
+	select DRM_KMS_CMA_HELPER
+	select DRM_MIPI_DSI
+	select DRM_PANEL
+	select VIDEOMODE_HELPERS
+	select BACKLIGHT_CLASS_DEVICE
+	help
+	  Choose this option if you have a Unisoc chipsets.
+	  If M is selected the module will be called sprd-drm.
\ No newline at end of file
drivers/gpu/drm/sprd/Makefile new file +8 -0
new file mode 100644
index 0000000..df0b316
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ccflags-y += -Iinclude/drm
+
+subdir-ccflags-y += -I$(src)
+
+obj-y := sprd_drm.o \
+	sprd_gem.o
\ No newline at end of file
drivers/gpu/drm/sprd/sprd_drm.c new file +286 -0
new file mode 100644
index 0000000..4aee25fa4
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#include <linux/component.h>
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of_graph.h>
+#include <linux/of_platform.h>
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_gem_cma_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+
+#include "sprd_drm.h"
+#include "sprd_gem.h"
+
+#define DRIVER_NAME	"sprd"
+#define DRIVER_DESC	"Spreadtrum SoCs' DRM Driver"
+#define DRIVER_DATE	"20191101"
+#define DRIVER_MAJOR	1
+#define DRIVER_MINOR	0
+
+static const struct drm_mode_config_helper_funcs sprd_drm_mode_config_helper = {
+	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
+};
+
+static const struct drm_mode_config_funcs sprd_drm_mode_config_funcs = {
+	.fb_create = drm_gem_fb_create,
+	.atomic_check = drm_atomic_helper_check,
+	.atomic_commit = drm_atomic_helper_commit,
+};
+
+static void sprd_drm_mode_config_init(struct drm_device *drm)
+{
+	drm_mode_config_init(drm);
+
+	drm->mode_config.min_width = 0;
+	drm->mode_config.min_height = 0;
+	drm->mode_config.max_width = 8192;
+	drm->mode_config.max_height = 8192;
+	drm->mode_config.allow_fb_modifiers = true;
+
+	drm->mode_config.funcs = &sprd_drm_mode_config_funcs;
+	drm->mode_config.helper_private = &sprd_drm_mode_config_helper;
+}
+
+static const struct file_operations sprd_drm_fops = {
+	.owner		= THIS_MODULE,
+	.open		= drm_open,
+	.release	= drm_release,
+	.unlocked_ioctl	= drm_ioctl,
+	.compat_ioctl	= drm_compat_ioctl,
+	.poll		= drm_poll,
+	.read		= drm_read,
+	.llseek		= no_llseek,
+	.mmap		= sprd_gem_mmap,
+};
+
+static struct drm_driver sprd_drm_drv = {
+	.driver_features	= DRIVER_GEM | DRIVER_ATOMIC,
+	.fops			= &sprd_drm_fops,
+	.gem_vm_ops		= &drm_gem_cma_vm_ops,
+	.gem_free_object_unlocked	= sprd_gem_free_object,
+	.dumb_create		= sprd_gem_dumb_create,
+	.prime_fd_to_handle	= drm_gem_prime_fd_to_handle,
+	.gem_prime_import	= drm_gem_prime_import,
+	.gem_prime_import_sg_table = sprd_gem_prime_import_sg_table,
+
+	.name			= DRIVER_NAME,
+	.desc			= DRIVER_DESC,
+	.date			= DRIVER_DATE,
+	.major			= DRIVER_MAJOR,
+	.minor			= DRIVER_MINOR,
+};
+
+static int sprd_drm_bind(struct device *dev)
+{
+	struct drm_device *drm;
+	struct sprd_drm *sprd;
+	int err;
+
+	drm = drm_dev_alloc(&sprd_drm_drv, dev);
+	if (IS_ERR(drm))
+		return PTR_ERR(drm);
+
+	dev_set_drvdata(dev, drm);
+
+	sprd = devm_kzalloc(drm->dev, sizeof(*sprd), GFP_KERNEL);
+	if (!sprd) {
+		err = -ENOMEM;
+		goto err_free_drm;
+	}
+	drm->dev_private = sprd;
+
+	sprd_drm_mode_config_init(drm);
+
+	/* bind and init sub drivers */
+	err = component_bind_all(drm->dev, drm);
+	if (err) {
+		DRM_ERROR("failed to bind all component.\n");
+		goto err_dc_cleanup;
+	}
+
+	/* vblank init */
+	err = drm_vblank_init(drm, drm->mode_config.num_crtc);
+	if (err) {
+		DRM_ERROR("failed to initialize vblank.\n");
+		goto err_unbind_all;
+	}
+	/* with irq_enabled = true, we can use the vblank feature. */
+	drm->irq_enabled = true;
+
+	/* reset all the states of crtc/plane/encoder/connector */
+	drm_mode_config_reset(drm);
+
+	/* init kms poll for handling hpd */
+	drm_kms_helper_poll_init(drm);
+
+	err = drm_dev_register(drm, 0);
+	if (err < 0)
+		goto err_kms_helper_poll_fini;
+
+	return 0;
+
+err_kms_helper_poll_fini:
+	drm_kms_helper_poll_fini(drm);
+err_unbind_all:
+	component_unbind_all(drm->dev, drm);
+err_dc_cleanup:
+	drm_mode_config_cleanup(drm);
+err_free_drm:
+	drm_dev_put(drm);
+	return err;
+}
+
+static void sprd_drm_unbind(struct device *dev)
+{
+	drm_put_dev(dev_get_drvdata(dev));
+}
+
+static const struct component_master_ops sprd_drm_component_ops = {
+	.bind = sprd_drm_bind,
+	.unbind = sprd_drm_unbind,
+};
+
+static int compare_of(struct device *dev, void *data)
+{
+	struct device_node *np = data;
+
+	DRM_DEBUG("compare %s\n", np->full_name);
+
+	return dev->of_node == np;
+}
+
+static int sprd_drm_component_probe(struct device *dev,
+			   const struct component_master_ops *m_ops)
+{
+	struct device_node *ep, *port, *remote;
+	struct component_match *match = NULL;
+	int i;
+
+	if (!dev->of_node)
+		return -EINVAL;
+
+	/*
+	 * Bind the crtc's ports first, so that drm_of_find_possible_crtcs()
+	 * called from encoder's .bind callbacks works as expected
+	 */
+	for (i = 0; ; i++) {
+		port = of_parse_phandle(dev->of_node, "ports", i);
+		if (!port)
+			break;
+
+		if (!of_device_is_available(port->parent)) {
+			of_node_put(port);
+			continue;
+		}
+
+		component_match_add(dev, &match, compare_of, port->parent);
+		of_node_put(port);
+	}
+
+	if (i == 0) {
+		dev_err(dev, "missing 'ports' property\n");
+		return -ENODEV;
+	}
+
+	if (!match) {
+		dev_err(dev, "no available port\n");
+		return -ENODEV;
+	}
+
+	/*
+	 * For bound crtcs, bind the encoders attached to their remote endpoint
+	 */
+	for (i = 0; ; i++) {
+		port = of_parse_phandle(dev->of_node, "ports", i);
+		if (!port)
+			break;
+
+		if (!of_device_is_available(port->parent)) {
+			of_node_put(port);
+			continue;
+		}
+
+		for_each_child_of_node(port, ep) {
+			remote = of_graph_get_remote_port_parent(ep);
+			if (!remote || !of_device_is_available(remote)) {
+				of_node_put(remote);
+				continue;
+			} else if (!of_device_is_available(remote->parent)) {
+				dev_warn(dev, "parent device of %s is not available\n",
+					 remote->full_name);
+				of_node_put(remote);
+				continue;
+			}
+
+			component_match_add(dev, &match, compare_of, remote);
+			of_node_put(remote);
+		}
+		of_node_put(port);
+	}
+
+	return component_master_add_with_match(dev, m_ops, match);
+}
+
+static int sprd_drm_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = dma_set_mask_and_coherent(&pdev->dev, ~0);
+	if (ret) {
+		DRM_ERROR("dma_set_mask_and_coherent failed (%d)\n", ret);
+		return ret;
+	}
+
+	return sprd_drm_component_probe(&pdev->dev, &sprd_drm_component_ops);
+}
+
+static int sprd_drm_remove(struct platform_device *pdev)
+{
+	component_master_del(&pdev->dev, &sprd_drm_component_ops);
+	return 0;
+}
+
+static void sprd_drm_shutdown(struct platform_device *pdev)
+{
+	struct drm_device *drm = platform_get_drvdata(pdev);
+
+	if (!drm) {
+		DRM_WARN("drm device is not available, no shutdown\n");
+		return;
+	}
+
+	drm_atomic_helper_shutdown(drm);
+}
+
+static const struct of_device_id sprd_drm_match_table[] = {
+	{ .compatible = "sprd,display-subsystem",},
+	{},
+};
+MODULE_DEVICE_TABLE(of, sprd_drm_match_table);
+
+static struct platform_driver sprd_drm_driver = {
+	.probe = sprd_drm_probe,
+	.remove = sprd_drm_remove,
+	.shutdown = sprd_drm_shutdown,
+	.driver = {
+		.name = "sprd-drm-drv",
+		.of_match_table = sprd_drm_match_table,
+	},
+};
+
+module_platform_driver(sprd_drm_driver);
+
+MODULE_AUTHOR("Leon He <[email protected]>");
+MODULE_AUTHOR("Kevin Tang <[email protected]>");
+MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver");
+MODULE_LICENSE("GPL v2");
drivers/gpu/drm/sprd/sprd_drm.h new file +16 -0
new file mode 100644
index 0000000..137cb27
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _SPRD_DRM_H_
+#define _SPRD_DRM_H_
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_print.h>
+
+struct sprd_drm {
+	struct drm_device *drm;
+};
+
+#endif /* _SPRD_DRM_H_ */
drivers/gpu/drm/sprd/sprd_gem.c new file +64 -0
new file mode 100644
index 0000000..9aec78e
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#include <linux/dma-buf.h>
+#include <linux/pm_runtime.h>
+
+#include <drm/drm_prime.h>
+
+#include "sprd_drm.h"
+#include "sprd_gem.h"
+
+static struct sprd_gem_obj *sprd_gem_obj_create(struct drm_device *drm,
+						unsigned long size)
+{
+	struct sprd_gem_obj *sprd_gem;
+	int ret;
+
+	sprd_gem = kzalloc(sizeof(*sprd_gem), GFP_KERNEL);
+	if (!sprd_gem)
+		return ERR_PTR(-ENOMEM);
+
+	ret = drm_gem_object_init(drm, &sprd_gem->base, size);
+	if (ret < 0) {
+		DRM_ERROR("failed to initialize gem object\n");
+		goto error;
+	}
+
+	ret = drm_gem_create_mmap_offset(&sprd_gem->base);
+	if (ret) {
+		drm_gem_object_release(&sprd_gem->base);
+		goto error;
+	}
+
+	return sprd_gem;
+
+error:
+	kfree(sprd_gem);
+	return ERR_PTR(ret);
+}
+
+void sprd_gem_free_object(struct drm_gem_object *obj)
+{
+	struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+
+	DRM_DEBUG("gem = %p\n", obj);
+
+	if (sprd_gem->vaddr)
+		dma_free_wc(obj->dev->dev, obj->size,
+			sprd_gem->vaddr, sprd_gem->dma_addr);
+	else if (sprd_gem->sgtb)
+		drm_prime_gem_destroy(obj, sprd_gem->sgtb);
+
+	drm_gem_object_release(obj);
+
+	kfree(sprd_gem);
+}
+
+int sprd_gem_dumb_create(struct drm_file *file_priv, struct drm_device *drm,
+			    struct drm_mode_create_dumb *args)
+{
+	struct sprd_gem_obj *sprd_gem;
+	int ret;

drivers/gpu/drm/sprd/sprd_gem.c line 74

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +10 -0
+
+	args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
+	args->size = round_up(args->pitch * args->height, PAGE_SIZE);
+
+	sprd_gem = sprd_gem_obj_create(drm, args->size);
+	if (IS_ERR(sprd_gem))
+		return PTR_ERR(sprd_gem);
+
+	sprd_gem->vaddr = dma_alloc_wc(drm->dev, args->size,
+			&sprd_gem->dma_addr, GFP_KERNEL | __GFP_NOWARN | GFP_DMA);

I might be missing something, but I still don't understand why all this GEM code is necessary. I quickly compared with the CMA helpers and the only meaningful difference is the use of the GFP_DMA flag.

Rather than duplicating the CMA code, it's better to change the CMA helpers to provide a way of setting this flag.

Best regards
Thomas

Quoted 141 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +104 -0
+	if (!sprd_gem->vaddr) {
+		DRM_ERROR("failed to allocate buffer with size %llu\n",
+			  args->size);
+		ret = -ENOMEM;
+		goto error;
+	}
+
+	ret = drm_gem_handle_create(file_priv, &sprd_gem->base, &args->handle);
+	if (ret)
+		goto error;
+
+	drm_gem_object_put_unlocked(&sprd_gem->base);
+
+	return 0;
+
+error:
+	sprd_gem_free_object(&sprd_gem->base);
+	return ret;
+}
+
+static int sprd_gem_object_mmap(struct drm_gem_object *obj,
+				   struct vm_area_struct *vma)
+
+{
+	int ret;
+	struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+
+	vma->vm_flags &= ~VM_PFNMAP;
+	vma->vm_pgoff = 0;
+
+	ret = dma_mmap_wc(obj->dev->dev, vma,
+				    sprd_gem->vaddr, sprd_gem->dma_addr,
+				    vma->vm_end - vma->vm_start);
+	if (ret)
+		drm_gem_vm_close(vma);
+
+	return ret;
+}
+
+int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+	struct drm_gem_object *obj;
+	int ret;
+
+	ret = drm_gem_mmap(filp, vma);
+	if (ret)
+		return ret;
+
+	obj = vma->vm_private_data;
+
+	return sprd_gem_object_mmap(obj, vma);
+}
+
+int sprd_gem_prime_mmap(struct drm_gem_object *obj,
+			    struct vm_area_struct *vma)
+{
+	int ret;
+
+	ret = drm_gem_mmap_obj(obj, obj->size, vma);
+	if (ret)
+		return ret;
+
+	return sprd_gem_object_mmap(obj, vma);
+}
+
+struct sg_table *sprd_gem_prime_get_sg_table(struct drm_gem_object *obj)
+{
+	struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+	struct sg_table *sgtb;
+	int ret;
+
+	sgtb = kzalloc(sizeof(*sgtb), GFP_KERNEL);
+	if (!sgtb)
+		return ERR_PTR(-ENOMEM);
+
+	ret = dma_get_sgtable(obj->dev->dev, sgtb, sprd_gem->vaddr,
+			      sprd_gem->dma_addr, obj->size);
+	if (ret) {
+		DRM_ERROR("failed to allocate sg_table, %d\n", ret);
+		kfree(sgtb);
+		return ERR_PTR(ret);
+	}
+
+	return sgtb;
+}
+
+struct drm_gem_object *sprd_gem_prime_import_sg_table(struct drm_device *drm,
+		struct dma_buf_attachment *attach, struct sg_table *sgtb)
+{
+	struct sprd_gem_obj *sprd_gem;
+
+	sprd_gem = sprd_gem_obj_create(drm, attach->dmabuf->size);
+	if (IS_ERR(sprd_gem))
+		return ERR_CAST(sprd_gem);
+
+	DRM_DEBUG("gem = %p\n", &sprd_gem->base);
+
+	if (sgtb->nents == 1)
+		sprd_gem->dma_addr = sg_dma_address(sgtb->sgl);
+
+	sprd_gem->sgtb = sgtb;
+
+	return &sprd_gem->base;
+}
drivers/gpu/drm/sprd/sprd_gem.h new file +30 -0
new file mode 100644
index 0000000..b6740bd
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _SPRD_GEM_H_
+#define _SPRD_GEM_H_
+
+#include <drm/drm_gem.h>
+
+struct sprd_gem_obj {
+	struct drm_gem_object	base;
+	dma_addr_t		dma_addr;
+	struct sg_table		*sgtb;
+	void			*vaddr;
+};
+
+#define to_sprd_gem_obj(x)	container_of(x, struct sprd_gem_obj, base)
+
+void sprd_gem_free_object(struct drm_gem_object *gem);
+int sprd_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
+			    struct drm_mode_create_dumb *args);
+int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma);
+int sprd_gem_prime_mmap(struct drm_gem_object *obj,
+			 struct vm_area_struct *vma);
+struct sg_table *sprd_gem_prime_get_sg_table(struct drm_gem_object *obj);
+struct drm_gem_object *sprd_gem_prime_import_sg_table(struct drm_device *dev,
+		struct dma_buf_attachment *attach, struct sg_table *sgtb);
+
+#endif
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

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

#4 lore raw

Re: [PATCH RFC v1 2/6] drm/sprd: add Unisoc's drm kms master

Hi

Am 06.01.20 um 11:11 schrieb Thomas Zimmermann:

Quoted 488 lines

Hi Kevin

Am 16.12.19 um 12:40 schrieb Kevin Tang:

Quoted 470 lines

From: Kevin Tang <[email protected]>

Adds drm support for the Unisoc's display subsystem.

This is drm device and gem driver. This driver provides support for the Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 drivers/gpu/drm/Kconfig         |   2 +
 drivers/gpu/drm/Makefile        |   1 +
 drivers/gpu/drm/sprd/Kconfig    |  14 ++
 drivers/gpu/drm/sprd/Makefile   |   8 ++
 drivers/gpu/drm/sprd/sprd_drm.c | 286 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
 drivers/gpu/drm/sprd/sprd_gem.c | 178 +++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_gem.h |  30 +++++
 8 files changed, 535 insertions(+)
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.h
drivers/gpu/drm/Kconfig +2 -0
index bfdadc3..cead12c 100644
@@ -387,6 +387,8 @@ source "drivers/gpu/drm/aspeed/Kconfig"
 
 source "drivers/gpu/drm/mcde/Kconfig"
 
+source "drivers/gpu/drm/sprd/Kconfig"
+
 # Keep legacy drivers last
 
 menuconfig DRM_LEGACY
drivers/gpu/drm/Makefile +1 -0
index 9f1c7c4..85ca211 100644
@@ -122,3 +122,4 @@ obj-$(CONFIG_DRM_LIMA)  += lima/
 obj-$(CONFIG_DRM_PANFROST) += panfrost/
 obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/
 obj-$(CONFIG_DRM_MCDE) += mcde/
+obj-$(CONFIG_DRM_SPRD) += sprd/
drivers/gpu/drm/sprd/Kconfig new file +14 -0
new file mode 100644
index 0000000..79f286b
@@ -0,0 +1,14 @@
+config DRM_SPRD
+	tristate "DRM Support for Unisoc SoCs Platform"
+	depends on ARCH_SPRD
+	depends on DRM && OF
+	select DRM_KMS_HELPER
+	select DRM_GEM_CMA_HELPER
+	select DRM_KMS_CMA_HELPER
+	select DRM_MIPI_DSI
+	select DRM_PANEL
+	select VIDEOMODE_HELPERS
+	select BACKLIGHT_CLASS_DEVICE
+	help
+	  Choose this option if you have a Unisoc chipsets.
+	  If M is selected the module will be called sprd-drm.
\ No newline at end of file
drivers/gpu/drm/sprd/Makefile new file +8 -0
new file mode 100644
index 0000000..df0b316
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ccflags-y += -Iinclude/drm
+
+subdir-ccflags-y += -I$(src)
+
+obj-y := sprd_drm.o \
+	sprd_gem.o
\ No newline at end of file
drivers/gpu/drm/sprd/sprd_drm.c new file +286 -0
new file mode 100644
index 0000000..4aee25fa4
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#include <linux/component.h>
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of_graph.h>
+#include <linux/of_platform.h>
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_gem_cma_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+
+#include "sprd_drm.h"
+#include "sprd_gem.h"
+
+#define DRIVER_NAME	"sprd"
+#define DRIVER_DESC	"Spreadtrum SoCs' DRM Driver"
+#define DRIVER_DATE	"20191101"
+#define DRIVER_MAJOR	1
+#define DRIVER_MINOR	0
+
+static const struct drm_mode_config_helper_funcs sprd_drm_mode_config_helper = {
+	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
+};
+
+static const struct drm_mode_config_funcs sprd_drm_mode_config_funcs = {
+	.fb_create = drm_gem_fb_create,
+	.atomic_check = drm_atomic_helper_check,
+	.atomic_commit = drm_atomic_helper_commit,
+};
+
+static void sprd_drm_mode_config_init(struct drm_device *drm)
+{
+	drm_mode_config_init(drm);
+
+	drm->mode_config.min_width = 0;
+	drm->mode_config.min_height = 0;
+	drm->mode_config.max_width = 8192;
+	drm->mode_config.max_height = 8192;
+	drm->mode_config.allow_fb_modifiers = true;
+
+	drm->mode_config.funcs = &sprd_drm_mode_config_funcs;
+	drm->mode_config.helper_private = &sprd_drm_mode_config_helper;
+}
+
+static const struct file_operations sprd_drm_fops = {
+	.owner		= THIS_MODULE,
+	.open		= drm_open,
+	.release	= drm_release,
+	.unlocked_ioctl	= drm_ioctl,
+	.compat_ioctl	= drm_compat_ioctl,
+	.poll		= drm_poll,
+	.read		= drm_read,
+	.llseek		= no_llseek,
+	.mmap		= sprd_gem_mmap,
+};
+
+static struct drm_driver sprd_drm_drv = {
+	.driver_features	= DRIVER_GEM | DRIVER_ATOMIC,
+	.fops			= &sprd_drm_fops,
+	.gem_vm_ops		= &drm_gem_cma_vm_ops,
+	.gem_free_object_unlocked	= sprd_gem_free_object,
+	.dumb_create		= sprd_gem_dumb_create,
+	.prime_fd_to_handle	= drm_gem_prime_fd_to_handle,
+	.gem_prime_import	= drm_gem_prime_import,
+	.gem_prime_import_sg_table = sprd_gem_prime_import_sg_table,
+
+	.name			= DRIVER_NAME,
+	.desc			= DRIVER_DESC,
+	.date			= DRIVER_DATE,
+	.major			= DRIVER_MAJOR,
+	.minor			= DRIVER_MINOR,
+};
+
+static int sprd_drm_bind(struct device *dev)
+{
+	struct drm_device *drm;
+	struct sprd_drm *sprd;
+	int err;
+
+	drm = drm_dev_alloc(&sprd_drm_drv, dev);
+	if (IS_ERR(drm))
+		return PTR_ERR(drm);
+
+	dev_set_drvdata(dev, drm);
+
+	sprd = devm_kzalloc(drm->dev, sizeof(*sprd), GFP_KERNEL);
+	if (!sprd) {
+		err = -ENOMEM;
+		goto err_free_drm;
+	}
+	drm->dev_private = sprd;
+
+	sprd_drm_mode_config_init(drm);
+
+	/* bind and init sub drivers */
+	err = component_bind_all(drm->dev, drm);
+	if (err) {
+		DRM_ERROR("failed to bind all component.\n");
+		goto err_dc_cleanup;
+	}
+
+	/* vblank init */
+	err = drm_vblank_init(drm, drm->mode_config.num_crtc);
+	if (err) {
+		DRM_ERROR("failed to initialize vblank.\n");
+		goto err_unbind_all;
+	}
+	/* with irq_enabled = true, we can use the vblank feature. */
+	drm->irq_enabled = true;
+
+	/* reset all the states of crtc/plane/encoder/connector */
+	drm_mode_config_reset(drm);
+
+	/* init kms poll for handling hpd */
+	drm_kms_helper_poll_init(drm);
+
+	err = drm_dev_register(drm, 0);
+	if (err < 0)
+		goto err_kms_helper_poll_fini;
+
+	return 0;
+
+err_kms_helper_poll_fini:
+	drm_kms_helper_poll_fini(drm);
+err_unbind_all:
+	component_unbind_all(drm->dev, drm);
+err_dc_cleanup:
+	drm_mode_config_cleanup(drm);
+err_free_drm:
+	drm_dev_put(drm);
+	return err;
+}
+
+static void sprd_drm_unbind(struct device *dev)
+{
+	drm_put_dev(dev_get_drvdata(dev));
+}
+
+static const struct component_master_ops sprd_drm_component_ops = {
+	.bind = sprd_drm_bind,
+	.unbind = sprd_drm_unbind,
+};
+
+static int compare_of(struct device *dev, void *data)
+{
+	struct device_node *np = data;
+
+	DRM_DEBUG("compare %s\n", np->full_name);
+
+	return dev->of_node == np;
+}
+
+static int sprd_drm_component_probe(struct device *dev,
+			   const struct component_master_ops *m_ops)
+{
+	struct device_node *ep, *port, *remote;
+	struct component_match *match = NULL;
+	int i;
+
+	if (!dev->of_node)
+		return -EINVAL;
+
+	/*
+	 * Bind the crtc's ports first, so that drm_of_find_possible_crtcs()
+	 * called from encoder's .bind callbacks works as expected
+	 */
+	for (i = 0; ; i++) {
+		port = of_parse_phandle(dev->of_node, "ports", i);
+		if (!port)
+			break;
+
+		if (!of_device_is_available(port->parent)) {
+			of_node_put(port);
+			continue;
+		}
+
+		component_match_add(dev, &match, compare_of, port->parent);
+		of_node_put(port);
+	}
+
+	if (i == 0) {
+		dev_err(dev, "missing 'ports' property\n");
+		return -ENODEV;
+	}
+
+	if (!match) {
+		dev_err(dev, "no available port\n");
+		return -ENODEV;
+	}
+
+	/*
+	 * For bound crtcs, bind the encoders attached to their remote endpoint
+	 */
+	for (i = 0; ; i++) {
+		port = of_parse_phandle(dev->of_node, "ports", i);
+		if (!port)
+			break;
+
+		if (!of_device_is_available(port->parent)) {
+			of_node_put(port);
+			continue;
+		}
+
+		for_each_child_of_node(port, ep) {
+			remote = of_graph_get_remote_port_parent(ep);
+			if (!remote || !of_device_is_available(remote)) {
+				of_node_put(remote);
+				continue;
+			} else if (!of_device_is_available(remote->parent)) {
+				dev_warn(dev, "parent device of %s is not available\n",
+					 remote->full_name);
+				of_node_put(remote);
+				continue;
+			}
+
+			component_match_add(dev, &match, compare_of, remote);
+			of_node_put(remote);
+		}
+		of_node_put(port);
+	}
+
+	return component_master_add_with_match(dev, m_ops, match);
+}
+
+static int sprd_drm_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = dma_set_mask_and_coherent(&pdev->dev, ~0);
+	if (ret) {
+		DRM_ERROR("dma_set_mask_and_coherent failed (%d)\n", ret);
+		return ret;
+	}
+
+	return sprd_drm_component_probe(&pdev->dev, &sprd_drm_component_ops);
+}
+
+static int sprd_drm_remove(struct platform_device *pdev)
+{
+	component_master_del(&pdev->dev, &sprd_drm_component_ops);
+	return 0;
+}
+
+static void sprd_drm_shutdown(struct platform_device *pdev)
+{
+	struct drm_device *drm = platform_get_drvdata(pdev);
+
+	if (!drm) {
+		DRM_WARN("drm device is not available, no shutdown\n");
+		return;
+	}
+
+	drm_atomic_helper_shutdown(drm);
+}
+
+static const struct of_device_id sprd_drm_match_table[] = {
+	{ .compatible = "sprd,display-subsystem",},
+	{},
+};
+MODULE_DEVICE_TABLE(of, sprd_drm_match_table);
+
+static struct platform_driver sprd_drm_driver = {
+	.probe = sprd_drm_probe,
+	.remove = sprd_drm_remove,
+	.shutdown = sprd_drm_shutdown,
+	.driver = {
+		.name = "sprd-drm-drv",
+		.of_match_table = sprd_drm_match_table,
+	},
+};
+
+module_platform_driver(sprd_drm_driver);
+
+MODULE_AUTHOR("Leon He <[email protected]>");
+MODULE_AUTHOR("Kevin Tang <[email protected]>");
+MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver");
+MODULE_LICENSE("GPL v2");
drivers/gpu/drm/sprd/sprd_drm.h new file +16 -0
new file mode 100644
index 0000000..137cb27
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _SPRD_DRM_H_
+#define _SPRD_DRM_H_
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_print.h>
+
+struct sprd_drm {
+	struct drm_device *drm;
+};
+
+#endif /* _SPRD_DRM_H_ */
drivers/gpu/drm/sprd/sprd_gem.c new file +64 -0
new file mode 100644
index 0000000..9aec78e
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#include <linux/dma-buf.h>
+#include <linux/pm_runtime.h>
+
+#include <drm/drm_prime.h>
+
+#include "sprd_drm.h"
+#include "sprd_gem.h"
+
+static struct sprd_gem_obj *sprd_gem_obj_create(struct drm_device *drm,
+						unsigned long size)
+{
+	struct sprd_gem_obj *sprd_gem;
+	int ret;
+
+	sprd_gem = kzalloc(sizeof(*sprd_gem), GFP_KERNEL);
+	if (!sprd_gem)
+		return ERR_PTR(-ENOMEM);
+
+	ret = drm_gem_object_init(drm, &sprd_gem->base, size);
+	if (ret < 0) {
+		DRM_ERROR("failed to initialize gem object\n");
+		goto error;
+	}
+
+	ret = drm_gem_create_mmap_offset(&sprd_gem->base);
+	if (ret) {
+		drm_gem_object_release(&sprd_gem->base);
+		goto error;
+	}
+
+	return sprd_gem;
+
+error:
+	kfree(sprd_gem);
+	return ERR_PTR(ret);
+}
+
+void sprd_gem_free_object(struct drm_gem_object *obj)
+{
+	struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+
+	DRM_DEBUG("gem = %p\n", obj);
+
+	if (sprd_gem->vaddr)
+		dma_free_wc(obj->dev->dev, obj->size,
+			sprd_gem->vaddr, sprd_gem->dma_addr);
+	else if (sprd_gem->sgtb)
+		drm_prime_gem_destroy(obj, sprd_gem->sgtb);
+
+	drm_gem_object_release(obj);
+
+	kfree(sprd_gem);
+}
+
+int sprd_gem_dumb_create(struct drm_file *file_priv, struct drm_device *drm,
+			    struct drm_mode_create_dumb *args)
+{
+	struct sprd_gem_obj *sprd_gem;
+	int ret;

drivers/gpu/drm/sprd/sprd_gem.c line 74

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +10 -0
+
+	args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
+	args->size = round_up(args->pitch * args->height, PAGE_SIZE);
+
+	sprd_gem = sprd_gem_obj_create(drm, args->size);
+	if (IS_ERR(sprd_gem))
+		return PTR_ERR(sprd_gem);
+
+	sprd_gem->vaddr = dma_alloc_wc(drm->dev, args->size,
+			&sprd_gem->dma_addr, GFP_KERNEL | __GFP_NOWARN | GFP_DMA);

I might be missing something, but I still don't understand why all this GEM code is necessary. I quickly compared with the CMA helpers and the only meaningful difference is the use of the GFP_DMA flag.

Quoted 2 lines

Rather than duplicating the CMA code, it's better to change the CMA helpers to provide a way of setting this flag.

Further looking at the implementation of dma_alloc_wc(), the GFP_DMA flags get cleared unconditionally. [1]

Best regards
Thomas

[1] https://elixir.bootlin.com/linux/latest/source/kernel/dma/mapping.c#L295

Quoted 152 lines

Best regards
Thomas

Quoted 131 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +104 -0
+	if (!sprd_gem->vaddr) {
+		DRM_ERROR("failed to allocate buffer with size %llu\n",
+			  args->size);
+		ret = -ENOMEM;
+		goto error;
+	}
+
+	ret = drm_gem_handle_create(file_priv, &sprd_gem->base, &args->handle);
+	if (ret)
+		goto error;
+
+	drm_gem_object_put_unlocked(&sprd_gem->base);
+
+	return 0;
+
+error:
+	sprd_gem_free_object(&sprd_gem->base);
+	return ret;
+}
+
+static int sprd_gem_object_mmap(struct drm_gem_object *obj,
+				   struct vm_area_struct *vma)
+
+{
+	int ret;
+	struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+
+	vma->vm_flags &= ~VM_PFNMAP;
+	vma->vm_pgoff = 0;
+
+	ret = dma_mmap_wc(obj->dev->dev, vma,
+				    sprd_gem->vaddr, sprd_gem->dma_addr,
+				    vma->vm_end - vma->vm_start);
+	if (ret)
+		drm_gem_vm_close(vma);
+
+	return ret;
+}
+
+int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+	struct drm_gem_object *obj;
+	int ret;
+
+	ret = drm_gem_mmap(filp, vma);
+	if (ret)
+		return ret;
+
+	obj = vma->vm_private_data;
+
+	return sprd_gem_object_mmap(obj, vma);
+}
+
+int sprd_gem_prime_mmap(struct drm_gem_object *obj,
+			    struct vm_area_struct *vma)
+{
+	int ret;
+
+	ret = drm_gem_mmap_obj(obj, obj->size, vma);
+	if (ret)
+		return ret;
+
+	return sprd_gem_object_mmap(obj, vma);
+}
+
+struct sg_table *sprd_gem_prime_get_sg_table(struct drm_gem_object *obj)
+{
+	struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+	struct sg_table *sgtb;
+	int ret;
+
+	sgtb = kzalloc(sizeof(*sgtb), GFP_KERNEL);
+	if (!sgtb)
+		return ERR_PTR(-ENOMEM);
+
+	ret = dma_get_sgtable(obj->dev->dev, sgtb, sprd_gem->vaddr,
+			      sprd_gem->dma_addr, obj->size);
+	if (ret) {
+		DRM_ERROR("failed to allocate sg_table, %d\n", ret);
+		kfree(sgtb);
+		return ERR_PTR(ret);
+	}
+
+	return sgtb;
+}
+
+struct drm_gem_object *sprd_gem_prime_import_sg_table(struct drm_device *drm,
+		struct dma_buf_attachment *attach, struct sg_table *sgtb)
+{
+	struct sprd_gem_obj *sprd_gem;
+
+	sprd_gem = sprd_gem_obj_create(drm, attach->dmabuf->size);
+	if (IS_ERR(sprd_gem))
+		return ERR_CAST(sprd_gem);
+
+	DRM_DEBUG("gem = %p\n", &sprd_gem->base);
+
+	if (sgtb->nents == 1)
+		sprd_gem->dma_addr = sg_dma_address(sgtb->sgl);
+
+	sprd_gem->sgtb = sgtb;
+
+	return &sprd_gem->base;
+}
drivers/gpu/drm/sprd/sprd_gem.h new file +20 -0
new file mode 100644
index 0000000..b6740bd
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _SPRD_GEM_H_
+#define _SPRD_GEM_H_
+
+#include <drm/drm_gem.h>
+
+struct sprd_gem_obj {
+	struct drm_gem_object	base;
+	dma_addr_t		dma_addr;
+	struct sg_table		*sgtb;
+	void			*vaddr;
+};
+
+#define to_sprd_gem_obj(x)	container_of(x, struct sprd_gem_obj, base)
+
+void sprd_gem_free_object(struct drm_gem_object *gem);

drivers/gpu/drm/sprd/sprd_gem.h line 30

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_gem.h new file +10 -0
+int sprd_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
+			    struct drm_mode_create_dumb *args);
+int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma);
+int sprd_gem_prime_mmap(struct drm_gem_object *obj,
+			 struct vm_area_struct *vma);
+struct sg_table *sprd_gem_prime_get_sg_table(struct drm_gem_object *obj);
+struct drm_gem_object *sprd_gem_prime_import_sg_table(struct drm_device *dev,
+		struct dma_buf_attachment *attach, struct sg_table *sgtb);
+
+#endif

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

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

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

#5 lore raw

Re: [PATCH RFC v1 2/6] drm/sprd: add Unisoc's drm kms master

In reply to Thomas Zimmermann

Hi Thomas,
Our soc needs to support both cma and iommu, but our iommu is not ready for upload, so i remove it from sprd_gem.c
So can i upload the cma code first? and add iommu support later

Quoted 651 lines · Thomas Zimmermann

Hi Kevin

Am 16.12.19 um 12:40 schrieb Kevin Tang:

Quoted 11 lines

From: Kevin Tang <[email protected]>

Adds drm support for the Unisoc's display subsystem.

This is drm device and gem driver. This driver provides support for the Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
Quoted 6 lines
---
 drivers/gpu/drm/Kconfig         |   2 +
 drivers/gpu/drm/Makefile        |   1 +
 drivers/gpu/drm/sprd/Kconfig    |  14 ++
 drivers/gpu/drm/sprd/Makefile   |   8 ++
 drivers/gpu/drm/sprd/sprd_drm.c | 286

++++++++++++++++++++++++++++++++++++++++

Review

Quoted 55 lines
 drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
 drivers/gpu/drm/sprd/sprd_gem.c | 178 +++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_gem.h |  30 +++++
 8 files changed, 535 insertions(+)
 create mode 100644 drivers/gpu/drm/sprd/Kconfig
 create mode 100644 drivers/gpu/drm/sprd/Makefile
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_gem.h
drivers/gpu/drm/Kconfig +2 -0
index bfdadc3..cead12c 100644
@@ -387,6 +387,8 @@ source "drivers/gpu/drm/aspeed/Kconfig"
 
 source "drivers/gpu/drm/mcde/Kconfig"
 
+source "drivers/gpu/drm/sprd/Kconfig"
+
 # Keep legacy drivers last
 
 menuconfig DRM_LEGACY
drivers/gpu/drm/Makefile +1 -0
index 9f1c7c4..85ca211 100644
@@ -122,3 +122,4 @@ obj-$(CONFIG_DRM_LIMA)  += lima/
 obj-$(CONFIG_DRM_PANFROST) += panfrost/
 obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/
 obj-$(CONFIG_DRM_MCDE) += mcde/
+obj-$(CONFIG_DRM_SPRD) += sprd/
drivers/gpu/drm/sprd/Kconfig new file +14 -0
new file mode 100644
index 0000000..79f286b
@@ -0,0 +1,14 @@
+config DRM_SPRD
+     tristate "DRM Support for Unisoc SoCs Platform"
+     depends on ARCH_SPRD
+     depends on DRM && OF
+     select DRM_KMS_HELPER
+     select DRM_GEM_CMA_HELPER
+     select DRM_KMS_CMA_HELPER
+     select DRM_MIPI_DSI
+     select DRM_PANEL
+     select VIDEOMODE_HELPERS
+     select BACKLIGHT_CLASS_DEVICE
+     help
+       Choose this option if you have a Unisoc chipsets.
+       If M is selected the module will be called sprd-drm.
\ No newline at end of file
(quoted diff) +0 -0

b/drivers/gpu/drm/sprd/Makefile

Review

Quoted 15 lines

new file mode 100644
index 0000000..df0b316

drivers/gpu/drm/sprd/Makefile new file +8 -0
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ccflags-y += -Iinclude/drm
+
+subdir-ccflags-y += -I$(src)
+
+obj-y := sprd_drm.o \
+     sprd_gem.o
\ No newline at end of file
(quoted diff) +0 -0

b/drivers/gpu/drm/sprd/sprd_drm.c

Quoted 25 lines

new file mode 100644
index 0000000..4aee25fa4

drivers/gpu/drm/sprd/sprd_drm.c new file +20 -0
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#include <linux/component.h>
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of_graph.h>
+#include <linux/of_platform.h>
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_gem_cma_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+

drivers/gpu/drm/sprd/sprd_drm.c line 30

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +10 -0
+#include "sprd_drm.h"
+#include "sprd_gem.h"
+
+#define DRIVER_NAME  "sprd"
+#define DRIVER_DESC  "Spreadtrum SoCs' DRM Driver"
+#define DRIVER_DATE  "20191101"
+#define DRIVER_MAJOR 1
+#define DRIVER_MINOR 0
+
+static const struct drm_mode_config_helper_funcs

sprd_drm_mode_config_helper = {

Quoted 133 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +133 -0
+     .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
+};
+
+static const struct drm_mode_config_funcs sprd_drm_mode_config_funcs = {
+     .fb_create = drm_gem_fb_create,
+     .atomic_check = drm_atomic_helper_check,
+     .atomic_commit = drm_atomic_helper_commit,
+};
+
+static void sprd_drm_mode_config_init(struct drm_device *drm)
+{
+     drm_mode_config_init(drm);
+
+     drm->mode_config.min_width = 0;
+     drm->mode_config.min_height = 0;
+     drm->mode_config.max_width = 8192;
+     drm->mode_config.max_height = 8192;
+     drm->mode_config.allow_fb_modifiers = true;
+
+     drm->mode_config.funcs = &sprd_drm_mode_config_funcs;
+     drm->mode_config.helper_private = &sprd_drm_mode_config_helper;
+}
+
+static const struct file_operations sprd_drm_fops = {
+     .owner          = THIS_MODULE,
+     .open           = drm_open,
+     .release        = drm_release,
+     .unlocked_ioctl = drm_ioctl,
+     .compat_ioctl   = drm_compat_ioctl,
+     .poll           = drm_poll,
+     .read           = drm_read,
+     .llseek         = no_llseek,
+     .mmap           = sprd_gem_mmap,
+};
+
+static struct drm_driver sprd_drm_drv = {
+     .driver_features        = DRIVER_GEM | DRIVER_ATOMIC,
+     .fops                   = &sprd_drm_fops,
+     .gem_vm_ops             = &drm_gem_cma_vm_ops,
+     .gem_free_object_unlocked       = sprd_gem_free_object,
+     .dumb_create            = sprd_gem_dumb_create,
+     .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
+     .gem_prime_import       = drm_gem_prime_import,
+     .gem_prime_import_sg_table = sprd_gem_prime_import_sg_table,
+
+     .name                   = DRIVER_NAME,
+     .desc                   = DRIVER_DESC,
+     .date                   = DRIVER_DATE,
+     .major                  = DRIVER_MAJOR,
+     .minor                  = DRIVER_MINOR,
+};
+
+static int sprd_drm_bind(struct device *dev)
+{
+     struct drm_device *drm;
+     struct sprd_drm *sprd;
+     int err;
+
+     drm = drm_dev_alloc(&sprd_drm_drv, dev);
+     if (IS_ERR(drm))
+             return PTR_ERR(drm);
+
+     dev_set_drvdata(dev, drm);
+
+     sprd = devm_kzalloc(drm->dev, sizeof(*sprd), GFP_KERNEL);
+     if (!sprd) {
+             err = -ENOMEM;
+             goto err_free_drm;
+     }
+     drm->dev_private = sprd;
+
+     sprd_drm_mode_config_init(drm);
+
+     /* bind and init sub drivers */
+     err = component_bind_all(drm->dev, drm);
+     if (err) {
+             DRM_ERROR("failed to bind all component.\n");
+             goto err_dc_cleanup;
+     }
+
+     /* vblank init */
+     err = drm_vblank_init(drm, drm->mode_config.num_crtc);
+     if (err) {
+             DRM_ERROR("failed to initialize vblank.\n");
+             goto err_unbind_all;
+     }
+     /* with irq_enabled = true, we can use the vblank feature. */
+     drm->irq_enabled = true;
+
+     /* reset all the states of crtc/plane/encoder/connector */
+     drm_mode_config_reset(drm);
+
+     /* init kms poll for handling hpd */
+     drm_kms_helper_poll_init(drm);
+
+     err = drm_dev_register(drm, 0);
+     if (err < 0)
+             goto err_kms_helper_poll_fini;
+
+     return 0;
+
+err_kms_helper_poll_fini:
+     drm_kms_helper_poll_fini(drm);
+err_unbind_all:
+     component_unbind_all(drm->dev, drm);
+err_dc_cleanup:
+     drm_mode_config_cleanup(drm);
+err_free_drm:
+     drm_dev_put(drm);
+     return err;
+}
+
+static void sprd_drm_unbind(struct device *dev)
+{
+     drm_put_dev(dev_get_drvdata(dev));
+}
+
+static const struct component_master_ops sprd_drm_component_ops = {
+     .bind = sprd_drm_bind,
+     .unbind = sprd_drm_unbind,
+};
+
+static int compare_of(struct device *dev, void *data)
+{
+     struct device_node *np = data;
+
+     DRM_DEBUG("compare %s\n", np->full_name);
+
+     return dev->of_node == np;
+}
+
+static int sprd_drm_component_probe(struct device *dev,
+                        const struct component_master_ops *m_ops)

drivers/gpu/drm/sprd/sprd_drm.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +10 -0
+{
+     struct device_node *ep, *port, *remote;
+     struct component_match *match = NULL;
+     int i;
+
+     if (!dev->of_node)
+             return -EINVAL;
+
+     /*
+      * Bind the crtc's ports first, so that

drm_of_find_possible_crtcs()

Quoted 18 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +18 -0
+      * called from encoder's .bind callbacks works as expected
+      */
+     for (i = 0; ; i++) {
+             port = of_parse_phandle(dev->of_node, "ports", i);
+             if (!port)
+                     break;
+
+             if (!of_device_is_available(port->parent)) {
+                     of_node_put(port);
+                     continue;
+             }
+
+             component_match_add(dev, &match, compare_of, port->parent);
+             of_node_put(port);
+     }
+
+     if (i == 0) {
+             dev_err(dev, "missing 'ports' property\n");

drivers/gpu/drm/sprd/sprd_drm.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +10 -0
+             return -ENODEV;
+     }
+
+     if (!match) {
+             dev_err(dev, "no available port\n");
+             return -ENODEV;
+     }
+
+     /*
+      * For bound crtcs, bind the encoders attached to their remote

endpoint

Quoted 7 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +7 -0
+      */
+     for (i = 0; ; i++) {
+             port = of_parse_phandle(dev->of_node, "ports", i);
+             if (!port)
+                     break;
+
+             if (!of_device_is_available(port->parent)) {

drivers/gpu/drm/sprd/sprd_drm.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +10 -0
+                     of_node_put(port);
+                     continue;
+             }
+
+             for_each_child_of_node(port, ep) {
+                     remote = of_graph_get_remote_port_parent(ep);
+                     if (!remote || !of_device_is_available(remote)) {
+                             of_node_put(remote);
+                             continue;
+                     } else if

(!of_device_is_available(remote->parent)) {

drivers/gpu/drm/sprd/sprd_drm.c line 219

Quoted 1 line
drivers/gpu/drm/sprd/sprd_drm.c new file +1 -0
+                             dev_warn(dev, "parent device of %s is not

available\n",

drivers/gpu/drm/sprd/sprd_drm.c

Quoted 6 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +6 -0
+                                      remote->full_name);
+                             of_node_put(remote);
+                             continue;
+                     }
+
+                     component_match_add(dev, &match, compare_of,

remote);

Quoted 9 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +9 -0
+                     of_node_put(remote);
+             }
+             of_node_put(port);
+     }
+
+     return component_master_add_with_match(dev, m_ops, match);
+}
+
+static int sprd_drm_probe(struct platform_device *pdev)

drivers/gpu/drm/sprd/sprd_drm.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +10 -0
+{
+     int ret;
+
+     ret = dma_set_mask_and_coherent(&pdev->dev, ~0);
+     if (ret) {
+             DRM_ERROR("dma_set_mask_and_coherent failed (%d)\n", ret);
+             return ret;
+     }
+
+     return sprd_drm_component_probe(&pdev->dev,

&sprd_drm_component_ops);

Review

Quoted 43 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +42 -0
+}
+
+static int sprd_drm_remove(struct platform_device *pdev)
+{
+     component_master_del(&pdev->dev, &sprd_drm_component_ops);
+     return 0;
+}
+
+static void sprd_drm_shutdown(struct platform_device *pdev)
+{
+     struct drm_device *drm = platform_get_drvdata(pdev);
+
+     if (!drm) {
+             DRM_WARN("drm device is not available, no shutdown\n");
+             return;
+     }
+
+     drm_atomic_helper_shutdown(drm);
+}
+
+static const struct of_device_id sprd_drm_match_table[] = {
+     { .compatible = "sprd,display-subsystem",},
+     {},
+};
+MODULE_DEVICE_TABLE(of, sprd_drm_match_table);
+
+static struct platform_driver sprd_drm_driver = {
+     .probe = sprd_drm_probe,
+     .remove = sprd_drm_remove,
+     .shutdown = sprd_drm_shutdown,
+     .driver = {
+             .name = "sprd-drm-drv",
+             .of_match_table = sprd_drm_match_table,
+     },
+};
+
+module_platform_driver(sprd_drm_driver);
+
+MODULE_AUTHOR("Leon He <[email protected]>");
+MODULE_AUTHOR("Kevin Tang <[email protected]>");
+MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver");
+MODULE_LICENSE("GPL v2");
(quoted diff) +0 -0

b/drivers/gpu/drm/sprd/sprd_drm.h

Review

Quoted 22 lines

new file mode 100644
index 0000000..137cb27

drivers/gpu/drm/sprd/sprd_drm.h new file +16 -0
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _SPRD_DRM_H_
+#define _SPRD_DRM_H_
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_print.h>
+
+struct sprd_drm {
+     struct drm_device *drm;
+};
+
+#endif /* _SPRD_DRM_H_ */
(quoted diff) +0 -0

b/drivers/gpu/drm/sprd/sprd_gem.c

Quoted 55 lines

new file mode 100644
index 0000000..9aec78e

drivers/gpu/drm/sprd/sprd_gem.c new file +50 -0
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#include <linux/dma-buf.h>
+#include <linux/pm_runtime.h>
+
+#include <drm/drm_prime.h>
+
+#include "sprd_drm.h"
+#include "sprd_gem.h"
+
+static struct sprd_gem_obj *sprd_gem_obj_create(struct drm_device *drm,
+                                             unsigned long size)
+{
+     struct sprd_gem_obj *sprd_gem;
+     int ret;
+
+     sprd_gem = kzalloc(sizeof(*sprd_gem), GFP_KERNEL);
+     if (!sprd_gem)
+             return ERR_PTR(-ENOMEM);
+
+     ret = drm_gem_object_init(drm, &sprd_gem->base, size);
+     if (ret < 0) {
+             DRM_ERROR("failed to initialize gem object\n");
+             goto error;
+     }
+
+     ret = drm_gem_create_mmap_offset(&sprd_gem->base);
+     if (ret) {
+             drm_gem_object_release(&sprd_gem->base);
+             goto error;
+     }
+
+     return sprd_gem;
+
+error:
+     kfree(sprd_gem);
+     return ERR_PTR(ret);
+}
+
+void sprd_gem_free_object(struct drm_gem_object *obj)
+{
+     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+
+     DRM_DEBUG("gem = %p\n", obj);
+
+     if (sprd_gem->vaddr)
+             dma_free_wc(obj->dev->dev, obj->size,

drivers/gpu/drm/sprd/sprd_gem.c line 60

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +10 -0
+                     sprd_gem->vaddr, sprd_gem->dma_addr);
+     else if (sprd_gem->sgtb)
+             drm_prime_gem_destroy(obj, sprd_gem->sgtb);
+
+     drm_gem_object_release(obj);
+
+     kfree(sprd_gem);
+}
+
+int sprd_gem_dumb_create(struct drm_file *file_priv, struct drm_device

*drm,

Quoted 4 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +4 -0
+                         struct drm_mode_create_dumb *args)
+{
+     struct sprd_gem_obj *sprd_gem;
+     int ret;

drivers/gpu/drm/sprd/sprd_gem.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +10 -0
+
+     args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
+     args->size = round_up(args->pitch * args->height, PAGE_SIZE);
+
+     sprd_gem = sprd_gem_obj_create(drm, args->size);
+     if (IS_ERR(sprd_gem))
+             return PTR_ERR(sprd_gem);
+
+     sprd_gem->vaddr = dma_alloc_wc(drm->dev, args->size,
+                     &sprd_gem->dma_addr, GFP_KERNEL | __GFP_NOWARN |

GFP_DMA);

I might be missing something, but I still don't understand why all this GEM code is necessary. I quickly compared with the CMA helpers and the only meaningful difference is the use of the GFP_DMA flag.

Rather than duplicating the CMA code, it's better to change the CMA helpers to provide a way of setting this flag.

Best regards
Thomas

drivers/gpu/drm/sprd/sprd_gem.c

Quoted 8 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +8 -0
+     if (!sprd_gem->vaddr) {
+             DRM_ERROR("failed to allocate buffer with size %llu\n",
+                       args->size);
+             ret = -ENOMEM;
+             goto error;
+     }
+
+     ret = drm_gem_handle_create(file_priv, &sprd_gem->base,

&args->handle);

Quoted 69 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +69 -0
+     if (ret)
+             goto error;
+
+     drm_gem_object_put_unlocked(&sprd_gem->base);
+
+     return 0;
+
+error:
+     sprd_gem_free_object(&sprd_gem->base);
+     return ret;
+}
+
+static int sprd_gem_object_mmap(struct drm_gem_object *obj,
+                                struct vm_area_struct *vma)
+
+{
+     int ret;
+     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+
+     vma->vm_flags &= ~VM_PFNMAP;
+     vma->vm_pgoff = 0;
+
+     ret = dma_mmap_wc(obj->dev->dev, vma,
+                                 sprd_gem->vaddr, sprd_gem->dma_addr,
+                                 vma->vm_end - vma->vm_start);
+     if (ret)
+             drm_gem_vm_close(vma);
+
+     return ret;
+}
+
+int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+     struct drm_gem_object *obj;
+     int ret;
+
+     ret = drm_gem_mmap(filp, vma);
+     if (ret)
+             return ret;
+
+     obj = vma->vm_private_data;
+
+     return sprd_gem_object_mmap(obj, vma);
+}
+
+int sprd_gem_prime_mmap(struct drm_gem_object *obj,
+                         struct vm_area_struct *vma)
+{
+     int ret;
+
+     ret = drm_gem_mmap_obj(obj, obj->size, vma);
+     if (ret)
+             return ret;
+
+     return sprd_gem_object_mmap(obj, vma);
+}
+
+struct sg_table *sprd_gem_prime_get_sg_table(struct drm_gem_object *obj)
+{
+     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
+     struct sg_table *sgtb;
+     int ret;
+
+     sgtb = kzalloc(sizeof(*sgtb), GFP_KERNEL);
+     if (!sgtb)
+             return ERR_PTR(-ENOMEM);
+
+     ret = dma_get_sgtable(obj->dev->dev, sgtb, sprd_gem->vaddr,
+                           sprd_gem->dma_addr, obj->size);

drivers/gpu/drm/sprd/sprd_gem.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +10 -0
+     if (ret) {
+             DRM_ERROR("failed to allocate sg_table, %d\n", ret);
+             kfree(sgtb);
+             return ERR_PTR(ret);
+     }
+
+     return sgtb;
+}
+
+struct drm_gem_object *sprd_gem_prime_import_sg_table(struct drm_device

*drm,

Review

Quoted 18 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +17 -0
+             struct dma_buf_attachment *attach, struct sg_table *sgtb)
+{
+     struct sprd_gem_obj *sprd_gem;
+
+     sprd_gem = sprd_gem_obj_create(drm, attach->dmabuf->size);
+     if (IS_ERR(sprd_gem))
+             return ERR_CAST(sprd_gem);
+
+     DRM_DEBUG("gem = %p\n", &sprd_gem->base);
+
+     if (sgtb->nents == 1)
+             sprd_gem->dma_addr = sg_dma_address(sgtb->sgl);
+
+     sprd_gem->sgtb = sgtb;
+
+     return &sprd_gem->base;
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/sprd/sprd_gem.h

Quoted 16 lines

new file mode 100644
index 0000000..b6740bd

drivers/gpu/drm/sprd/sprd_gem.h new file +11 -0
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _SPRD_GEM_H_
+#define _SPRD_GEM_H_
+
+#include <drm/drm_gem.h>
+
+struct sprd_gem_obj {

drivers/gpu/drm/sprd/sprd_gem.h line 21

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_gem.h new file +10 -0
+     struct drm_gem_object   base;
+     dma_addr_t              dma_addr;
+     struct sg_table         *sgtb;
+     void                    *vaddr;
+};
+
+#define to_sprd_gem_obj(x)   container_of(x, struct sprd_gem_obj, base)
+
+void sprd_gem_free_object(struct drm_gem_object *gem);
+int sprd_gem_dumb_create(struct drm_file *file_priv, struct drm_device

*dev,

drivers/gpu/drm/sprd/sprd_gem.h

Quoted 5 lines
drivers/gpu/drm/sprd/sprd_gem.h new file +5 -0
+                         struct drm_mode_create_dumb *args);
+int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma);
+int sprd_gem_prime_mmap(struct drm_gem_object *obj,
+                      struct vm_area_struct *vma);
+struct sg_table *sprd_gem_prime_get_sg_table(struct drm_gem_object

*obj);

drivers/gpu/drm/sprd/sprd_gem.h line 27

Quoted 1 line
drivers/gpu/drm/sprd/sprd_gem.h new file +1 -0
+struct drm_gem_object *sprd_gem_prime_import_sg_table(struct drm_device

*dev,

Quoted 14 lines

drivers/gpu/drm/sprd/sprd_gem.h line 30

Quoted 4 lines
drivers/gpu/drm/sprd/sprd_gem.h new file +3 -0
+             struct dma_buf_attachment *attach, struct sg_table *sgtb);
+
+#endif

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

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

#6 lore raw

Re: [PATCH RFC v1 2/6] drm/sprd: add Unisoc's drm kms master

Hi

Am 07.01.20 um 12:36 schrieb tang pengchuan:

Quoted 4 lines

Hi Thomas,
Our soc needs to support both cma and iommu, but our iommu is not ready for upload, so i remove it from sprd_gem.c
So can i upload the cma code first? and add iommu support later

This might be possible, but I cannot make the decision. I'd suggest a different strategy.

1) Convert to generic CMA handlers and submit. You'd want the least
amount of code in your patches, so they go in quickly and easily.

2) Duplicate CMA handlers into your driver and add IOMMU support.
Submit this patchset at a later point when it's ready.

Just an untested idea: Is it a generic IOMMU or a GART? With a generic IOMMU it could be possible to implement dma_map_ops for your platform. CMA helpers will use the IOMMU in their call to dma_alloc_wc(). [1] If this works, you would not have to maintain you own GEM code and can merge IOMMU support at any time.

Best regards
Thomas

[1] https://elixir.bootlin.com/linux/latest/source/kernel/dma/mapping.c#L298

Quoted 684 lines

On Mon, Jan 6, 2020 at 6:11 PM Thomas Zimmermann <[email protected] <mailto:[email protected]>> wrote:

    Hi Kevin

    Am 16.12.19 um 12:40 schrieb Kevin Tang:
    > From: Kevin Tang <[email protected]
    <mailto:[email protected]>>
    >
    > Adds drm support for the Unisoc's display subsystem.
    >
    > This is drm device and gem driver. This driver provides support
    for the
    > Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
    >
    > Cc: Orson Zhai <[email protected] <mailto:[email protected]>>
    > Cc: Baolin Wang <[email protected]
    <mailto:[email protected]>>
    > Cc: Chunyan Zhang <[email protected] <mailto:[email protected]>>
    > Signed-off-by: Kevin Tang <[email protected]
    <mailto:[email protected]>>
    > ---
    >  drivers/gpu/drm/Kconfig         |   2 +
    >  drivers/gpu/drm/Makefile        |   1 +
    >  drivers/gpu/drm/sprd/Kconfig    |  14 ++
    >  drivers/gpu/drm/sprd/Makefile   |   8 ++
    >  drivers/gpu/drm/sprd/sprd_drm.c | 286
    ++++++++++++++++++++++++++++++++++++++++
    >  drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
    >  drivers/gpu/drm/sprd/sprd_gem.c | 178 +++++++++++++++++++++++++
    >  drivers/gpu/drm/sprd/sprd_gem.h |  30 +++++
    >  8 files changed, 535 insertions(+)
    >  create mode 100644 drivers/gpu/drm/sprd/Kconfig
    >  create mode 100644 drivers/gpu/drm/sprd/Makefile
    >  create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
    >  create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
    >  create mode 100644 drivers/gpu/drm/sprd/sprd_gem.c
    >  create mode 100644 drivers/gpu/drm/sprd/sprd_gem.h
    >
    > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
    > index bfdadc3..cead12c 100644
    > --- a/drivers/gpu/drm/Kconfig
    > +++ b/drivers/gpu/drm/Kconfig
    > @@ -387,6 +387,8 @@ source "drivers/gpu/drm/aspeed/Kconfig"
    > 
    >  source "drivers/gpu/drm/mcde/Kconfig"
    > 
    > +source "drivers/gpu/drm/sprd/Kconfig"
    > +
    >  # Keep legacy drivers last
    > 
    >  menuconfig DRM_LEGACY
    > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
    > index 9f1c7c4..85ca211 100644
    > --- a/drivers/gpu/drm/Makefile
    > +++ b/drivers/gpu/drm/Makefile
    > @@ -122,3 +122,4 @@ obj-$(CONFIG_DRM_LIMA)  += lima/
    >  obj-$(CONFIG_DRM_PANFROST) += panfrost/
    >  obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/
    >  obj-$(CONFIG_DRM_MCDE) += mcde/
    > +obj-$(CONFIG_DRM_SPRD) += sprd/
    > diff --git a/drivers/gpu/drm/sprd/Kconfig
    b/drivers/gpu/drm/sprd/Kconfig
    > new file mode 100644
    > index 0000000..79f286b
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/Kconfig
    > @@ -0,0 +1,14 @@
    > +config DRM_SPRD
    > +     tristate "DRM Support for Unisoc SoCs Platform"
    > +     depends on ARCH_SPRD
    > +     depends on DRM && OF
    > +     select DRM_KMS_HELPER
    > +     select DRM_GEM_CMA_HELPER
    > +     select DRM_KMS_CMA_HELPER
    > +     select DRM_MIPI_DSI
    > +     select DRM_PANEL
    > +     select VIDEOMODE_HELPERS
    > +     select BACKLIGHT_CLASS_DEVICE
    > +     help
    > +       Choose this option if you have a Unisoc chipsets.
    > +       If M is selected the module will be called sprd-drm.
    > \ No newline at end of file
    > diff --git a/drivers/gpu/drm/sprd/Makefile
    b/drivers/gpu/drm/sprd/Makefile
    > new file mode 100644
    > index 0000000..df0b316
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/Makefile
    > @@ -0,0 +1,8 @@
    > +# SPDX-License-Identifier: GPL-2.0
    > +
    > +ccflags-y += -Iinclude/drm
    > +
    > +subdir-ccflags-y += -I$(src)
    > +
    > +obj-y := sprd_drm.o \
    > +     sprd_gem.o
    > \ No newline at end of file
    > diff --git a/drivers/gpu/drm/sprd/sprd_drm.c
    b/drivers/gpu/drm/sprd/sprd_drm.c
    > new file mode 100644
    > index 0000000..4aee25fa4
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/sprd_drm.c
    > @@ -0,0 +1,286 @@
    > +// SPDX-License-Identifier: GPL-2.0
    > +/*
    > + * Copyright (C) 2019 Unisoc Inc.
    > + */
    > +
    > +#include <linux/component.h>
    > +#include <linux/dma-mapping.h>
    > +#include <linux/module.h>
    > +#include <linux/mutex.h>
    > +#include <linux/of_graph.h>
    > +#include <linux/of_platform.h>
    > +
    > +#include <drm/drm_atomic_helper.h>
    > +#include <drm/drm_crtc_helper.h>
    > +#include <drm/drm_drv.h>
    > +#include <drm/drm_gem_cma_helper.h>
    > +#include <drm/drm_gem_framebuffer_helper.h>
    > +#include <drm/drm_probe_helper.h>
    > +#include <drm/drm_vblank.h>
    > +
    > +#include "sprd_drm.h"
    > +#include "sprd_gem.h"
    > +
    > +#define DRIVER_NAME  "sprd"
    > +#define DRIVER_DESC  "Spreadtrum SoCs' DRM Driver"
    > +#define DRIVER_DATE  "20191101"
    > +#define DRIVER_MAJOR 1
    > +#define DRIVER_MINOR 0
    > +
    > +static const struct drm_mode_config_helper_funcs
    sprd_drm_mode_config_helper = {
    > +     .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
    > +};
    > +
    > +static const struct drm_mode_config_funcs
    sprd_drm_mode_config_funcs = {
    > +     .fb_create = drm_gem_fb_create,
    > +     .atomic_check = drm_atomic_helper_check,
    > +     .atomic_commit = drm_atomic_helper_commit,
    > +};
    > +
    > +static void sprd_drm_mode_config_init(struct drm_device *drm)
    > +{
    > +     drm_mode_config_init(drm);
    > +
    > +     drm->mode_config.min_width = 0;
    > +     drm->mode_config.min_height = 0;
    > +     drm->mode_config.max_width = 8192;
    > +     drm->mode_config.max_height = 8192;
    > +     drm->mode_config.allow_fb_modifiers = true;
    > +
    > +     drm->mode_config.funcs = &sprd_drm_mode_config_funcs;
    > +     drm->mode_config.helper_private = &sprd_drm_mode_config_helper;
    > +}
    > +
    > +static const struct file_operations sprd_drm_fops = {
    > +     .owner          = THIS_MODULE,
    > +     .open           = drm_open,
    > +     .release        = drm_release,
    > +     .unlocked_ioctl = drm_ioctl,
    > +     .compat_ioctl   = drm_compat_ioctl,
    > +     .poll           = drm_poll,
    > +     .read           = drm_read,
    > +     .llseek         = no_llseek,
    > +     .mmap           = sprd_gem_mmap,
    > +};
    > +
    > +static struct drm_driver sprd_drm_drv = {
    > +     .driver_features        = DRIVER_GEM | DRIVER_ATOMIC,
    > +     .fops                   = &sprd_drm_fops,
    > +     .gem_vm_ops             = &drm_gem_cma_vm_ops,
    > +     .gem_free_object_unlocked       = sprd_gem_free_object,
    > +     .dumb_create            = sprd_gem_dumb_create,
    > +     .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
    > +     .gem_prime_import       = drm_gem_prime_import,
    > +     .gem_prime_import_sg_table = sprd_gem_prime_import_sg_table,
    > +
    > +     .name                   = DRIVER_NAME,
    > +     .desc                   = DRIVER_DESC,
    > +     .date                   = DRIVER_DATE,
    > +     .major                  = DRIVER_MAJOR,
    > +     .minor                  = DRIVER_MINOR,
    > +};
    > +
    > +static int sprd_drm_bind(struct device *dev)
    > +{
    > +     struct drm_device *drm;
    > +     struct sprd_drm *sprd;
    > +     int err;
    > +
    > +     drm = drm_dev_alloc(&sprd_drm_drv, dev);
    > +     if (IS_ERR(drm))
    > +             return PTR_ERR(drm);
    > +
    > +     dev_set_drvdata(dev, drm);
    > +
    > +     sprd = devm_kzalloc(drm->dev, sizeof(*sprd), GFP_KERNEL);
    > +     if (!sprd) {
    > +             err = -ENOMEM;
    > +             goto err_free_drm;
    > +     }
    > +     drm->dev_private = sprd;
    > +
    > +     sprd_drm_mode_config_init(drm);
    > +
    > +     /* bind and init sub drivers */
    > +     err = component_bind_all(drm->dev, drm);
    > +     if (err) {
    > +             DRM_ERROR("failed to bind all component.\n");
    > +             goto err_dc_cleanup;
    > +     }
    > +
    > +     /* vblank init */
    > +     err = drm_vblank_init(drm, drm->mode_config.num_crtc);
    > +     if (err) {
    > +             DRM_ERROR("failed to initialize vblank.\n");
    > +             goto err_unbind_all;
    > +     }
    > +     /* with irq_enabled = true, we can use the vblank feature. */
    > +     drm->irq_enabled = true;
    > +
    > +     /* reset all the states of crtc/plane/encoder/connector */
    > +     drm_mode_config_reset(drm);
    > +
    > +     /* init kms poll for handling hpd */
    > +     drm_kms_helper_poll_init(drm);
    > +
    > +     err = drm_dev_register(drm, 0);
    > +     if (err < 0)
    > +             goto err_kms_helper_poll_fini;
    > +
    > +     return 0;
    > +
    > +err_kms_helper_poll_fini:
    > +     drm_kms_helper_poll_fini(drm);
    > +err_unbind_all:
    > +     component_unbind_all(drm->dev, drm);
    > +err_dc_cleanup:
    > +     drm_mode_config_cleanup(drm);
    > +err_free_drm:
    > +     drm_dev_put(drm);
    > +     return err;
    > +}
    > +
    > +static void sprd_drm_unbind(struct device *dev)
    > +{
    > +     drm_put_dev(dev_get_drvdata(dev));
    > +}
    > +
    > +static const struct component_master_ops sprd_drm_component_ops = {
    > +     .bind = sprd_drm_bind,
    > +     .unbind = sprd_drm_unbind,
    > +};
    > +
    > +static int compare_of(struct device *dev, void *data)
    > +{
    > +     struct device_node *np = data;
    > +
    > +     DRM_DEBUG("compare %s\n", np->full_name);
    > +
    > +     return dev->of_node == np;
    > +}
    > +
    > +static int sprd_drm_component_probe(struct device *dev,
    > +                        const struct component_master_ops *m_ops)
    > +{
    > +     struct device_node *ep, *port, *remote;
    > +     struct component_match *match = NULL;
    > +     int i;
    > +
    > +     if (!dev->of_node)
    > +             return -EINVAL;
    > +
    > +     /*
    > +      * Bind the crtc's ports first, so that
    drm_of_find_possible_crtcs()
    > +      * called from encoder's .bind callbacks works as expected
    > +      */
    > +     for (i = 0; ; i++) {
    > +             port = of_parse_phandle(dev->of_node, "ports", i);
    > +             if (!port)
    > +                     break;
    > +
    > +             if (!of_device_is_available(port->parent)) {
    > +                     of_node_put(port);
    > +                     continue;
    > +             }
    > +
    > +             component_match_add(dev, &match, compare_of,
    port->parent);
    > +             of_node_put(port);
    > +     }
    > +
    > +     if (i == 0) {
    > +             dev_err(dev, "missing 'ports' property\n");
    > +             return -ENODEV;
    > +     }
    > +
    > +     if (!match) {
    > +             dev_err(dev, "no available port\n");
    > +             return -ENODEV;
    > +     }
    > +
    > +     /*
    > +      * For bound crtcs, bind the encoders attached to their
    remote endpoint
    > +      */
    > +     for (i = 0; ; i++) {
    > +             port = of_parse_phandle(dev->of_node, "ports", i);
    > +             if (!port)
    > +                     break;
    > +
    > +             if (!of_device_is_available(port->parent)) {
    > +                     of_node_put(port);
    > +                     continue;
    > +             }
    > +
    > +             for_each_child_of_node(port, ep) {
    > +                     remote = of_graph_get_remote_port_parent(ep);
    > +                     if (!remote ||
    !of_device_is_available(remote)) {
    > +                             of_node_put(remote);
    > +                             continue;
    > +                     } else if
    (!of_device_is_available(remote->parent)) {
    > +                             dev_warn(dev, "parent device of %s
    is not available\n",
    > +                                      remote->full_name);
    > +                             of_node_put(remote);
    > +                             continue;
    > +                     }
    > +
    > +                     component_match_add(dev, &match, compare_of,
    remote);
    > +                     of_node_put(remote);
    > +             }
    > +             of_node_put(port);
    > +     }
    > +
    > +     return component_master_add_with_match(dev, m_ops, match);
    > +}
    > +
    > +static int sprd_drm_probe(struct platform_device *pdev)
    > +{
    > +     int ret;
    > +
    > +     ret = dma_set_mask_and_coherent(&pdev->dev, ~0);
    > +     if (ret) {
    > +             DRM_ERROR("dma_set_mask_and_coherent failed (%d)\n",
    ret);
    > +             return ret;
    > +     }
    > +
    > +     return sprd_drm_component_probe(&pdev->dev,
    &sprd_drm_component_ops);
    > +}
    > +
    > +static int sprd_drm_remove(struct platform_device *pdev)
    > +{
    > +     component_master_del(&pdev->dev, &sprd_drm_component_ops);
    > +     return 0;
    > +}
    > +
    > +static void sprd_drm_shutdown(struct platform_device *pdev)
    > +{
    > +     struct drm_device *drm = platform_get_drvdata(pdev);
    > +
    > +     if (!drm) {
    > +             DRM_WARN("drm device is not available, no shutdown\n");
    > +             return;
    > +     }
    > +
    > +     drm_atomic_helper_shutdown(drm);
    > +}
    > +
    > +static const struct of_device_id sprd_drm_match_table[] = {
    > +     { .compatible = "sprd,display-subsystem",},
    > +     {},
    > +};
    > +MODULE_DEVICE_TABLE(of, sprd_drm_match_table);
    > +
    > +static struct platform_driver sprd_drm_driver = {
    > +     .probe = sprd_drm_probe,
    > +     .remove = sprd_drm_remove,
    > +     .shutdown = sprd_drm_shutdown,
    > +     .driver = {
    > +             .name = "sprd-drm-drv",
    > +             .of_match_table = sprd_drm_match_table,
    > +     },
    > +};
    > +
    > +module_platform_driver(sprd_drm_driver);
    > +
    > +MODULE_AUTHOR("Leon He <[email protected]
    <mailto:[email protected]>>");
    > +MODULE_AUTHOR("Kevin Tang <[email protected]
    <mailto:[email protected]>>");
    > +MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver");
    > +MODULE_LICENSE("GPL v2");
    > diff --git a/drivers/gpu/drm/sprd/sprd_drm.h
    b/drivers/gpu/drm/sprd/sprd_drm.h
    > new file mode 100644
    > index 0000000..137cb27
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/sprd_drm.h
    > @@ -0,0 +1,16 @@
    > +/* SPDX-License-Identifier: GPL-2.0 */
    > +/*
    > + * Copyright (C) 2019 Unisoc Inc.
    > + */
    > +
    > +#ifndef _SPRD_DRM_H_
    > +#define _SPRD_DRM_H_
    > +
    > +#include <drm/drm_atomic.h>
    > +#include <drm/drm_print.h>
    > +
    > +struct sprd_drm {
    > +     struct drm_device *drm;
    > +};
    > +
    > +#endif /* _SPRD_DRM_H_ */
    > diff --git a/drivers/gpu/drm/sprd/sprd_gem.c
    b/drivers/gpu/drm/sprd/sprd_gem.c
    > new file mode 100644
    > index 0000000..9aec78e
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/sprd_gem.c
    > @@ -0,0 +1,178 @@
    > +// SPDX-License-Identifier: GPL-2.0
    > +/*
    > + * Copyright (C) 2019 Unisoc Inc.
    > + */
    > +
    > +#include <linux/dma-buf.h>
    > +#include <linux/pm_runtime.h>
    > +
    > +#include <drm/drm_prime.h>
    > +
    > +#include "sprd_drm.h"
    > +#include "sprd_gem.h"
    > +
    > +static struct sprd_gem_obj *sprd_gem_obj_create(struct drm_device
    *drm,
    > +                                             unsigned long size)
    > +{
    > +     struct sprd_gem_obj *sprd_gem;
    > +     int ret;
    > +
    > +     sprd_gem = kzalloc(sizeof(*sprd_gem), GFP_KERNEL);
    > +     if (!sprd_gem)
    > +             return ERR_PTR(-ENOMEM);
    > +
    > +     ret = drm_gem_object_init(drm, &sprd_gem->base, size);
    > +     if (ret < 0) {
    > +             DRM_ERROR("failed to initialize gem object\n");
    > +             goto error;
    > +     }
    > +
    > +     ret = drm_gem_create_mmap_offset(&sprd_gem->base);
    > +     if (ret) {
    > +             drm_gem_object_release(&sprd_gem->base);
    > +             goto error;
    > +     }
    > +
    > +     return sprd_gem;
    > +
    > +error:
    > +     kfree(sprd_gem);
    > +     return ERR_PTR(ret);
    > +}
    > +
    > +void sprd_gem_free_object(struct drm_gem_object *obj)
    > +{
    > +     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
    > +
    > +     DRM_DEBUG("gem = %p\n", obj);
    > +
    > +     if (sprd_gem->vaddr)
    > +             dma_free_wc(obj->dev->dev, obj->size,
    > +                     sprd_gem->vaddr, sprd_gem->dma_addr);
    > +     else if (sprd_gem->sgtb)
    > +             drm_prime_gem_destroy(obj, sprd_gem->sgtb);
    > +
    > +     drm_gem_object_release(obj);
    > +
    > +     kfree(sprd_gem);
    > +}
    > +
    > +int sprd_gem_dumb_create(struct drm_file *file_priv, struct
    drm_device *drm,
    > +                         struct drm_mode_create_dumb *args)
    > +{
    > +     struct sprd_gem_obj *sprd_gem;
    > +     int ret;
    > +
    > +     args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
    > +     args->size = round_up(args->pitch * args->height, PAGE_SIZE);
    > +
    > +     sprd_gem = sprd_gem_obj_create(drm, args->size);
    > +     if (IS_ERR(sprd_gem))
    > +             return PTR_ERR(sprd_gem);
    > +
    > +     sprd_gem->vaddr = dma_alloc_wc(drm->dev, args->size,
    > +                     &sprd_gem->dma_addr, GFP_KERNEL |
    __GFP_NOWARN | GFP_DMA);

    I might be missing something, but I still don't understand why all this
    GEM code is necessary. I quickly compared with the CMA helpers and the
    only meaningful difference is the use of the GFP_DMA flag.

    Rather than duplicating the CMA code, it's better to change the CMA
    helpers to provide a way of setting this flag.

    Best regards
    Thomas

    > +     if (!sprd_gem->vaddr) {
    > +             DRM_ERROR("failed to allocate buffer with size %llu\n",
    > +                       args->size);
    > +             ret = -ENOMEM;
    > +             goto error;
    > +     }
    > +
    > +     ret = drm_gem_handle_create(file_priv, &sprd_gem->base,
    &args->handle);
    > +     if (ret)
    > +             goto error;
    > +
    > +     drm_gem_object_put_unlocked(&sprd_gem->base);
    > +
    > +     return 0;
    > +
    > +error:
    > +     sprd_gem_free_object(&sprd_gem->base);
    > +     return ret;
    > +}
    > +
    > +static int sprd_gem_object_mmap(struct drm_gem_object *obj,
    > +                                struct vm_area_struct *vma)
    > +
    > +{
    > +     int ret;
    > +     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
    > +
    > +     vma->vm_flags &= ~VM_PFNMAP;
    > +     vma->vm_pgoff = 0;
    > +
    > +     ret = dma_mmap_wc(obj->dev->dev, vma,
    > +                                 sprd_gem->vaddr, sprd_gem->dma_addr,
    > +                                 vma->vm_end - vma->vm_start);
    > +     if (ret)
    > +             drm_gem_vm_close(vma);
    > +
    > +     return ret;
    > +}
    > +
    > +int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma)
    > +{
    > +     struct drm_gem_object *obj;
    > +     int ret;
    > +
    > +     ret = drm_gem_mmap(filp, vma);
    > +     if (ret)
    > +             return ret;
    > +
    > +     obj = vma->vm_private_data;
    > +
    > +     return sprd_gem_object_mmap(obj, vma);
    > +}
    > +
    > +int sprd_gem_prime_mmap(struct drm_gem_object *obj,
    > +                         struct vm_area_struct *vma)
    > +{
    > +     int ret;
    > +
    > +     ret = drm_gem_mmap_obj(obj, obj->size, vma);
    > +     if (ret)
    > +             return ret;
    > +
    > +     return sprd_gem_object_mmap(obj, vma);
    > +}
    > +
    > +struct sg_table *sprd_gem_prime_get_sg_table(struct
    drm_gem_object *obj)
    > +{
    > +     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
    > +     struct sg_table *sgtb;
    > +     int ret;
    > +
    > +     sgtb = kzalloc(sizeof(*sgtb), GFP_KERNEL);
    > +     if (!sgtb)
    > +             return ERR_PTR(-ENOMEM);
    > +
    > +     ret = dma_get_sgtable(obj->dev->dev, sgtb, sprd_gem->vaddr,
    > +                           sprd_gem->dma_addr, obj->size);
    > +     if (ret) {
    > +             DRM_ERROR("failed to allocate sg_table, %d\n", ret);
    > +             kfree(sgtb);
    > +             return ERR_PTR(ret);
    > +     }
    > +
    > +     return sgtb;
    > +}
    > +
    > +struct drm_gem_object *sprd_gem_prime_import_sg_table(struct
    drm_device *drm,
    > +             struct dma_buf_attachment *attach, struct sg_table
    *sgtb)
    > +{
    > +     struct sprd_gem_obj *sprd_gem;
    > +
    > +     sprd_gem = sprd_gem_obj_create(drm, attach->dmabuf->size);
    > +     if (IS_ERR(sprd_gem))
    > +             return ERR_CAST(sprd_gem);
    > +
    > +     DRM_DEBUG("gem = %p\n", &sprd_gem->base);
    > +
    > +     if (sgtb->nents == 1)
    > +             sprd_gem->dma_addr = sg_dma_address(sgtb->sgl);
    > +
    > +     sprd_gem->sgtb = sgtb;
    > +
    > +     return &sprd_gem->base;
    > +}
    > diff --git a/drivers/gpu/drm/sprd/sprd_gem.h
    b/drivers/gpu/drm/sprd/sprd_gem.h
    > new file mode 100644
    > index 0000000..b6740bd
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/sprd_gem.h
    > @@ -0,0 +1,30 @@
    > +/* SPDX-License-Identifier: GPL-2.0 */
    > +/*
    > + * Copyright (C) 2019 Unisoc Inc.
    > + */
    > +
    > +#ifndef _SPRD_GEM_H_
    > +#define _SPRD_GEM_H_
    > +
    > +#include <drm/drm_gem.h>
    > +
    > +struct sprd_gem_obj {
    > +     struct drm_gem_object   base;
    > +     dma_addr_t              dma_addr;
    > +     struct sg_table         *sgtb;
    > +     void                    *vaddr;
    > +};
    > +
    > +#define to_sprd_gem_obj(x)   container_of(x, struct sprd_gem_obj,
    base)
    > +
    > +void sprd_gem_free_object(struct drm_gem_object *gem);
    > +int sprd_gem_dumb_create(struct drm_file *file_priv, struct
    drm_device *dev,
    > +                         struct drm_mode_create_dumb *args);
    > +int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma);
    > +int sprd_gem_prime_mmap(struct drm_gem_object *obj,
    > +                      struct vm_area_struct *vma);
    > +struct sg_table *sprd_gem_prime_get_sg_table(struct
    drm_gem_object *obj);
    > +struct drm_gem_object *sprd_gem_prime_import_sg_table(struct
    drm_device *dev,
    > +             struct dma_buf_attachment *attach, struct sg_table
    *sgtb);
    > +
    > +#endif
    >

    -- 
    Thomas Zimmermann
    Graphics Driver Developer
    SUSE Software Solutions Germany GmbH
    Maxfeldstr. 5, 90409 Nürnberg, Germany
    (HRB 36809, AG Nürnberg)
    Geschäftsführer: Felix Imendörffer
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

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

#7 lore raw

Re: [PATCH RFC v1 2/6] drm/sprd: add Unisoc's drm kms master

1) Convert to generic CMA handlers and submit. You'd want the least amount of code in your patches, so they go in quickly and easily. Ok, I will follow this suggestion, thank you very much!

Quoted 723 lines · Thomas Zimmermann

Hi

Am 07.01.20 um 12:36 schrieb tang pengchuan:

Quoted 4 lines

Hi Thomas,
Our soc needs to support both cma and iommu, but our iommu is not ready for upload, so i remove it from sprd_gem.c
So can i upload the cma code first? and add iommu support later

This might be possible, but I cannot make the decision. I'd suggest a different strategy.

1) Convert to generic CMA handlers and submit. You'd want the least
amount of code in your patches, so they go in quickly and easily.

2) Duplicate CMA handlers into your driver and add IOMMU support.
Submit this patchset at a later point when it's ready.

Just an untested idea: Is it a generic IOMMU or a GART? With a generic IOMMU it could be possible to implement dma_map_ops for your platform. CMA helpers will use the IOMMU in their call to dma_alloc_wc(). [1] If this works, you would not have to maintain you own GEM code and can merge IOMMU support at any time.

Best regards
Thomas

[1]
https://elixir.bootlin.com/linux/latest/source/kernel/dma/mapping.c#L298

Quoted 12 lines

On Mon, Jan 6, 2020 at 6:11 PM Thomas Zimmermann <[email protected] <mailto:[email protected]>> wrote:

Hi Kevin

Am 16.12.19 um 12:40 schrieb Kevin Tang:
> From: Kevin Tang <[email protected] <mailto:[email protected]>>
>
> Adds drm support for the Unisoc's display subsystem. >

Quoted 8 lines

> This is drm device and gem driver. This driver provides support for the
> Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. >
> Cc: Orson Zhai <[email protected] <mailto:[email protected]>> > Cc: Baolin Wang <[email protected] <mailto:[email protected]>>
> Cc: Chunyan Zhang <[email protected] <mailto:

[email protected]>>

Quoted 132 lines
Quoted 1 line
    <mailto:[email protected]>>
    > ---
    >  drivers/gpu/drm/Kconfig         |   2 +
    >  drivers/gpu/drm/Makefile        |   1 +
    >  drivers/gpu/drm/sprd/Kconfig    |  14 ++
    >  drivers/gpu/drm/sprd/Makefile   |   8 ++
    >  drivers/gpu/drm/sprd/sprd_drm.c | 286
    ++++++++++++++++++++++++++++++++++++++++
    >  drivers/gpu/drm/sprd/sprd_drm.h |  16 +++
    >  drivers/gpu/drm/sprd/sprd_gem.c | 178 +++++++++++++++++++++++++
    >  drivers/gpu/drm/sprd/sprd_gem.h |  30 +++++
    >  8 files changed, 535 insertions(+)
    >  create mode 100644 drivers/gpu/drm/sprd/Kconfig
    >  create mode 100644 drivers/gpu/drm/sprd/Makefile
    >  create mode 100644 drivers/gpu/drm/sprd/sprd_drm.c
    >  create mode 100644 drivers/gpu/drm/sprd/sprd_drm.h
    >  create mode 100644 drivers/gpu/drm/sprd/sprd_gem.c
    >  create mode 100644 drivers/gpu/drm/sprd/sprd_gem.h
    >
    > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
    > index bfdadc3..cead12c 100644
    > --- a/drivers/gpu/drm/Kconfig
    > +++ b/drivers/gpu/drm/Kconfig
    > @@ -387,6 +387,8 @@ source "drivers/gpu/drm/aspeed/Kconfig"
    >
    >  source "drivers/gpu/drm/mcde/Kconfig"
    >
    > +source "drivers/gpu/drm/sprd/Kconfig"
    > +
    >  # Keep legacy drivers last
    >
    >  menuconfig DRM_LEGACY
    > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
    > index 9f1c7c4..85ca211 100644
    > --- a/drivers/gpu/drm/Makefile
    > +++ b/drivers/gpu/drm/Makefile
    > @@ -122,3 +122,4 @@ obj-$(CONFIG_DRM_LIMA)  += lima/
    >  obj-$(CONFIG_DRM_PANFROST) += panfrost/
    >  obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/
    >  obj-$(CONFIG_DRM_MCDE) += mcde/
    > +obj-$(CONFIG_DRM_SPRD) += sprd/
    > diff --git a/drivers/gpu/drm/sprd/Kconfig
    b/drivers/gpu/drm/sprd/Kconfig
    > new file mode 100644
    > index 0000000..79f286b
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/Kconfig
    > @@ -0,0 +1,14 @@
    > +config DRM_SPRD
    > +     tristate "DRM Support for Unisoc SoCs Platform"
    > +     depends on ARCH_SPRD
    > +     depends on DRM && OF
    > +     select DRM_KMS_HELPER
    > +     select DRM_GEM_CMA_HELPER
    > +     select DRM_KMS_CMA_HELPER
    > +     select DRM_MIPI_DSI
    > +     select DRM_PANEL
    > +     select VIDEOMODE_HELPERS
    > +     select BACKLIGHT_CLASS_DEVICE
    > +     help
    > +       Choose this option if you have a Unisoc chipsets.
    > +       If M is selected the module will be called sprd-drm.
    > \ No newline at end of file
    > diff --git a/drivers/gpu/drm/sprd/Makefile
    b/drivers/gpu/drm/sprd/Makefile
    > new file mode 100644
    > index 0000000..df0b316
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/Makefile
    > @@ -0,0 +1,8 @@
    > +# SPDX-License-Identifier: GPL-2.0
    > +
    > +ccflags-y += -Iinclude/drm
    > +
    > +subdir-ccflags-y += -I$(src)
    > +
    > +obj-y := sprd_drm.o \
    > +     sprd_gem.o
    > \ No newline at end of file
    > diff --git a/drivers/gpu/drm/sprd/sprd_drm.c
    b/drivers/gpu/drm/sprd/sprd_drm.c
    > new file mode 100644
    > index 0000000..4aee25fa4
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/sprd_drm.c
    > @@ -0,0 +1,286 @@
    > +// SPDX-License-Identifier: GPL-2.0
    > +/*
    > + * Copyright (C) 2019 Unisoc Inc.
    > + */
    > +
    > +#include <linux/component.h>
    > +#include <linux/dma-mapping.h>
    > +#include <linux/module.h>
    > +#include <linux/mutex.h>
    > +#include <linux/of_graph.h>
    > +#include <linux/of_platform.h>
    > +
    > +#include <drm/drm_atomic_helper.h>
    > +#include <drm/drm_crtc_helper.h>
    > +#include <drm/drm_drv.h>
    > +#include <drm/drm_gem_cma_helper.h>
    > +#include <drm/drm_gem_framebuffer_helper.h>
    > +#include <drm/drm_probe_helper.h>
    > +#include <drm/drm_vblank.h>
    > +
    > +#include "sprd_drm.h"
    > +#include "sprd_gem.h"
    > +
    > +#define DRIVER_NAME  "sprd"
    > +#define DRIVER_DESC  "Spreadtrum SoCs' DRM Driver"
    > +#define DRIVER_DATE  "20191101"
    > +#define DRIVER_MAJOR 1
    > +#define DRIVER_MINOR 0
    > +
    > +static const struct drm_mode_config_helper_funcs
    sprd_drm_mode_config_helper = {
    > +     .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
    > +};
    > +
    > +static const struct drm_mode_config_funcs
    sprd_drm_mode_config_funcs = {
    > +     .fb_create = drm_gem_fb_create,
    > +     .atomic_check = drm_atomic_helper_check,
    > +     .atomic_commit = drm_atomic_helper_commit,
    > +};
    > +
    > +static void sprd_drm_mode_config_init(struct drm_device *drm)
    > +{
    > +     drm_mode_config_init(drm);
    > +
Quoted 8 lines
    > +     drm->mode_config.min_width = 0;
    > +     drm->mode_config.min_height = 0;
    > +     drm->mode_config.max_width = 8192;
    > +     drm->mode_config.max_height = 8192;
    > +     drm->mode_config.allow_fb_modifiers = true;
    > +
    > +     drm->mode_config.funcs = &sprd_drm_mode_config_funcs;
    > +     drm->mode_config.helper_private =

&sprd_drm_mode_config_helper;

Quoted 89 lines
Quoted 89 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +89 -0
+}
+
+static const struct file_operations sprd_drm_fops = {
+     .owner          = THIS_MODULE,
+     .open           = drm_open,
+     .release        = drm_release,
+     .unlocked_ioctl = drm_ioctl,
+     .compat_ioctl   = drm_compat_ioctl,
+     .poll           = drm_poll,
+     .read           = drm_read,
+     .llseek         = no_llseek,
+     .mmap           = sprd_gem_mmap,
+};
+
+static struct drm_driver sprd_drm_drv = {
+     .driver_features        = DRIVER_GEM | DRIVER_ATOMIC,
+     .fops                   = &sprd_drm_fops,
+     .gem_vm_ops             = &drm_gem_cma_vm_ops,
+     .gem_free_object_unlocked       = sprd_gem_free_object,
+     .dumb_create            = sprd_gem_dumb_create,
+     .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
+     .gem_prime_import       = drm_gem_prime_import,
+     .gem_prime_import_sg_table = sprd_gem_prime_import_sg_table,
+
+     .name                   = DRIVER_NAME,
+     .desc                   = DRIVER_DESC,
+     .date                   = DRIVER_DATE,
+     .major                  = DRIVER_MAJOR,
+     .minor                  = DRIVER_MINOR,
+};
+
+static int sprd_drm_bind(struct device *dev)
+{
+     struct drm_device *drm;
+     struct sprd_drm *sprd;
+     int err;
+
+     drm = drm_dev_alloc(&sprd_drm_drv, dev);
+     if (IS_ERR(drm))
+             return PTR_ERR(drm);
+
+     dev_set_drvdata(dev, drm);
+
+     sprd = devm_kzalloc(drm->dev, sizeof(*sprd), GFP_KERNEL);
+     if (!sprd) {
+             err = -ENOMEM;
+             goto err_free_drm;
+     }
+     drm->dev_private = sprd;
+
+     sprd_drm_mode_config_init(drm);
+
+     /* bind and init sub drivers */
+     err = component_bind_all(drm->dev, drm);
+     if (err) {
+             DRM_ERROR("failed to bind all component.\n");
+             goto err_dc_cleanup;
+     }
+
+     /* vblank init */
+     err = drm_vblank_init(drm, drm->mode_config.num_crtc);
+     if (err) {
+             DRM_ERROR("failed to initialize vblank.\n");
+             goto err_unbind_all;
+     }
+     /* with irq_enabled = true, we can use the vblank feature. */
+     drm->irq_enabled = true;
+
+     /* reset all the states of crtc/plane/encoder/connector */
+     drm_mode_config_reset(drm);
+
+     /* init kms poll for handling hpd */
+     drm_kms_helper_poll_init(drm);
+
+     err = drm_dev_register(drm, 0);
+     if (err < 0)
+             goto err_kms_helper_poll_fini;
+
+     return 0;
+
+err_kms_helper_poll_fini:
+     drm_kms_helper_poll_fini(drm);
+err_unbind_all:
+     component_unbind_all(drm->dev, drm);
+err_dc_cleanup:
+     drm_mode_config_cleanup(drm);
+err_free_drm:
+     drm_dev_put(drm);
+     return err;
Quoted 8 lines

drivers/gpu/drm/sprd/sprd_drm.c

Quoted 8 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +8 -0
+}
+
+static void sprd_drm_unbind(struct device *dev)
+{
+     drm_put_dev(dev_get_drvdata(dev));
+}
+
+static const struct component_master_ops sprd_drm_component_ops =

{

Quoted 111 lines
Quoted 15 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +15 -0
+     .bind = sprd_drm_bind,
+     .unbind = sprd_drm_unbind,
+};
+
+static int compare_of(struct device *dev, void *data)
+{
+     struct device_node *np = data;
+
+     DRM_DEBUG("compare %s\n", np->full_name);
+
+     return dev->of_node == np;
+}
+
+static int sprd_drm_component_probe(struct device *dev,
+                        const struct component_master_ops *m_ops)

drivers/gpu/drm/sprd/sprd_drm.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +10 -0
+{
+     struct device_node *ep, *port, *remote;
+     struct component_match *match = NULL;
+     int i;
+
+     if (!dev->of_node)
+             return -EINVAL;
+
+     /*
+      * Bind the crtc's ports first, so that
    drm_of_find_possible_crtcs()
    > +      * called from encoder's .bind callbacks works as expected
    > +      */
    > +     for (i = 0; ; i++) {
    > +             port = of_parse_phandle(dev->of_node, "ports", i);
    > +             if (!port)
    > +                     break;
    > +
    > +             if (!of_device_is_available(port->parent)) {
    > +                     of_node_put(port);
    > +                     continue;
    > +             }
    > +
    > +             component_match_add(dev, &match, compare_of,
    port->parent);
    > +             of_node_put(port);
    > +     }
    > +
    > +     if (i == 0) {
    > +             dev_err(dev, "missing 'ports' property\n");
    > +             return -ENODEV;
    > +     }
    > +
    > +     if (!match) {
    > +             dev_err(dev, "no available port\n");
    > +             return -ENODEV;
    > +     }
    > +
    > +     /*
    > +      * For bound crtcs, bind the encoders attached to their
    remote endpoint
    > +      */
    > +     for (i = 0; ; i++) {
    > +             port = of_parse_phandle(dev->of_node, "ports", i);
    > +             if (!port)
    > +                     break;
    > +
    > +             if (!of_device_is_available(port->parent)) {
    > +                     of_node_put(port);
    > +                     continue;
    > +             }
    > +
    > +             for_each_child_of_node(port, ep) {
    > +                     remote = of_graph_get_remote_port_parent(ep);
    > +                     if (!remote ||
    !of_device_is_available(remote)) {
    > +                             of_node_put(remote);
    > +                             continue;
    > +                     } else if
    (!of_device_is_available(remote->parent)) {
    > +                             dev_warn(dev, "parent device of %s
    is not available\n",
    > +                                      remote->full_name);
    > +                             of_node_put(remote);
    > +                             continue;
    > +                     }
    > +
    > +                     component_match_add(dev, &match, compare_of,
    remote);
    > +                     of_node_put(remote);
    > +             }
    > +             of_node_put(port);
    > +     }
    > +
    > +     return component_master_add_with_match(dev, m_ops, match);
    > +}
    > +
    > +static int sprd_drm_probe(struct platform_device *pdev)
    > +{
    > +     int ret;
    > +
    > +     ret = dma_set_mask_and_coherent(&pdev->dev, ~0);
    > +     if (ret) {
    > +             DRM_ERROR("dma_set_mask_and_coherent failed (%d)\n",
    ret);
    > +             return ret;
    > +     }
    > +
    > +     return sprd_drm_component_probe(&pdev->dev,
    &sprd_drm_component_ops);
    > +}
    > +
    > +static int sprd_drm_remove(struct platform_device *pdev)
    > +{
    > +     component_master_del(&pdev->dev, &sprd_drm_component_ops);
    > +     return 0;
Quoted 8 lines
    > +}
    > +
    > +static void sprd_drm_shutdown(struct platform_device *pdev)
    > +{
    > +     struct drm_device *drm = platform_get_drvdata(pdev);
    > +
    > +     if (!drm) {
    > +             DRM_WARN("drm device is not available, no

shutdown\n");

Quoted 131 lines
Quoted 15 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +15 -0
+             return;
+     }
+
+     drm_atomic_helper_shutdown(drm);
+}
+
+static const struct of_device_id sprd_drm_match_table[] = {
+     { .compatible = "sprd,display-subsystem",},
+     {},
+};
+MODULE_DEVICE_TABLE(of, sprd_drm_match_table);
+
+static struct platform_driver sprd_drm_driver = {
+     .probe = sprd_drm_probe,
+     .remove = sprd_drm_remove,

drivers/gpu/drm/sprd/sprd_drm.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_drm.c new file +10 -0
+     .shutdown = sprd_drm_shutdown,
+     .driver = {
+             .name = "sprd-drm-drv",
+             .of_match_table = sprd_drm_match_table,
+     },
+};
+
+module_platform_driver(sprd_drm_driver);
+
+MODULE_AUTHOR("Leon He <[email protected]
    <mailto:[email protected]>>");
    > +MODULE_AUTHOR("Kevin Tang <[email protected]
    <mailto:[email protected]>>");
    > +MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver");
    > +MODULE_LICENSE("GPL v2");
    > diff --git a/drivers/gpu/drm/sprd/sprd_drm.h
    b/drivers/gpu/drm/sprd/sprd_drm.h
    > new file mode 100644
    > index 0000000..137cb27
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/sprd_drm.h
    > @@ -0,0 +1,16 @@
    > +/* SPDX-License-Identifier: GPL-2.0 */
    > +/*
    > + * Copyright (C) 2019 Unisoc Inc.
    > + */
    > +
    > +#ifndef _SPRD_DRM_H_
    > +#define _SPRD_DRM_H_
    > +
    > +#include <drm/drm_atomic.h>
    > +#include <drm/drm_print.h>
    > +
    > +struct sprd_drm {
    > +     struct drm_device *drm;
    > +};
    > +
    > +#endif /* _SPRD_DRM_H_ */
    > diff --git a/drivers/gpu/drm/sprd/sprd_gem.c
    b/drivers/gpu/drm/sprd/sprd_gem.c
    > new file mode 100644
    > index 0000000..9aec78e
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/sprd_gem.c
    > @@ -0,0 +1,178 @@
    > +// SPDX-License-Identifier: GPL-2.0
    > +/*
    > + * Copyright (C) 2019 Unisoc Inc.
    > + */
    > +
    > +#include <linux/dma-buf.h>
    > +#include <linux/pm_runtime.h>
    > +
    > +#include <drm/drm_prime.h>
    > +
    > +#include "sprd_drm.h"
    > +#include "sprd_gem.h"
    > +
    > +static struct sprd_gem_obj *sprd_gem_obj_create(struct drm_device
    *drm,
    > +                                             unsigned long size)
    > +{
    > +     struct sprd_gem_obj *sprd_gem;
    > +     int ret;
    > +
    > +     sprd_gem = kzalloc(sizeof(*sprd_gem), GFP_KERNEL);
    > +     if (!sprd_gem)
    > +             return ERR_PTR(-ENOMEM);
    > +
    > +     ret = drm_gem_object_init(drm, &sprd_gem->base, size);
    > +     if (ret < 0) {
    > +             DRM_ERROR("failed to initialize gem object\n");
    > +             goto error;
    > +     }
    > +
    > +     ret = drm_gem_create_mmap_offset(&sprd_gem->base);
    > +     if (ret) {
    > +             drm_gem_object_release(&sprd_gem->base);
    > +             goto error;
    > +     }
    > +
    > +     return sprd_gem;
    > +
    > +error:
    > +     kfree(sprd_gem);
    > +     return ERR_PTR(ret);
    > +}
    > +
    > +void sprd_gem_free_object(struct drm_gem_object *obj)
    > +{
    > +     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
    > +
    > +     DRM_DEBUG("gem = %p\n", obj);
    > +
    > +     if (sprd_gem->vaddr)
    > +             dma_free_wc(obj->dev->dev, obj->size,
    > +                     sprd_gem->vaddr, sprd_gem->dma_addr);
    > +     else if (sprd_gem->sgtb)
    > +             drm_prime_gem_destroy(obj, sprd_gem->sgtb);
    > +
    > +     drm_gem_object_release(obj);
    > +
    > +     kfree(sprd_gem);
    > +}
    > +
    > +int sprd_gem_dumb_create(struct drm_file *file_priv, struct
    drm_device *drm,
    > +                         struct drm_mode_create_dumb *args)
    > +{
    > +     struct sprd_gem_obj *sprd_gem;
    > +     int ret;
    > +
    > +     args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
    > +     args->size = round_up(args->pitch * args->height, PAGE_SIZE);
    > +
    > +     sprd_gem = sprd_gem_obj_create(drm, args->size);
Quoted 8 lines
    > +     if (IS_ERR(sprd_gem))
    > +             return PTR_ERR(sprd_gem);
    > +
    > +     sprd_gem->vaddr = dma_alloc_wc(drm->dev, args->size,
    > +                     &sprd_gem->dma_addr, GFP_KERNEL |
    __GFP_NOWARN | GFP_DMA);

    I might be missing something, but I still don't understand why all

this

Quoted 1 line

GEM code is necessary. I quickly compared with the CMA helpers and

the

Quoted 10 lines

only meaningful difference is the use of the GFP_DMA flag.

Rather than duplicating the CMA code, it's better to change the CMA helpers to provide a way of setting this flag.

Best regards
Thomas

> + if (!sprd_gem->vaddr) {
> + DRM_ERROR("failed to allocate buffer with size

%llu\n",

Quoted 23 lines

drivers/gpu/drm/sprd/sprd_gem.c

Quoted 6 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +6 -0
+                       args->size);
+             ret = -ENOMEM;
+             goto error;
+     }
+
+     ret = drm_gem_handle_create(file_priv, &sprd_gem->base,
    &args->handle);
    > +     if (ret)
    > +             goto error;
    > +
    > +     drm_gem_object_put_unlocked(&sprd_gem->base);
    > +
    > +     return 0;
    > +
    > +error:
    > +     sprd_gem_free_object(&sprd_gem->base);
    > +     return ret;
    > +}
    > +
    > +static int sprd_gem_object_mmap(struct drm_gem_object *obj,
    > +                                struct vm_area_struct *vma)
    > +
    > +{
Quoted 8 lines
    > +     int ret;
    > +     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
    > +
    > +     vma->vm_flags &= ~VM_PFNMAP;
    > +     vma->vm_pgoff = 0;
    > +
    > +     ret = dma_mmap_wc(obj->dev->dev, vma,
    > +                                 sprd_gem->vaddr,

sprd_gem->dma_addr,

Quoted 119 lines
Quoted 24 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +24 -0
+                                 vma->vm_end - vma->vm_start);
+     if (ret)
+             drm_gem_vm_close(vma);
+
+     return ret;
+}
+
+int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+     struct drm_gem_object *obj;
+     int ret;
+
+     ret = drm_gem_mmap(filp, vma);
+     if (ret)
+             return ret;
+
+     obj = vma->vm_private_data;
+
+     return sprd_gem_object_mmap(obj, vma);
+}
+
+int sprd_gem_prime_mmap(struct drm_gem_object *obj,
+                         struct vm_area_struct *vma)
+{

drivers/gpu/drm/sprd/sprd_gem.c

Quoted 10 lines
drivers/gpu/drm/sprd/sprd_gem.c new file +10 -0
+     int ret;
+
+     ret = drm_gem_mmap_obj(obj, obj->size, vma);
+     if (ret)
+             return ret;
+
+     return sprd_gem_object_mmap(obj, vma);
+}
+
+struct sg_table *sprd_gem_prime_get_sg_table(struct
    drm_gem_object *obj)
    > +{
    > +     struct sprd_gem_obj *sprd_gem = to_sprd_gem_obj(obj);
    > +     struct sg_table *sgtb;
    > +     int ret;
    > +
    > +     sgtb = kzalloc(sizeof(*sgtb), GFP_KERNEL);
    > +     if (!sgtb)
    > +             return ERR_PTR(-ENOMEM);
    > +
    > +     ret = dma_get_sgtable(obj->dev->dev, sgtb, sprd_gem->vaddr,
    > +                           sprd_gem->dma_addr, obj->size);
    > +     if (ret) {
    > +             DRM_ERROR("failed to allocate sg_table, %d\n", ret);
    > +             kfree(sgtb);
    > +             return ERR_PTR(ret);
    > +     }
    > +
    > +     return sgtb;
    > +}
    > +
    > +struct drm_gem_object *sprd_gem_prime_import_sg_table(struct
    drm_device *drm,
    > +             struct dma_buf_attachment *attach, struct sg_table
    *sgtb)
    > +{
    > +     struct sprd_gem_obj *sprd_gem;
    > +
    > +     sprd_gem = sprd_gem_obj_create(drm, attach->dmabuf->size);
    > +     if (IS_ERR(sprd_gem))
    > +             return ERR_CAST(sprd_gem);
    > +
    > +     DRM_DEBUG("gem = %p\n", &sprd_gem->base);
    > +
    > +     if (sgtb->nents == 1)
    > +             sprd_gem->dma_addr = sg_dma_address(sgtb->sgl);
    > +
    > +     sprd_gem->sgtb = sgtb;
    > +
    > +     return &sprd_gem->base;
    > +}
    > diff --git a/drivers/gpu/drm/sprd/sprd_gem.h
    b/drivers/gpu/drm/sprd/sprd_gem.h
    > new file mode 100644
    > index 0000000..b6740bd
    > --- /dev/null
    > +++ b/drivers/gpu/drm/sprd/sprd_gem.h
    > @@ -0,0 +1,30 @@
    > +/* SPDX-License-Identifier: GPL-2.0 */
    > +/*
    > + * Copyright (C) 2019 Unisoc Inc.
    > + */
    > +
    > +#ifndef _SPRD_GEM_H_
    > +#define _SPRD_GEM_H_
    > +
    > +#include <drm/drm_gem.h>
    > +
    > +struct sprd_gem_obj {
    > +     struct drm_gem_object   base;
    > +     dma_addr_t              dma_addr;
    > +     struct sg_table         *sgtb;
    > +     void                    *vaddr;
    > +};
    > +
    > +#define to_sprd_gem_obj(x)   container_of(x, struct sprd_gem_obj,
    base)
    > +
    > +void sprd_gem_free_object(struct drm_gem_object *gem);
    > +int sprd_gem_dumb_create(struct drm_file *file_priv, struct
    drm_device *dev,
    > +                         struct drm_mode_create_dumb *args);
    > +int sprd_gem_mmap(struct file *filp, struct vm_area_struct *vma);
    > +int sprd_gem_prime_mmap(struct drm_gem_object *obj,
    > +                      struct vm_area_struct *vma);
    > +struct sg_table *sprd_gem_prime_get_sg_table(struct
    drm_gem_object *obj);
    > +struct drm_gem_object *sprd_gem_prime_import_sg_table(struct
    drm_device *dev,
    > +             struct dma_buf_attachment *attach, struct sg_table
    *sgtb);
    > +
    > +#endif
    >
Quoted 8 lines
    --
    Thomas Zimmermann
    Graphics Driver Developer
    SUSE Software Solutions Germany GmbH
    Maxfeldstr. 5, 90409 Nürnberg, Germany
    (HRB 36809, AG Nürnberg)
    Geschäftsführer: Felix Imendörffer
Quoted 9 lines

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

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

author
#8 lore raw

RFC PATCH 3/6 dt-bindings: display: add Unisoc's dpu bindings

In reply to Kevin Tang

From: Kevin Tang <[email protected]>

DPU (Display Processor Unit) is the Display Controller for the Unisoc SoCs which transfers the image data from a video memory buffer to an internal LCD interface.

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 .../devicetree/bindings/display/sprd/dpu.yaml      | 85 ++++++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sprd/dpu.yaml
Documentation/devicetree/bindings/display/sprd/dpu.yaml new file +85 -0
new file mode 100644
index 0000000..f84eddd
@@ -0,0 +1,85 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sprd/dpu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc SoC Display Processor Unit (DPU)
+
+maintainers:
+  - David Airlie <[email protected]>
+  - Daniel Vetter <[email protected]>
+  - Rob Herring <[email protected]>
+  - Mark Rutland <[email protected]>
+
+description: |
+  DPU (Display Processor Unit) is the Display Controller for the Unisoc SoCs
+  which transfers the image data from a video memory buffer to an internal
+  LCD interface.
+
+properties:
+  compatible:
+    const: sprd,display-processor
+
+  reg:
+    maxItems: 1
+    description:
+      Physical base address and length of the DPU registers set
+
+  interrupts:
+    maxItems: 1
+    description:
+      The interrupt signal from DPU
+
+  clocks:
+    minItems: 2
+
+  clock-names:
+    items:
+      - const: clk_src_128m
+      - const: clk_src_384m
+
+  power-domains:
+    description: A phandle to DPU power domain node.
+
+  iommus:
+    description: A phandle to DPU iommu node.
+
+  port:
+    type: object
+    description:
+      A port node with endpoint definitions as defined in
+      Documentation/devicetree/bindings/media/video-interfaces.txt.
+      That port should be the output endpoint, usually output to
+      the associated DSI.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/sprd,sc9860-clk.h>
+    dpu: dpu@0x63000000 {
+          compatible = "sprd,display-processor";
+          reg = <0x0 0x63000000 0x0 0x1000>;
+          interrupts = <GIC_SPI 46 IRQ_TYPE_LEVEL_HIGH>;
+          clock-names = "clk_src_128m",
+      	        "clk_src_384m";
+
+          clocks = <&pll CLK_TWPLL_128M>,
+                <&pll CLK_TWPLL_384M>;
+
+          dpu_port: port {
+                  dpu_out: endpoint {
+                          remote-endpoint = <&dsi_in>;
+                  };
+          };
+    };
Signature · 1 line
2.7.4
author
#9 lore raw

RFC PATCH 4/6 drm/sprd: add Unisoc's drm display controller driver

In reply to Kevin Tang

From: Kevin Tang <[email protected]>

Adds DPU(Display Processor Unit) support for the Unisoc's display subsystem. It's support multi planes, scaler, rotation, PQ(Picture Quality) and more.

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 drivers/gpu/drm/sprd/Makefile       |   6 +-
 drivers/gpu/drm/sprd/disp_lib.c     |  93 +++++
 drivers/gpu/drm/sprd/disp_lib.h     |  34 ++
 drivers/gpu/drm/sprd/dpu/Makefile   |   8 +
 drivers/gpu/drm/sprd/dpu/dpu_r2p0.c | 798 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_dpu.c     | 671 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/sprd/sprd_dpu.h     | 138 +++++++
 drivers/gpu/drm/sprd/sprd_drm.c     |   2 +-
 drivers/gpu/drm/sprd/sprd_drm.h     |   2 +
 9 files changed, 1750 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/sprd/disp_lib.c
 create mode 100644 drivers/gpu/drm/sprd/disp_lib.h
 create mode 100644 drivers/gpu/drm/sprd/dpu/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dpu/dpu_r2p0.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dpu.h
drivers/gpu/drm/sprd/Makefile +5 -1
index df0b316..3f188ab 100644
@@ -5,4 +5,8 @@ ccflags-y += -Iinclude/drm
 subdir-ccflags-y += -I$(src)
 
 obj-y := sprd_drm.o \
-	sprd_gem.o
\ No newline at end of file
+	sprd_gem.o \
+	sprd_dpu.o
+
+obj-y += disp_lib.o
+obj-y += dpu/
\ No newline at end of file
drivers/gpu/drm/sprd/disp_lib.c new file +93 -0

93 lines not on this page · raw message

drivers/gpu/drm/sprd/disp_lib.h new file +34 -0
new file mode 100644
index 0000000..d694302
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Unisoc Inc.
+ */
+
+#ifndef _DISP_LIB_H_
+#define _DISP_LIB_H_
+
+#include <linux/list.h>
+#include <drm/drm_print.h>
+
+#ifdef pr_fmt
+#undef pr_fmt
+#define pr_fmt(__fmt) "[drm][%20s] "__fmt, __func__
+#endif
+
+struct ops_entry {
+	const char *ver;
+	void *ops;
+};
+
+struct ops_list {
+	struct list_head head;
+	struct ops_entry *entry;
+};
+
+void *disp_ops_attach(const char *str, struct list_head *head);
+int disp_ops_register(struct ops_entry *entry, struct list_head *head);
+
+struct device *sprd_disp_pipe_get_by_port(struct device *dev, int port);
+struct device *sprd_disp_pipe_get_input(struct device *dev);
+struct device *sprd_disp_pipe_get_output(struct device *dev);
+
+#endif
drivers/gpu/drm/sprd/dpu/Makefile new file +8 -0
new file mode 100644
index 0000000..d960107
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ifdef CONFIG_ARM64
+KBUILD_CFLAGS += -mstrict-align
+endif
+
+obj-y += dpu_r2p0.o
+
drivers/gpu/drm/sprd/dpu/dpu_r2p0.c new file +798 -0

798 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dpu.c new file +671 -0

671 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dpu.h new file +138 -0

138 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_drm.c +1 -1
index 4aee25fa4..212324e 100644
@@ -64,7 +64,7 @@ static const struct file_operations sprd_drm_fops = {
 };
 
 static struct drm_driver sprd_drm_drv = {
-	.driver_features	= DRIVER_GEM | DRIVER_ATOMIC,
+	.driver_features	= DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
 	.fops			= &sprd_drm_fops,
 	.gem_vm_ops		= &drm_gem_cma_vm_ops,
 	.gem_free_object_unlocked	= sprd_gem_free_object,
drivers/gpu/drm/sprd/sprd_drm.h +2 -0
index 137cb27..1c021a8 100644
@@ -11,6 +11,8 @@
 
 struct sprd_drm {
 	struct drm_device *drm;
+	struct device *dpu_dev;
+
 };
 
 #endif /* _SPRD_DRM_H_ */
Signature · 1 line
2.7.4
author
#10 lore raw

RFC PATCH 5/6 dt-bindings: display: add Unisoc's mipi dsi&dphy bindings

In reply to Kevin Tang

From: Kevin Tang <[email protected]>

Adds MIPI DSI Master and MIPI DSI-PHY (D-PHY)
support for Unisoc's display subsystem.

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 .../devicetree/bindings/display/sprd/dphy.yaml     |  78 ++++++++++++++++
 .../devicetree/bindings/display/sprd/dsi.yaml      | 101 +++++++++++++++++++++
 2 files changed, 179 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/sprd/dphy.yaml
 create mode 100644 Documentation/devicetree/bindings/display/sprd/dsi.yaml
Documentation/devicetree/bindings/display/sprd/dphy.yaml new file +78 -0
new file mode 100644
index 0000000..dc00f35
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/sprd/dphy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc MIPI DSI-PHY (D-PHY)
+
+maintainers:
+  - David Airlie <[email protected]>
+  - Daniel Vetter <[email protected]>
+  - Rob Herring <[email protected]>
+  - Mark Rutland <[email protected]>
+
+properties:
+  compatible:
+    const: sprd,dsi-phy
+
+  reg:
+    maxItems: 1
+    description:
+      Must be the dsi controller base address.
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  port@0:
+    type: object
+    description:
+      A port node with endpoint definitions as defined in
+      Documentation/devicetree/bindings/media/video-interfaces.txt.
+      That port should be the output endpoint, usually output to
+      the associated panel.
+  port@1:
+    type: object
+    description:
+      A port node with endpoint definitions as defined in
+      Documentation/devicetree/bindings/media/video-interfaces.txt.
+      That port should be the input endpoint, usually coming from
+      the associated DSI controller.
+
+required:
+  - compatible
+  - reg
+  - port@0
+  - port@1
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    dphy: dphy {
+        compatible = "sprd,dsi-phy";
+        reg = <0x0 0x63100000 0x0 0x1000>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        /* input port*/
+        port@1 {
+            reg = <1>;
+            dphy_in: endpoint {
+    	          remote-endpoint = <&dsi_out>;
+            };
+        };
+
+        /* output port */
+        port@0 {
+    	      reg = <0>;
+    	      dphy_out: endpoint {
+    		        remote-endpoint = <&panel_in>;
+    	      };
+        };
+    };
\ No newline at end of file
Documentation/devicetree/bindings/display/sprd/dsi.yaml new file +101 -0

102 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#11 lore raw

RFC PATCH 6/6 drm/sprd: add Unisoc's drm mipi dsi&dphy driver

In reply to Kevin Tang

From: Kevin Tang <[email protected]>

Adds dsi host controller support for the Unisoc's display subsystem. Adds dsi phy support for the Unisoc's display subsystem. Only MIPI DSI Displays supported, DP/TV/HMDI will be support in the feature.

Cc Orson Zhai <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Chunyan Zhang <[email protected]>
---
 drivers/gpu/drm/sprd/Makefile                     |    8 +-
 drivers/gpu/drm/sprd/dphy/Makefile                |    7 +
 drivers/gpu/drm/sprd/dphy/pll/Makefile            |    3 +
 drivers/gpu/drm/sprd/dphy/pll/megacores_sharkle.c |  640 ++++++++++
 drivers/gpu/drm/sprd/dphy/sprd_dphy_api.c         |  254 ++++
 drivers/gpu/drm/sprd/dphy/sprd_dphy_hal.h         |  329 +++++
 drivers/gpu/drm/sprd/dsi/Makefile                 |    7 +
 drivers/gpu/drm/sprd/dsi/core/Makefile            |    3 +
 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.c     | 1186 +++++++++++++++++
 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.h     | 1417 +++++++++++++++++++++
 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0_ppi.c |  392 ++++++
 drivers/gpu/drm/sprd/dsi/sprd_dsi_api.c           |  544 ++++++++
 drivers/gpu/drm/sprd/dsi/sprd_dsi_api.h           |   28 +
 drivers/gpu/drm/sprd/dsi/sprd_dsi_hal.h           | 1102 ++++++++++++++++
 drivers/gpu/drm/sprd/sprd_dphy.c                  |  218 ++++
 drivers/gpu/drm/sprd/sprd_dphy.h                  |  106 ++
 drivers/gpu/drm/sprd/sprd_dsi.c                   |  606 +++++++++
 drivers/gpu/drm/sprd/sprd_dsi.h                   |  195 +++
 18 files changed, 7043 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/sprd/dphy/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dphy/pll/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dphy/pll/megacores_sharkle.c
 create mode 100644 drivers/gpu/drm/sprd/dphy/sprd_dphy_api.c
 create mode 100644 drivers/gpu/drm/sprd/dphy/sprd_dphy_hal.h
 create mode 100644 drivers/gpu/drm/sprd/dsi/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dsi/core/Makefile
 create mode 100644 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.c
 create mode 100644 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.h
 create mode 100644 drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0_ppi.c
 create mode 100644 drivers/gpu/drm/sprd/dsi/sprd_dsi_api.c
 create mode 100644 drivers/gpu/drm/sprd/dsi/sprd_dsi_api.h
 create mode 100644 drivers/gpu/drm/sprd/dsi/sprd_dsi_hal.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_dphy.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dphy.h
 create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.c
 create mode 100644 drivers/gpu/drm/sprd/sprd_dsi.h
drivers/gpu/drm/sprd/Makefile +6 -2
index 3f188ab..78d3ddb 100644
@@ -6,7 +6,11 @@ subdir-ccflags-y += -I$(src)
 
 obj-y := sprd_drm.o \
 	sprd_gem.o \
-	sprd_dpu.o
+	sprd_dpu.o \
+	sprd_dsi.o \
+	sprd_dphy.o
 
 obj-y += disp_lib.o
-obj-y += dpu/
\ No newline at end of file
+obj-y += dpu/
+obj-y += dsi/
+obj-y += dphy/
drivers/gpu/drm/sprd/dphy/Makefile new file +7 -0
new file mode 100644
index 0000000..8a1012d6
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+subdir-ccflags-y += -I$(src)
+
+obj-y := sprd_dphy_api.o
+
+obj-y += pll/
drivers/gpu/drm/sprd/dphy/pll/Makefile new file +3 -0
new file mode 100644
index 0000000..1fe9638
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += megacores_sharkle.o
\ No newline at end of file
drivers/gpu/drm/sprd/dphy/pll/megacores_sharkle.c new file +640 -0

640 lines not on this page · raw message

drivers/gpu/drm/sprd/dphy/sprd_dphy_api.c new file +254 -0

254 lines not on this page · raw message

drivers/gpu/drm/sprd/dphy/sprd_dphy_hal.h new file +329 -0

329 lines not on this page · raw message

drivers/gpu/drm/sprd/dsi/Makefile new file +7 -0
new file mode 100644
index 0000000..b7999b5
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+subdir-ccflags-y += -I$(src)
+
+obj-y += sprd_dsi_api.o
+
+obj-y += core/
drivers/gpu/drm/sprd/dsi/core/Makefile new file +3 -0
new file mode 100644
index 0000000..8a2957f
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += dsi_ctrl_r1p0.o dsi_ctrl_r1p0_ppi.o
\ No newline at end of file
drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.c new file +1186 -0

1,186 lines not on this page · raw message

drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0.h new file +1417 -0

555 lines not on this page · raw message

drivers/gpu/drm/sprd/dsi/core/dsi_ctrl_r1p0_ppi.c new file +392 -0

392 lines not on this page · raw message

drivers/gpu/drm/sprd/dsi/sprd_dsi_api.c new file +544 -0

544 lines not on this page · raw message

drivers/gpu/drm/sprd/dsi/sprd_dsi_api.h new file +28 -0
new file mode 100644
index 0000000..45a706a

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/sprd/dsi/sprd_dsi_hal.h new file +1102 -0

1,102 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dphy.c new file +218 -0

218 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dphy.h new file +106 -0

106 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dsi.c new file +606 -0

606 lines not on this page · raw message

drivers/gpu/drm/sprd/sprd_dsi.h new file +195 -0

195 lines not on this page · raw message

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

Signature · 1 line
2.7.4

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