Skip to contentSkip to conversation

drm/loongson: Introduce component framework support

PATCH Superseded Sui Jingfeng 2 participants 5 messages Jul 23, 2024 – Jul 24, 2024

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover drm/loongson: Introduce component framework support

Introduce component framework to avoid potential cyclic dependency problem. The whole driver won't finish bound before all submodules are ready, respective modules just do fundimental works in their probe() function, such as allocating storage for themselves, mapping mmio, and handling the external dependencies.

v1 -> v2:
* Squash patch 0002 and patch 0003 into one
* Fill typos and improve commit message

v2 -> v3:
* Squash all patch into one
* Create another platform device as drm proxy master.
* Make LSDC PCI driver as a subcomponent as well.

v3 -> v4:
* Tiny refinement and clean up.

Tested with ls3a6000+ls7a2000:

[   11.307887] loongson 0000:00:06.1: Found LS7A2000 bridge chipset, revision: 2
[   11.316701] loongson 0000:00:06.1: i2c-6(sda pin mask=1, scl pin mask=2) created
[   11.325318] loongson 0000:00:06.1: i2c-7(sda pin mask=4, scl pin mask=8) created
[   12.644855] loongson 0000:00:06.1: lsdc-output.0 probed, type: HDMI-or-VGA
[   12.654461] loongson 0000:00:06.1: lsdc-output.1 probed, type: HDMI
[   12.661175] loongson 0000:00:06.1: [drm] dc: 400MHz, gmc: 1200MHz, gpu: 480MHz
[   12.669027] loongson loongson: bound lsdc-output.0 (ops lsdc_output_component_ops [loongson])
[   12.677968] loongson loongson: bound lsdc-output.1 (ops lsdc_output_component_ops [loongson])
[   12.686578] loongson 0000:00:06.1: [drm] Dedicated vram start: 0xe0020000000, size: 256MiB
[   12.700799] loongson 0000:00:06.1: lsdc irq: 61
[   12.700802] loongson loongson: bound 0000:00:06.1 (ops lsdc_component_ops [loongson])
[   12.700825] loongson 0000:00:06.1: [drm] LoongGPU(TM): LG110, revision: 0, Host: LS7A2000
[   12.700835] loongson 0000:00:06.1: [drm] LoongGPU irq: 62
[   12.700837] loongson loongson: bound 0000:00:06.0 (ops loonggpu_component_ops [loongson])
[   12.700870] loongson 0000:00:06.1: [drm] Total 2 outputs
[   12.706489] loongson 0000:00:06.1: [drm] VRAM: 16384 pages ready
[   12.746614] loongson 0000:00:06.1: [drm] GTT: 32768 pages ready
[   12.792895] [drm] Initialized loongson 1.0.0 for 0000:00:06.1 on minor 0
[   12.879707] loongson 0000:00:06.1: [drm] fb0: loongsondrmfb frame buffer device
[   16.952830] loongson 0000:00:06.1: vgaarb: VGA decodes changed: olddecodes=io+mem,decodes=none:owns=io+mem

Tested with ls3a5000+ls7a1000:

[   10.509247] loongson.lsdc 0000:00:06.1: Found LS7A2000 bridge chipset, revision: 2
[   10.574274] loongson.lsdc 0000:00:06.1: i2c-6(sda pin mask=1, scl pin mask=2) created
[   10.624394] loongson.lsdc 0000:00:06.1: i2c-7(sda pin mask=4, scl pin mask=8) created
[   10.643855] loongson.lsdc 0000:00:06.1: loongson.output.agent.0 probed, type: HDMI-or-VGA
[   10.656206] loongson.lsdc 0000:00:06.1: loongson.output.agent.1 probed, type: HDMI
[   11.739180] loongson.loonggpu 0000:00:06.0: LoongGPU PCI driver probed
[   11.875815] loongson loongson: drm proxy probed
[   11.880345] loongson.lsdc 0000:00:06.1: [drm] Dedicated vram start: 0xe0020000000, size: 256MiB
[   11.889019] loongson.lsdc 0000:00:06.1: [drm] dc: 400MHz, gmc: 1200MHz, gpu: 480MHz
[   11.896673] loongson loongson: bound loongson.output.agent.0 (ops lsdc_output_component_ops [loongson])
[   11.906046] loongson loongson: bound loongson.output.agent.1 (ops lsdc_output_component_ops [loongson])
[   11.921372] loongson.lsdc 0000:00:06.1: lsdc irq: 61
[   11.926319] loongson loongson: bound 0000:00:06.1 (ops lsdc_pci_component_ops [loongson])
[   11.934474] loongson.lsdc 0000:00:06.1: [drm] LoongGPU(TM): LG110, revision: 0, Host: LS7A2000
[   11.943055] loongson.lsdc 0000:00:06.1: [drm] LoongGPU irq: 62
[   11.948869] loongson loongson: bound 0000:00:06.0 (ops loonggpu_component_ops [loongson])
[   11.997246] loongson.lsdc 0000:00:06.1: [drm] VRAM: 16384 pages ready
[   12.003665] loongson.lsdc 0000:00:06.1: [drm] GTT: 32768 pages ready
[   12.010295] [drm] Initialized loongson 1.0.0 for 0000:00:06.1 on minor 1
[   12.087732] loongson.lsdc 0000:00:06.1: [drm] fb0: loongsondrmfb frame buffer device
[   12.115177] loongson: total 4 drivers registered
[   16.110934] loongson.lsdc 0000:00:06.1: vgaarb: VGA decodes changed: olddecodes=io+mem,decodes=none:owns=io+mem

[root@fedora 0]# cd /sys/kernel/debug/dri/0000\:00\:06.1/ [root@fedora 0000:00:06.1]# ls

benchmark  clients  crtc-1     framebuffer  HDMI-A-1          mm     vram_mm
bos        clocks   encoder-0  gem_names    HDMI-A-2          name
chips      crtc-0   encoder-1  gtt_mm       internal_clients  state

[root@fedora 0000:00:06.1]# cat bos
bo[0000][0000000033d33c9c]: size: 8112KiB VRAM offset: 0
bo[0001][0000000059581d0a]: size: 8112KiB VRAM offset: 7ec000
bo[0002][00000000e7eec263]: size: 16KiB VRAM offset: 0
bo[0003][00000000d4fb6ef2]: size: 16KiB VRAM offset: fff8000
Pinned BO size: VRAM: 8128KiB, GTT: 0 KiB

[root@fedora 0000:00:06.1]# cat chips
Running on cpu 0xc0, cpu revision: 0x11
Contained in: LS7A2000 bridge chipset

[root@fedora 0000:00:06.1]# cat benchmark
Copy bo of 8100KiB 60 times from GTT to GTT in 48ms: 10125MB/s Copy bo of 8100KiB 60 times from GTT to VRAM in 104ms: 4673MB/s Copy bo of 8100KiB 60 times from VRAM to GTT in 13480ms: 36MB/s

Also run IGT kms_flip and fbdev tests, no obvious problem found.

Sui Jingfeng (1):
drm/loongson: Introduce component framework support

 drivers/gpu/drm/loongson/Makefile             |   6 +
 drivers/gpu/drm/loongson/loonggpu_pci_drv.c   | 163 ++++++++
 drivers/gpu/drm/loongson/loonggpu_pci_drv.h   |  35 ++
 drivers/gpu/drm/loongson/loongson_device.c    |  30 ++
 drivers/gpu/drm/loongson/loongson_drv.c       | 293 +++++++++++++
 drivers/gpu/drm/loongson/loongson_drv.h       |  90 ++++
 drivers/gpu/drm/loongson/loongson_module.c    |  84 +++-
 drivers/gpu/drm/loongson/loongson_module.h    |  32 ++
 drivers/gpu/drm/loongson/lsdc_benchmark.c     |  12 +-
 drivers/gpu/drm/loongson/lsdc_benchmark.h     |   2 +-
 drivers/gpu/drm/loongson/lsdc_component.c     | 159 +++++++
 drivers/gpu/drm/loongson/lsdc_crtc.c          |   4 +-
 drivers/gpu/drm/loongson/lsdc_debugfs.c       |  44 +-
 drivers/gpu/drm/loongson/lsdc_drv.c           | 394 ++----------------
 drivers/gpu/drm/loongson/lsdc_drv.h           |  83 +---
 drivers/gpu/drm/loongson/lsdc_gem.c           |  44 +-
 drivers/gpu/drm/loongson/lsdc_gem.h           |  19 +-
 drivers/gpu/drm/loongson/lsdc_gfxpll.c        |  29 +-
 drivers/gpu/drm/loongson/lsdc_gfxpll.h        |   3 +-
 drivers/gpu/drm/loongson/lsdc_i2c.c           |  43 +-
 drivers/gpu/drm/loongson/lsdc_i2c.h           |  12 +-
 drivers/gpu/drm/loongson/lsdc_output.c        | 183 ++++++++
 drivers/gpu/drm/loongson/lsdc_output.h        |  36 +-
 drivers/gpu/drm/loongson/lsdc_output_7a1000.c |  14 +-
 drivers/gpu/drm/loongson/lsdc_output_7a2000.c |  20 +-
 drivers/gpu/drm/loongson/lsdc_plane.c         |   4 +-
 drivers/gpu/drm/loongson/lsdc_ttm.c           |  84 ++--
 drivers/gpu/drm/loongson/lsdc_ttm.h           |   4 +-
 28 files changed, 1318 insertions(+), 608 deletions(-)
 create mode 100644 drivers/gpu/drm/loongson/loonggpu_pci_drv.c
 create mode 100644 drivers/gpu/drm/loongson/loonggpu_pci_drv.h
 create mode 100644 drivers/gpu/drm/loongson/loongson_drv.c
 create mode 100644 drivers/gpu/drm/loongson/loongson_drv.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_component.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_output.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/1 drm/loongson: Introduce component framework support

In some display subsystems, the functionality of a PCIe device may too complex to be managed by a single driver. A split of the functionality into child devices can help to achieve better modularity. For example, KMS drivers who have dependencies on external modules will suffer from the deferral probe problem. The problem is that the DRM driver has to tear down everything when it receives '-EPROBE_DEFER', even though the independent part of the driver is not related to this error.

Loongson Graphics are PCIe multifunctional devices, the GPU and the display controller are two distinct devices. Despite all hardware units that come along with PCIe are actually ready to be driven by the time of the dirver is loaded, drm/loongson driver still need to wait all of its dependencies ready before it can register the service to userspace.

The idea is to migrate (offload) the dependency to submodules, creating submodule by creating platform devices manually during driverload time. Submodules are functional as agents, which will be responsible for attaching needed external modules for the main body of the whole KMS driver. Submodules are also responsible for returning '-EPROBE_DEFER' to the driver core if it needs to do so.

Add a dummy GPU driver as a subcomponent, make LSDC PCI driver as a subcomponent as well. Introduce the component framework to bind those scatter software and/or hardware entities into one. Creating a platform device as a DRM proxy, which will attach the common drm routines to our hardware after all submodules bound. The proxy is the explicit executant working at the foreground, while the LSDC PCIe device is the master.

Move DRM-related codes into the loongson_drm_master_bind(), move output related things into the submodule, because the output hardware units are relatively standalone IPs and the encoder/connector/transcoder may depend on external modules. While the display controller itself and GPIO-I2Cs have no dependency on external modules, therefore go with the LSDC PCIe device. Also assign GFX PLL, TTM memory manager part, and power management part to loongson drm proxy, as they do not belong to the LSDC itself.

While at it, also do some cleanups.

---
 drivers/gpu/drm/loongson/Makefile             |   6 +
 drivers/gpu/drm/loongson/loonggpu_pci_drv.c   | 163 ++++++++
 drivers/gpu/drm/loongson/loonggpu_pci_drv.h   |  35 ++
 drivers/gpu/drm/loongson/loongson_device.c    |  30 ++
 drivers/gpu/drm/loongson/loongson_drv.c       | 293 +++++++++++++
 drivers/gpu/drm/loongson/loongson_drv.h       |  90 ++++
 drivers/gpu/drm/loongson/loongson_module.c    |  84 +++-
 drivers/gpu/drm/loongson/loongson_module.h    |  32 ++
 drivers/gpu/drm/loongson/lsdc_benchmark.c     |  12 +-
 drivers/gpu/drm/loongson/lsdc_benchmark.h     |   2 +-
 drivers/gpu/drm/loongson/lsdc_component.c     | 159 +++++++
 drivers/gpu/drm/loongson/lsdc_crtc.c          |   4 +-
 drivers/gpu/drm/loongson/lsdc_debugfs.c       |  44 +-
 drivers/gpu/drm/loongson/lsdc_drv.c           | 394 ++----------------
 drivers/gpu/drm/loongson/lsdc_drv.h           |  83 +---
 drivers/gpu/drm/loongson/lsdc_gem.c           |  44 +-
 drivers/gpu/drm/loongson/lsdc_gem.h           |  19 +-
 drivers/gpu/drm/loongson/lsdc_gfxpll.c        |  29 +-
 drivers/gpu/drm/loongson/lsdc_gfxpll.h        |   3 +-
 drivers/gpu/drm/loongson/lsdc_i2c.c           |  43 +-
 drivers/gpu/drm/loongson/lsdc_i2c.h           |  12 +-
 drivers/gpu/drm/loongson/lsdc_output.c        | 183 ++++++++
 drivers/gpu/drm/loongson/lsdc_output.h        |  36 +-
 drivers/gpu/drm/loongson/lsdc_output_7a1000.c |  14 +-
 drivers/gpu/drm/loongson/lsdc_output_7a2000.c |  20 +-
 drivers/gpu/drm/loongson/lsdc_plane.c         |   4 +-
 drivers/gpu/drm/loongson/lsdc_ttm.c           |  84 ++--
 drivers/gpu/drm/loongson/lsdc_ttm.h           |   4 +-
 28 files changed, 1318 insertions(+), 608 deletions(-)
 create mode 100644 drivers/gpu/drm/loongson/loonggpu_pci_drv.c
 create mode 100644 drivers/gpu/drm/loongson/loonggpu_pci_drv.h
 create mode 100644 drivers/gpu/drm/loongson/loongson_drv.c
 create mode 100644 drivers/gpu/drm/loongson/loongson_drv.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_component.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_output.c
drivers/gpu/drm/loongson/Makefile +6 -0
index 91e72bd900c1..1c496713baa9 100644
@@ -2,6 +2,7 @@
 
 loongson-y := \
 	lsdc_benchmark.o \
+	lsdc_component.o \
 	lsdc_crtc.o \
 	lsdc_debugfs.o \
 	lsdc_drv.o \
@@ -9,6 +10,7 @@ loongson-y := \
 	lsdc_gfxpll.o \
 	lsdc_i2c.o \
 	lsdc_irq.o \
+	lsdc_output.o \
 	lsdc_output_7a1000.o \
 	lsdc_output_7a2000.o \
 	lsdc_plane.o \
@@ -16,7 +18,11 @@ loongson-y := \
 	lsdc_probe.o \
 	lsdc_ttm.o
 
+loongson-y += \
+	loonggpu_pci_drv.o
+
 loongson-y += loongson_device.o \
+	      loongson_drv.o \
 	      loongson_module.o
 
 obj-$(CONFIG_DRM_LOONGSON) += loongson.o
drivers/gpu/drm/loongson/loonggpu_pci_drv.c new file +163 -0

163 lines not on this page · raw message

drivers/gpu/drm/loongson/loonggpu_pci_drv.h new file +35 -0
new file mode 100644
index 000000000000..1ba64ef12835
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Authors:
+ *      Sui Jingfeng <[email protected]>
+ */
+
+#ifndef __LOONGGPU_PCI_DRV_H__
+#define __LOONGGPU_PCI_DRV_H__
+
+#include <linux/component.h>
+#include <linux/pci.h>
+
+struct loonggpu_device {
+	struct pci_dev *pdev;
+	struct drm_device *drm;
+
+	void __iomem *reg_base;
+	int irq;
+
+	u32 ver_major;
+	u32 ver_minor;
+	u32 revision;
+};
+
+static inline u32 loong_rreg32(struct loonggpu_device *ldev, u32 offset)
+{
+	return readl(ldev->reg_base + offset);
+}
+
+static inline void loong_wreg32(struct loonggpu_device *ldev, u32 offset, u32 val)
+{
+	writel(val, ldev->reg_base + offset);
+}
+
+#endif
drivers/gpu/drm/loongson/loongson_device.c +30 -0
index 9986c8a2a255..364b4bdbf0c5 100644
@@ -4,6 +4,7 @@
  */
 
 #include <linux/pci.h>
+#include <linux/platform_device.h>
 
 #include "lsdc_drv.h"
 
@@ -100,3 +101,32 @@ lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip_id)
 {
 	return __chip_id_desc_table[chip_id];
 }
+
+static void loongson_device_postfini(void *data)
+{
+	struct platform_device *proxy = data;
+
+	platform_device_unregister(proxy);
+}
+
+int loongson_device_preinit(struct device *parent)
+{
+	struct platform_device *proxy;
+	int ret;
+
+	proxy = platform_device_register_resndata(parent,
+						  "loongson",
+						  PLATFORM_DEVID_NONE,
+						  NULL, 0,
+						  NULL, 0);
+	if (IS_ERR(proxy)) {
+		dev_err(parent, "failed to register loongson proxy device\n");
+		return PTR_ERR(proxy);
+	}
+
+	ret = devm_add_action_or_reset(parent, loongson_device_postfini, proxy);
+	if (ret)
+		return ret;
+
+	return 0;
+}
drivers/gpu/drm/loongson/loongson_drv.c new file +293 -0

293 lines not on this page · raw message

drivers/gpu/drm/loongson/loongson_drv.h new file +90 -0

90 lines not on this page · raw message

drivers/gpu/drm/loongson/loongson_module.c +82 -2

105 lines not on this page · raw message

drivers/gpu/drm/loongson/loongson_module.h +32 -0
index 931c17521bf0..592c10158588 100644
@@ -6,7 +6,39 @@
 #ifndef __LOONGSON_MODULE_H__
 #define __LOONGSON_MODULE_H__
 
+#define DRIVER_AUTHOR               "Sui Jingfeng <[email protected]>"
+#define DRIVER_NAME                 "loongson"
+#define DRIVER_DESC                 "drm driver for loongson graphics"
+#define DRIVER_DATE                 "20220701"
+#define DRIVER_MAJOR                1
+#define DRIVER_MINOR                0
+#define DRIVER_PATCHLEVEL           0
+
+enum loongson_chip_id {
+	CHIP_LS7A1000 = 0,
+	CHIP_LS7A2000 = 1,
+	CHIP_LS_LAST,
+};
+
+enum loongson_driver_type {
+	LOONGSON_DRIVER_TYPE_UNKNOWN = 0,
+	LOONGSON_DRIVER_TYPE_DRM_MASTER = 1,
+	LOONGSON_DRIVER_TYPE_PCI = 2,
+	LOONGSON_DRIVER_TYPE_PLATFORM = 4,
+};
+
+struct loongson_driver_info {
+	struct device_driver *driver;
+	u64 type;
+};
+
+const struct loongson_driver_info *loongson_get_driver_info_array(int *num);
+
 extern int loongson_vblank;
+
 extern struct pci_driver lsdc_pci_driver;
+extern struct pci_driver loonggpu_pci_driver;
+extern struct platform_driver lsdc_output_platform_driver;
+extern struct platform_driver loongson_drm_platform_driver;
 
 #endif
drivers/gpu/drm/loongson/lsdc_benchmark.c +6 -6
index b088646a2ff9..b3f2fde5d345 100644
@@ -5,6 +5,7 @@
 
 #include <drm/drm_debugfs.h>
 
+#include "loongson_drv.h"
 #include "lsdc_benchmark.h"
 #include "lsdc_drv.h"
 #include "lsdc_gem.h"
@@ -60,7 +61,7 @@ static void lsdc_copy_gtt_to_gtt_cpu(struct lsdc_bo *src_bo,
 	lsdc_bo_kunmap(dst_bo);
 }
 
-static void lsdc_benchmark_copy(struct lsdc_device *ldev,
+static void lsdc_benchmark_copy(struct drm_device *ddev,
 				unsigned int size,
 				unsigned int n,
 				u32 src_domain,
@@ -68,7 +69,6 @@ static void lsdc_benchmark_copy(struct lsdc_device *ldev,
 				lsdc_copy_proc_t copy_proc,
 				struct drm_printer *p)
 {
-	struct drm_device *ddev = &ldev->base;
 	struct lsdc_bo *src_bo;
 	struct lsdc_bo *dst_bo;
 	unsigned long start_jiffies;
@@ -100,12 +100,12 @@ static void lsdc_benchmark_copy(struct lsdc_device *ldev,
 		   time, throughput);
 }
 
-int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct drm_printer *p)
+int lsdc_show_benchmark_copy(struct drm_device *ddev, struct drm_printer *p)
 {
 	unsigned int buffer_size = 1920 * 1080 * 4;
 	unsigned int iteration = 60;
 
-	lsdc_benchmark_copy(ldev,
+	lsdc_benchmark_copy(ddev,
 			    buffer_size,
 			    iteration,
 			    LSDC_GEM_DOMAIN_GTT,
@@ -113,7 +113,7 @@ int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct drm_printer *p)
 			    lsdc_copy_gtt_to_gtt_cpu,
 			    p);
 
-	lsdc_benchmark_copy(ldev,
+	lsdc_benchmark_copy(ddev,
 			    buffer_size,
 			    iteration,
 			    LSDC_GEM_DOMAIN_GTT,
@@ -121,7 +121,7 @@ int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct drm_printer *p)
 			    lsdc_copy_gtt_to_vram_cpu,
 			    p);
 
-	lsdc_benchmark_copy(ldev,
+	lsdc_benchmark_copy(ddev,
 			    buffer_size,
 			    iteration,
 			    LSDC_GEM_DOMAIN_VRAM,
drivers/gpu/drm/loongson/lsdc_benchmark.h +1 -1
index 36110278237e..432213189044 100644
@@ -8,6 +8,6 @@
 
 #include "lsdc_drv.h"
 
-int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct drm_printer *p);
+int lsdc_show_benchmark_copy(struct drm_device *ddev, struct drm_printer *p);
 
 #endif
drivers/gpu/drm/loongson/lsdc_component.c new file +159 -0

159 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_crtc.c +2 -2
index 03958b79f251..76f5269a3efa 100644
@@ -84,7 +84,7 @@ static void lsdc_crtc0_enable(struct lsdc_crtc *lcrtc)
 	 * something if it happens.
 	 */
 	if (val & CRTC_ANCHORED) {
-		drm_warn(&ldev->base, "%s stall\n", lcrtc->base.name);
+		drm_warn(ldev->drm, "%s stall\n", lcrtc->base.name);
 		return lsdc_crtc0_soft_reset(lcrtc);
 	}
 
@@ -112,7 +112,7 @@ static void lsdc_crtc1_enable(struct lsdc_crtc *lcrtc)
 	 */
 	val = lsdc_rreg32(ldev, LSDC_CRTC1_CFG_REG);
 	if (val & CRTC_ANCHORED) {
-		drm_warn(&ldev->base, "%s stall\n", lcrtc->base.name);
+		drm_warn(ldev->drm, "%s stall\n", lcrtc->base.name);
 		return lsdc_crtc1_soft_reset(lcrtc);
 	}
 
drivers/gpu/drm/loongson/lsdc_debugfs.c +11 -33

93 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_drv.c +29 -365

458 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_drv.h +14 -69

147 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_gem.c +29 -15

103 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_gem.h +16 -3
index 92cbb10e6e13..baf9184cbaaa 100644
@@ -6,18 +6,31 @@
 #ifndef __LSDC_GEM_H__
 #define __LSDC_GEM_H__
 
+#include <linux/types.h>
+
 #include <drm/drm_device.h>
 #include <drm/drm_gem.h>
 
+struct loongson_gem {
+	/* @mutex: protect objects list */
+	struct mutex mutex;
+	struct list_head objects;
+};
+
+struct lsdc_bo;
+
+void lsdc_gem_list_add_lbo(struct drm_device *ddev, struct lsdc_bo *lbo);
+void lsdc_gem_list_rm_lbo(struct drm_device *ddev, struct lsdc_bo *lbo);
+
 struct drm_gem_object *
 lsdc_prime_import_sg_table(struct drm_device *ddev,
 			   struct dma_buf_attachment *attach,
 			   struct sg_table *sg);
 
 int lsdc_dumb_map_offset(struct drm_file *file,
-			 struct drm_device *dev,
-			 u32 handle,
-			 uint64_t *offset);
+			     struct drm_device *dev,
+			     u32 handle,
+			     uint64_t *offset);
 
 int lsdc_dumb_create(struct drm_file *file,
 		     struct drm_device *ddev,
drivers/gpu/drm/loongson/lsdc_gfxpll.c +7 -22
index 249c09d703ad..c16ffd20f885 100644
@@ -10,6 +10,7 @@
 #include <drm/drm_print.h>
 
 #include "lsdc_drv.h"
+#include "lsdc_gfxpll.h"
 
 /*
  * GFX PLL is the PLL used by DC, GMC and GPU, the structure of the GFX PLL
@@ -143,8 +144,6 @@ static void loongson_gfxpll_fini(struct drm_device *ddev, void *data)
 	struct loongson_gfxpll *this = (struct loongson_gfxpll *)data;
 
 	iounmap(this->mmio);
-
-	kfree(this);
 }
 
 static int loongson_gfxpll_init(struct loongson_gfxpll * const this)
@@ -160,7 +159,7 @@ static int loongson_gfxpll_init(struct loongson_gfxpll * const this)
 
 	this->funcs->print(this, &printer, false);
 
-	return 0;
+	return drmm_add_action_or_reset(this->ddev, loongson_gfxpll_fini, this);
 }
 
 static const struct loongson_gfxpll_funcs lsdc_gmc_gpu_funcs = {
@@ -170,30 +169,16 @@ static const struct loongson_gfxpll_funcs lsdc_gmc_gpu_funcs = {
 	.print = loongson_gfxpll_print,
 };
 
-int loongson_gfxpll_create(struct drm_device *ddev,
-			   struct loongson_gfxpll **ppout)
+int loongson_gfxpll_preinit(struct drm_device *ddev)
 {
-	struct lsdc_device *ldev = to_lsdc(ddev);
-	const struct loongson_gfx_desc *gfx = to_loongson_gfx(ldev->descp);
-	struct loongson_gfxpll *this;
-	int ret;
-
-	this = kzalloc(sizeof(*this), GFP_KERNEL);
-	if (IS_ERR_OR_NULL(this))
-		return -ENOMEM;
+	struct loongson_drm *ldrm = to_loongson_drm(ddev);
+	const struct loongson_gfx_desc *gfx = ldrm->gfxinfo;
+	struct loongson_gfxpll *this = &ldrm->gfxpll;
 
 	this->ddev = ddev;
 	this->reg_size = gfx->gfxpll.reg_size;
 	this->reg_base = gfx->conf_reg_base + gfx->gfxpll.reg_offset;
 	this->funcs = &lsdc_gmc_gpu_funcs;
 
-	ret = this->funcs->init(this);
-	if (unlikely(ret)) {
-		kfree(this);
-		return ret;
-	}
-
-	*ppout = this;
-
-	return drmm_add_action_or_reset(ddev, loongson_gfxpll_fini, this);
+	return this->funcs->init(this);
 }
drivers/gpu/drm/loongson/lsdc_gfxpll.h +1 -2
index 9d59cbfc145d..470e20ec51bf 100644
@@ -46,7 +46,6 @@ struct loongson_gfxpll {
 	struct loongson_gfxpll_parms parms;
 };
 
-int loongson_gfxpll_create(struct drm_device *ddev,
-			   struct loongson_gfxpll **ppout);
+int loongson_gfxpll_preinit(struct drm_device *ddev);
 
 #endif
drivers/gpu/drm/loongson/lsdc_i2c.c +29 -14

101 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_i2c.h +7 -5
index 88cd1a1817a5..20ef1bdfc4a4 100644
@@ -9,10 +9,13 @@
 #include <linux/i2c.h>
 #include <linux/i2c-algo-bit.h>
 
+struct lsdc_device;
+struct lsdc_desc;
+
 struct lsdc_i2c {
 	struct i2c_adapter adapter;
 	struct i2c_algo_bit_data bit;
-	struct drm_device *ddev;
+	struct lsdc_device *lsdc;
 	void __iomem *dir_reg;
 	void __iomem *dat_reg;
 	/* pin bit mask */
@@ -20,10 +23,9 @@ struct lsdc_i2c {
 	u8 scl;
 };
 
-struct lsdc_display_pipe;
+int lsdc_create_i2c_chan(struct device *parent, unsigned int index,
+			 struct i2c_adapter **ppadapter);
 
-int lsdc_create_i2c_chan(struct drm_device *ddev,
-			 struct lsdc_display_pipe *dispipe,
-			 unsigned int index);
+int lsdc_i2c_preinit(struct device *parent, const struct lsdc_desc *descp);
 
 #endif
drivers/gpu/drm/loongson/lsdc_output.c new file +183 -0

183 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_output.h +33 -3
index 097789051a1d..c7f0933695af 100644
@@ -6,16 +6,46 @@
 #ifndef __LSDC_OUTPUT_H__
 #define __LSDC_OUTPUT_H__
 
-#include "lsdc_drv.h"
+#include <linux/component.h>
+
+#include <drm/drm_encoder.h>
+#include <drm/drm_connector.h>
+
+struct lsdc_desc;
+
+struct lsdc_output {
+	struct device *dev;
+	struct drm_encoder encoder;
+	struct drm_connector connector;
+	unsigned int pipe;
+};
+
+static inline struct lsdc_output *
+connector_to_lsdc_output(struct drm_connector *connector)
+{
+	return container_of(connector, struct lsdc_output, connector);
+}
+
+static inline struct lsdc_output *
+encoder_to_lsdc_output(struct drm_encoder *encoder)
+{
+	return container_of(encoder, struct lsdc_output, encoder);
+}
 
 int ls7a1000_output_init(struct drm_device *ddev,
-			 struct lsdc_display_pipe *dispipe,
+			 struct lsdc_output *output,
 			 struct i2c_adapter *ddc,
 			 unsigned int index);
 
 int ls7a2000_output_init(struct drm_device *ldev,
-			 struct lsdc_display_pipe *dispipe,
+			 struct lsdc_output *output,
 			 struct i2c_adapter *ddc,
 			 unsigned int index);
 
+int lsdc_output_preinit(struct device *parent,
+			const struct lsdc_desc *descp);
+
+void lsdc_output_match_add(struct device *parent,
+			   struct component_match **matchptr);
+
 #endif
drivers/gpu/drm/loongson/lsdc_output_7a1000.c +6 -8
index 600ed4fb0884..260712fe452f 100644
@@ -3,10 +3,13 @@
  * Copyright (C) 2023 Loongson Technology Corporation Limited
  */
 
+#include <linux/property.h>
+
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_edid.h>
 #include <drm/drm_probe_helper.h>
 
+#include "loongson_drv.h"
 #include "lsdc_drv.h"
 #include "lsdc_output.h"
 
@@ -101,8 +104,7 @@ static const struct drm_connector_funcs ls7a1000_dpi_connector_funcs = {
 
 static void ls7a1000_pipe0_encoder_reset(struct drm_encoder *encoder)
 {
-	struct drm_device *ddev = encoder->dev;
-	struct lsdc_device *ldev = to_lsdc(ddev);
+	struct lsdc_device *ldev = to_lsdc(encoder->dev);
 
 	/*
 	 * We need this for S3 support, screen will not lightup if don't set
@@ -114,8 +116,7 @@ static void ls7a1000_pipe0_encoder_reset(struct drm_encoder *encoder)
 
 static void ls7a1000_pipe1_encoder_reset(struct drm_encoder *encoder)
 {
-	struct drm_device *ddev = encoder->dev;
-	struct lsdc_device *ldev = to_lsdc(ddev);
+	struct lsdc_device *ldev = to_lsdc(encoder->dev);
 
 	/*
 	 * We need this for S3 support, screen will not lightup if don't set
@@ -139,11 +140,10 @@ static const struct drm_encoder_funcs ls7a1000_encoder_funcs[2] = {
 };
 
 int ls7a1000_output_init(struct drm_device *ddev,
-			 struct lsdc_display_pipe *dispipe,
+			 struct lsdc_output *output,
 			 struct i2c_adapter *ddc,
 			 unsigned int index)
 {
-	struct lsdc_output *output = &dispipe->output;
 	struct drm_encoder *encoder = &output->encoder;
 	struct drm_connector *connector = &output->connector;
 	int ret;
@@ -161,8 +161,6 @@ int ls7a1000_output_init(struct drm_device *ddev,
 	if (ret)
 		return ret;
 
-	drm_info(ddev, "display pipe-%u has a DVO\n", index);
-
 	drm_connector_helper_add(connector, &ls7a1000_dpi_connector_helpers);
 
 	drm_connector_attach_encoder(connector, encoder);
drivers/gpu/drm/loongson/lsdc_output_7a2000.c +7 -13
index 2bd797a9b9ff..2cb7ffaf8265 100644
@@ -10,6 +10,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_probe_helper.h>
 
+#include "loongson_drv.h"
 #include "lsdc_drv.h"
 #include "lsdc_output.h"
 
@@ -283,8 +284,7 @@ static int ls7a2000_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
 					   struct drm_display_mode *mode)
 {
 	struct lsdc_output *output = encoder_to_lsdc_output(encoder);
-	struct lsdc_display_pipe *dispipe = output_to_display_pipe(output);
-	unsigned int index = dispipe->index;
+	unsigned int index = output->pipe;
 	struct drm_device *ddev = encoder->dev;
 	struct lsdc_device *ldev = to_lsdc(ddev);
 	struct hdmi_avi_infoframe infoframe;
@@ -334,8 +334,7 @@ static void ls7a2000_hdmi_atomic_disable(struct drm_encoder *encoder,
 					 struct drm_atomic_state *state)
 {
 	struct lsdc_output *output = encoder_to_lsdc_output(encoder);
-	struct lsdc_display_pipe *dispipe = output_to_display_pipe(output);
-	unsigned int index = dispipe->index;
+	unsigned int index = output->pipe;
 	struct drm_device *ddev = encoder->dev;
 	struct lsdc_device *ldev = to_lsdc(ddev);
 	u32 val;
@@ -359,8 +358,7 @@ static void ls7a2000_hdmi_atomic_enable(struct drm_encoder *encoder,
 	struct drm_device *ddev = encoder->dev;
 	struct lsdc_device *ldev = to_lsdc(ddev);
 	struct lsdc_output *output = encoder_to_lsdc_output(encoder);
-	struct lsdc_display_pipe *dispipe = output_to_display_pipe(output);
-	unsigned int index = dispipe->index;
+	unsigned int index = output->pipe;
 	u32 val;
 
 	/* datasheet say it should larger than 48 */
@@ -414,7 +412,7 @@ static void ls7a2000_hdmi_phy_pll_config(struct lsdc_device *ldev,
 					 int fin,
 					 unsigned int index)
 {
-	struct drm_device *ddev = &ldev->base;
+	struct drm_device *ddev = ldev->drm;
 	int count = 0;
 	u32 val;
 
@@ -481,8 +479,7 @@ static void ls7a2000_hdmi_atomic_mode_set(struct drm_encoder *encoder,
 					  struct drm_connector_state *conn_state)
 {
 	struct lsdc_output *output = encoder_to_lsdc_output(encoder);
-	struct lsdc_display_pipe *dispipe = output_to_display_pipe(output);
-	unsigned int index = dispipe->index;
+	unsigned int index = output->pipe;
 	struct drm_device *ddev = encoder->dev;
 	struct lsdc_device *ldev = to_lsdc(ddev);
 	struct drm_display_mode *mode = &crtc_state->mode;
@@ -511,11 +508,10 @@ static const struct drm_encoder_helper_funcs ls7a2000_encoder_helper_funcs = {
  * writing hdmi register do no harms.
  */
 int ls7a2000_output_init(struct drm_device *ddev,
-			 struct lsdc_display_pipe *dispipe,
+			 struct lsdc_output *output,
 			 struct i2c_adapter *ddc,
 			 unsigned int pipe)
 {
-	struct lsdc_output *output = &dispipe->output;
 	struct drm_encoder *encoder = &output->encoder;
 	struct drm_connector *connector = &output->connector;
 	int ret;
@@ -535,8 +531,6 @@ int ls7a2000_output_init(struct drm_device *ddev,
 	if (ret)
 		return ret;
 
-	drm_info(ddev, "display pipe-%u has HDMI %s\n", pipe, pipe ? "" : "and/or VGA");
-
 	drm_connector_helper_add(connector, &ls7a2000_connector_helpers);
 
 	drm_connector_attach_encoder(connector, encoder);
drivers/gpu/drm/loongson/lsdc_plane.c +2 -2
index d227a2c1dcf1..c25e13184107 100644
@@ -10,6 +10,7 @@
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_gem_atomic_helper.h>
 
+#include "loongson_drv.h"
 #include "lsdc_drv.h"
 #include "lsdc_regs.h"
 #include "lsdc_ttm.h"
@@ -40,10 +41,9 @@ static unsigned int lsdc_get_fb_offset(struct drm_framebuffer *fb,
 
 static u64 lsdc_fb_base_addr(struct drm_framebuffer *fb)
 {
-	struct lsdc_device *ldev = to_lsdc(fb->dev);
 	struct lsdc_bo *lbo = gem_to_lsdc_bo(fb->obj[0]);
 
-	return lsdc_bo_gpu_offset(lbo) + ldev->vram_base;
+	return lsdc_bo_gpu_offset(lbo) + loongson_drm_vram_base(fb->dev);
 }
 
 static int lsdc_primary_atomic_check(struct drm_plane *plane,
drivers/gpu/drm/loongson/lsdc_ttm.c +43 -41

214 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_ttm.h +2 -2
index 843e1475064e..2825cec82172 100644
@@ -93,7 +93,7 @@ void lsdc_bo_clear(struct lsdc_bo *lbo);
 
 int lsdc_bo_evict_vram(struct drm_device *ddev);
 
-int lsdc_ttm_init(struct lsdc_device *ldev);
-void lsdc_ttm_debugfs_init(struct lsdc_device *ldev);
+int lsdc_ttm_init(struct drm_device *ddev);
+void lsdc_ttm_debugfs_init(struct drm_device *ddev);
 
 #endif
Signature · 1 line
2.43.0
#2 lore raw
Quoted 1 line

In some display subsystems, the functionality of a PCIe device may too

might be?

…

Quoted 1 line

of the dirver is loaded, …

driver?

…

Quoted 1 line

its dependencies ready before it can register the service to userspace.

user space?

…

Quoted 1 line

submodule by creating platform devices manually during driverload time.

driver load?

…

Quoted 1 line

device as a DRM proxy, which will attach the common drm routines to our

DRM?

…

Quoted 1 line

While at it, also do some cleanups.

I find such information suspicious.
Is there any need to offer adjustments as separate update steps?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10#n81

Regards,
Markus

#3 lore raw

Hi,

Quoted 29 lines · Markus Elfring
Quoted 1 line

In some display subsystems, the functionality of a PCIe device may too

might be?

…

Quoted 1 line

of the dirver is loaded, …

driver?

…

Quoted 1 line

its dependencies ready before it can register the service to userspace.

user space?

…

Quoted 1 line

submodule by creating platform devices manually during driverload time.

driver load?

…

Quoted 1 line

device as a DRM proxy, which will attach the common drm routines to our

DRM?

Quoted 6 lines

…

Quoted 1 line

While at it, also do some cleanups.

I find such information suspicious.
Is there any need to offer adjustments as separate update steps?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10#n81

Thanks a lot for review, I will try to fix those problems in the future.

Quoted 2 lines

Regards,
Markus