Skip to contentSkip to conversation

drm: add kms driver for loongson display controller

PATCH Superseded Sui Jingfeng 5 participants 43 messages May 20, 2023 – Jun 13, 2023

Subsystems (4)

v14 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v14 cover drm: add kms driver for loongson display controller

From: Sui Jingfeng <[email protected]>

Loongson display controller IP has been integrated in both Loongson north bridge chipset(ls7a1000/ls7a2000) and Loongson SoCs(ls2k1000/ls2k2000), it has been even included in Loongson self-made BMC products.

This display controller is a PCI device. It has two display pipes and each display pipe support a primary plane and a cursor plane. For the DC in the ls7a1000 and ls2k1000, each display pipe has a DVO output interface which provide RGB888 signals, vertical & horizontal synchronisations and pixel clock. Each CRTC is able to support 1920x1080@60Hz, the maximum resolution of each display pipe is 2048x2048 according to the hardware spec.

For the DC in LS7A2000, each display pipe is equipped with a built-in HDMI encoder which is compliant with the HDMI 1.4 specification, thus it support 3840x2160@30Hz. The first display pipe is also equipped with a transparent vga encoder which is parallel with the HDMI encoder. The DC in LS7A2000 is more complete compare with the one in old chips, besides above feature, it has two hardware cursors, two hardware vblank counter and two scanout position recorders unit. It also support tiled framebuffer format which can be scanout the tiled framebuffer rendered by the LoongGPU directly.

v1 -> v2:
1) Use hpd status reg when polling for ls7a2000
2) Fix all warnings emerged when compile with W=1

v2 -> v3:
1) Add COMPILE_TEST in Kconfig and make the driver off by default
2) Alphabetical sorting headers (Thomas)
3) Untangle register access functions as much as possible (Thomas)
4) Switch to TTM based memory manager and prefer cached mapping for Loongson SoC (Thomas)
5) Add chip id detection method, now all models are distinguishable.
6) Revise builtin HDMI phy driver, nearly all main stream mode below 4K@30Hz is tested, this driver supported these mode very well including clone display mode and extend display mode.

v3 -> v4:
1) Quickly fix a small mistake.

v4 -> v5:
1) Drop potential support for Loongson 2K series SoC temporary, this part should be resend with the DT binding patch in the future.
2) Add per display pipe debugfs support to the builtin HDMI encoder.
3) Rewrite atomic_update() for hardware cursors plane(Thomas)
4) Rewrite encoder and connector initialization part, untangle it according to the chip(Thomas).

v5 -> v6:
1) Remove stray code which didn't get used, say lsdc_of_get_reserved_ram
2) Fix all typos I could found, make sentences and code more readable
3) Untangle lsdc_hdmi*_connector_detect() function according to the pipe
4) After a serious consideration, we rename this driver as loongson. Because we also have drivers toward the LoongGPU IP in LS7A2000 and LS2K2000. Besides, there are also drivers about the external encoder, HDMI audio driver and vbios support etc. This patch only provide DC driver part, my teammate Li Yi believe that loongson will be more suitable for loongson graphics than lsdc in the long run.

loongson.ko = LSDC + LoongGPU + encoders driver + vbios/DT ...

v6 -> v7:
1) Add prime support, self-sharing is works. sharing buffer with etnaviv is also tested, and its works with limitation.
2) Implement buffer objects tracking with list_head.
3) S3(sleep to RAM) is tested on ls3a5000+ls7a2000 evb and it works.
4) Rewrite lsdc_bo_move, since ttm core stop allocating resources during BO creation. Patch V1 ~ V6 of this series no longer works on latest kernel. Thus, we send V7 to revival them.

v7 -> v8:
1) Zero a compile warnnings on 32-bit platform, compile with W=1
2) Revise lsdc_bo_gpu_offset() and minor cleanup
3) Pageflip tested on the virtual terminal with following commands

    modetest -M loongson -s 32:1920x1080 -v
    modetest -M loongson -s 34:1920x1080 -v -F tiles

It works like a charm, when running pageflip test with dual screnn configuration, another two additional bo created by the modetest emerged, VRAM usage up to 40+MB, well we have at least 64MB, still enough.

   # cat bos
       bo[0000]: size:     8112kB VRAM
       bo[0001]: size:       16kB VRAM
       bo[0002]: size:       16kB VRAM
       bo[0003]: size:    16208kB VRAM
       bo[0004]: size:     8112kB VRAM
       bo[0005]: size:     8112kB VRAM

v8 -> v9:
1) Select I2C and I2C_ALGOBIT in Kconfig and should depend on MMU.
2) Using pci_get_domain_bus_and_slot to get the GPU device.
3) Other minor improvements.

Those patches are tested on ls3a5000 + ls7a1000 CRB, ls3a5000 + ls7a2000 evb, and lemote a1901 board(ls3a4000 + ls7a1000). On loongson mips CPU, the write combine support should be enabled, to get a decent performance for writing framebuffer data to the VRAM.

v9 -> v10:
1) Revise lsdc_drm_freeze() to implement S3 completely and correctly. I suddenly realized that pinned buffer can not move and VRAM lost power when sleep to RAM. Thus, the data in the buffer who is pinned in VRAM will get lost when resume. Yet it's not big problem because we are software rendering solution which relay on the CPU update the front framebuffer. We can see the garbage data when resume from S3, but the screen will show correct image as I move the cursor. This is due to the cpu repaint. v10 of this patch make S3 perfect by unpin all of BOs in VRAM, evict them all to system RAM.

v10 -> v11:
1) On double screen case, the single giant framebuffer is referenced by two GEM object, hence, it will be pinned by prepare_fb() at lease two times. This cause its pin count > 1. V10 of this patch only unpin VRAM BOs once when suspend, which is not correct on double screen case. V11 of this patch unpin BOs until its pin count reach to zero when suspend. Then, we make the S3 support complete finally. With v11, I can't see any garbage data after resume. Tested on both ls7a1000 and ls7a2000 platform, with single screen and double screen configuration.
2) Fix vblank wait timeout when disable CRTC.
3) Test against IGT, at least fbdev test and kms_flip test passed.
4) Rewrite pixel PLL update function, magic numbers eliminated (Emil)
5) Drop a few common hardware features description in lsdc_desc (Emil)
6) Drop lsdc_mode_config_mode_valid(), instead add restrictions in dumb create function. (Emil)
7) Untangle the ls7a1000 case and ls7a2000 case completely (Thomas)

v11 -> v12:
none

v12 -> v13:
1) Add benchmark to figure out the bandwidth of the hardware platform. Usage:
# cd /sys/kernel/debug/dri/0/
# cat benchmark

2) VRAM is filled with garbage data if uninitialized, add a buffer clearing procedure, clear it on the BO creation time.
3) Update copyrights and adjust coding style (Huacai)

v13 -> v14:
1) Trying to add async update support for cursor plane.

Sui Jingfeng (2):
drm: add kms driver for loongson display controller
MAINTAINERS: add maintainers for DRM LOONGSON driver

 MAINTAINERS                                   |    8 +
 drivers/gpu/drm/Kconfig                       |    2 +
 drivers/gpu/drm/Makefile                      |    1 +
 drivers/gpu/drm/loongson/Kconfig              |   17 +
 drivers/gpu/drm/loongson/Makefile             |   20 +
 drivers/gpu/drm/loongson/lsdc_benchmark.c     |  133 ++
 drivers/gpu/drm/loongson/lsdc_benchmark.h     |   13 +
 drivers/gpu/drm/loongson/lsdc_crtc.c          | 1066 +++++++++++++++++
 drivers/gpu/drm/loongson/lsdc_debugfs.c       |   91 ++
 drivers/gpu/drm/loongson/lsdc_device.c        |  104 ++
 drivers/gpu/drm/loongson/lsdc_drv.c           |  495 ++++++++
 drivers/gpu/drm/loongson/lsdc_drv.h           |  451 +++++++
 drivers/gpu/drm/loongson/lsdc_gem.c           |  324 +++++
 drivers/gpu/drm/loongson/lsdc_gem.h           |   37 +
 drivers/gpu/drm/loongson/lsdc_gfxpll.c        |  199 +++
 drivers/gpu/drm/loongson/lsdc_gfxpll.h        |   52 +
 drivers/gpu/drm/loongson/lsdc_i2c.c           |  179 +++
 drivers/gpu/drm/loongson/lsdc_i2c.h           |   29 +
 drivers/gpu/drm/loongson/lsdc_irq.c           |   71 ++
 drivers/gpu/drm/loongson/lsdc_irq.h           |   16 +
 drivers/gpu/drm/loongson/lsdc_output.h        |   21 +
 drivers/gpu/drm/loongson/lsdc_output_7a1000.c |  161 +++
 drivers/gpu/drm/loongson/lsdc_output_7a2000.c |  531 ++++++++
 drivers/gpu/drm/loongson/lsdc_pixpll.c        |  481 ++++++++
 drivers/gpu/drm/loongson/lsdc_pixpll.h        |   86 ++
 drivers/gpu/drm/loongson/lsdc_plane.c         |  781 ++++++++++++
 drivers/gpu/drm/loongson/lsdc_probe.c         |   56 +
 drivers/gpu/drm/loongson/lsdc_probe.h         |   12 +
 drivers/gpu/drm/loongson/lsdc_regs.h          |  402 +++++++
 drivers/gpu/drm/loongson/lsdc_ttm.c           |  610 ++++++++++
 drivers/gpu/drm/loongson/lsdc_ttm.h           |   99 ++
 31 files changed, 6548 insertions(+)
 create mode 100644 drivers/gpu/drm/loongson/Kconfig
 create mode 100644 drivers/gpu/drm/loongson/Makefile
 create mode 100644 drivers/gpu/drm/loongson/lsdc_benchmark.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_benchmark.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_crtc.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_debugfs.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_device.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_drv.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_drv.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_gem.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_gem.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_gfxpll.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_gfxpll.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_i2c.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_i2c.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_irq.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_irq.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_output.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_output_7a1000.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_output_7a2000.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_pixpll.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_pixpll.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_plane.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_probe.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_probe.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_regs.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_ttm.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_ttm.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v14 1/2 drm: add kms driver for loongson display controller

From: Sui Jingfeng <[email protected]>

Loongson display controller IP has been integrated in both Loongson north bridge chipset(ls7a1000/ls7a2000) and Loongson SoCs(ls2k1000/ls2k2000), it has been even included in Loongson self-made BMC products.

This display controller is a PCI device. It has two display pipes and each display pipe support a primary plane and a cursor plane. For the DC in the ls7a1000 and ls2k1000, each display pipe has a DVO output interface which provide RGB888 signals, vertical & horizontal synchronisations and pixel clock. Each CRTC is able to support 1920x1080@60Hz, the maximum resolution of each display pipe is 2048x2048 according to the hardware spec.

For the DC in LS7A2000, each display pipe is equipped with a built-in HDMI encoder which is compliant with the HDMI 1.4 specification, thus it support 3840x2160@30Hz. The first display pipe is also equipped with a transparent vga encoder which is parallel with the HDMI encoder. The DC in LS7A2000 is more complete compare with the one in old chips, besides above feature, it has two hardware cursors, two hardware vblank counter and two scanout position recorders unit. It also support tiled framebuffer format which can be scanout the tiled framebuffer rendered by the LoongGPU directly.

v1 -> v2:
1) Use hpd status reg when polling for ls7a2000
2) Fix all warnings emerged when compile with W=1

v2 -> v3:
1) Add COMPILE_TEST in Kconfig and make the driver off by default
2) Alphabetical sorting headers (Thomas)
3) Untangle register access functions as much as possible (Thomas)
4) Switch to TTM based memory manager and prefer cached mapping for Loongson SoC (Thomas)
5) Add chip id detection method, now all models are distinguishable.
6) Revise builtin HDMI phy driver, nearly all main stream mode below 4K@30Hz is tested, this driver supported these mode very well including clone display mode and extend display mode.

v3 -> v4:
1) Quickly fix a small mistake.

v4 -> v5:
1) Drop potential support for Loongson 2K series SoC temporary, this part should be resend with the DT binding patch in the future.
2) Add per display pipe debugfs support to the builtin HDMI encoder.
3) Rewrite atomic_update() for hardware cursors plane(Thomas)
4) Rewrite encoder and connector initialization part, untangle it according to the chip(Thomas).

v5 -> v6:
1) Remove stray code which didn't get used, say lsdc_of_get_reserved_ram
2) Fix all typos I could found, make sentences and code more readable
3) Untangle lsdc_hdmi*_connector_detect() function according to the pipe
4) After a serious consideration, we rename this driver as loongson. Because we also have drivers toward the LoongGPU IP in LS7A2000 and LS2K2000. Besides, there are also drivers about the external encoder, HDMI audio driver and vbios support etc. This patch only provide DC driver part, my teammate Li Yi believe that loongson will be more suitable for loongson graphics than lsdc in the long run.

loongson.ko = LSDC + LoongGPU + encoders driver + vbios/DT ...

v6 -> v7:
1) Add prime support, self-sharing is works. sharing buffer with etnaviv is also tested, and its works with limitation.
2) Implement buffer objects tracking with list_head.
3) S3(sleep to RAM) is tested on ls3a5000+ls7a2000 evb and it works.
4) Rewrite lsdc_bo_move, since ttm core stop allocating resources during BO creation. Patch V1 ~ V6 of this series no longer works on latest kernel. Thus, we send V7 to revival them.

v7 -> v8:
1) Zero a compile warnnings on 32-bit platform, compile with W=1
2) Revise lsdc_bo_gpu_offset() and minor cleanup
3) Pageflip tested on the virtual terminal with following commands

    modetest -M loongson -s 32:1920x1080 -v
    modetest -M loongson -s 34:1920x1080 -v -F tiles

It works like a charm, when running pageflip test with dual screnn configuration, another two additional bo created by the modetest emerged, VRAM usage up to 40+MB, well we have at least 64MB, still enough.

   # cat bos
       bo[0000]: size:     8112kB VRAM
       bo[0001]: size:       16kB VRAM
       bo[0002]: size:       16kB VRAM
       bo[0003]: size:    16208kB VRAM
       bo[0004]: size:     8112kB VRAM
       bo[0005]: size:     8112kB VRAM

v8 -> v9:
1) Select I2C and I2C_ALGOBIT in Kconfig and should depend on MMU.
2) Using pci_get_domain_bus_and_slot to get the GPU device.
3) Other minor improvements.

Those patches are tested on ls3a5000 + ls7a1000 CRB, ls3a5000 + ls7a2000 evb, and lemote a1901 board(ls3a4000 + ls7a1000). On loongson mips CPU, the write combine support should be enabled, to get a decent performance for writing framebuffer data to the VRAM.

v9 -> v10:
1) Revise lsdc_drm_freeze() to implement S3 completely and correctly. I suddenly realized that pinned buffer can not move and VRAM lost power when sleep to RAM. Thus, the data in the buffer who is pinned in VRAM will get lost when resume. Yet it's not big problem because we are software rendering solution which relay on the CPU update the front framebuffer. We can see the garbage data when resume from S3, but the screen will show correct image as I move the cursor. This is due to the cpu repaint. v10 of this patch make S3 perfect by unpin all of BOs in VRAM, evict them all to system RAM.

v10 -> v11:
1) On double screen case, the single giant framebuffer is referenced by two GEM object, hence, it will be pinned by prepare_fb() at lease two times. This cause its pin count > 1. V10 of this patch only unpin VRAM BOs once when suspend, which is not correct on double screen case. V11 of this patch unpin BOs until its pin count reach to zero when suspend. Then, we make the S3 support complete finally. With v11, I can't see any garbage data after resume. Tested on both ls7a1000 and ls7a2000 platform, with single screen and double screen configuration.
2) Fix vblank wait timeout when disable CRTC.
3) Test against IGT, at least fbdev test and kms_flip test passed.
4) Rewrite pixel PLL update function, magic numbers eliminated (Emil)
5) Drop a few common hardware features description in lsdc_desc (Emil)
6) Drop lsdc_mode_config_mode_valid(), instead add restrictions in dumb create function. (Emil)
7) Untangle the ls7a1000 case and ls7a2000 case completely (Thomas)

v11 -> v12:
none

v12 -> v13:
1) Add benchmark to figure out the bandwidth of the hardware platform. Usage:
# cd /sys/kernel/debug/dri/0/
# cat benchmark

2) VRAM is filled with garbage data if uninitialized, add a buffer clearing procedure, clear it on the BO creation time.
3) Update copyrights and adjust coding style (Huacai)

v13 -> v14:
1) Trying to add async update support for cursor plane.

Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sumit Semwal <[email protected]>
Cc "Christian König" <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Javier Martinez Canillas <[email protected]>
---
 drivers/gpu/drm/Kconfig                       |    2 +
 drivers/gpu/drm/Makefile                      |    1 +
 drivers/gpu/drm/loongson/Kconfig              |   17 +
 drivers/gpu/drm/loongson/Makefile             |   20 +
 drivers/gpu/drm/loongson/lsdc_benchmark.c     |  133 ++
 drivers/gpu/drm/loongson/lsdc_benchmark.h     |   13 +
 drivers/gpu/drm/loongson/lsdc_crtc.c          | 1066 +++++++++++++++++
 drivers/gpu/drm/loongson/lsdc_debugfs.c       |   91 ++
 drivers/gpu/drm/loongson/lsdc_device.c        |  104 ++
 drivers/gpu/drm/loongson/lsdc_drv.c           |  495 ++++++++
 drivers/gpu/drm/loongson/lsdc_drv.h           |  451 +++++++
 drivers/gpu/drm/loongson/lsdc_gem.c           |  324 +++++
 drivers/gpu/drm/loongson/lsdc_gem.h           |   37 +
 drivers/gpu/drm/loongson/lsdc_gfxpll.c        |  199 +++
 drivers/gpu/drm/loongson/lsdc_gfxpll.h        |   52 +
 drivers/gpu/drm/loongson/lsdc_i2c.c           |  179 +++
 drivers/gpu/drm/loongson/lsdc_i2c.h           |   29 +
 drivers/gpu/drm/loongson/lsdc_irq.c           |   71 ++
 drivers/gpu/drm/loongson/lsdc_irq.h           |   16 +
 drivers/gpu/drm/loongson/lsdc_output.h        |   21 +
 drivers/gpu/drm/loongson/lsdc_output_7a1000.c |  161 +++
 drivers/gpu/drm/loongson/lsdc_output_7a2000.c |  531 ++++++++
 drivers/gpu/drm/loongson/lsdc_pixpll.c        |  481 ++++++++
 drivers/gpu/drm/loongson/lsdc_pixpll.h        |   86 ++
 drivers/gpu/drm/loongson/lsdc_plane.c         |  781 ++++++++++++
 drivers/gpu/drm/loongson/lsdc_probe.c         |   56 +
 drivers/gpu/drm/loongson/lsdc_probe.h         |   12 +
 drivers/gpu/drm/loongson/lsdc_regs.h          |  402 +++++++
 drivers/gpu/drm/loongson/lsdc_ttm.c           |  610 ++++++++++
 drivers/gpu/drm/loongson/lsdc_ttm.h           |   99 ++
 30 files changed, 6540 insertions(+)
 create mode 100644 drivers/gpu/drm/loongson/Kconfig
 create mode 100644 drivers/gpu/drm/loongson/Makefile
 create mode 100644 drivers/gpu/drm/loongson/lsdc_benchmark.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_benchmark.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_crtc.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_debugfs.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_device.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_drv.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_drv.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_gem.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_gem.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_gfxpll.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_gfxpll.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_i2c.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_i2c.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_irq.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_irq.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_output.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_output_7a1000.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_output_7a2000.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_pixpll.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_pixpll.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_plane.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_probe.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_probe.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_regs.h
 create mode 100644 drivers/gpu/drm/loongson/lsdc_ttm.c
 create mode 100644 drivers/gpu/drm/loongson/lsdc_ttm.h
drivers/gpu/drm/Kconfig +2 -0
index ba3fb04bb691..d1fa87d2acb7 100644
@@ -331,6 +331,8 @@ source "drivers/gpu/drm/v3d/Kconfig"
 
 source "drivers/gpu/drm/vc4/Kconfig"
 
+source "drivers/gpu/drm/loongson/Kconfig"
+
 source "drivers/gpu/drm/etnaviv/Kconfig"
 
 source "drivers/gpu/drm/hisilicon/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index a33257d2bc7f..131531453b8e 100644
@@ -194,3 +194,4 @@ obj-y			+= gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
 obj-y			+= solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
+obj-$(CONFIG_DRM_LOONGSON) += loongson/
drivers/gpu/drm/loongson/Kconfig new file +17 -0
new file mode 100644
index 000000000000..df6946d505fa
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_LOONGSON
+	tristate "DRM support for Loongson Graphics"
+	depends on DRM && PCI && MMU
+	select DRM_KMS_HELPER
+	select DRM_TTM
+	select I2C
+	select I2C_ALGOBIT
+	help
+	  This is a DRM driver for Loongson Graphics, it may including
+	  LS7A2000, LS7A1000, LS2K2000 and LS2K1000 etc. Loongson LS7A
+	  series are bridge chipset, while Loongson LS2K series are SoC.
+
+	  If "M" is selected, the module will be called loongson.
+
+	  If in doubt, say "N".
drivers/gpu/drm/loongson/Makefile new file +20 -0
new file mode 100644
index 000000000000..9158816ece8e
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0
+
+loongson-y := \
+	lsdc_benchmark.o \
+	lsdc_crtc.o \
+	lsdc_debugfs.o \
+	lsdc_device.o \
+	lsdc_drv.o \
+	lsdc_gem.o \
+	lsdc_gfxpll.o \
+	lsdc_i2c.o \
+	lsdc_irq.o \
+	lsdc_output_7a1000.o \
+	lsdc_output_7a2000.o \
+	lsdc_plane.o \
+	lsdc_pixpll.o \
+	lsdc_probe.o \
+	lsdc_ttm.o
+
+obj-$(CONFIG_DRM_LOONGSON) += loongson.o
drivers/gpu/drm/loongson/lsdc_benchmark.c new file +133 -0

133 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_benchmark.h new file +13 -0
new file mode 100644
index 000000000000..2bf9406eae9c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef __LSDC_BENCHMARK_H__
+#define __LSDC_BENCHMARK_H__
+
+#include "lsdc_drv.h"
+
+int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct drm_printer *p);
+
+#endif
drivers/gpu/drm/loongson/lsdc_crtc.c new file +1066 -0

1,066 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_debugfs.c new file +91 -0

91 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_device.c new file +104 -0

104 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_drv.c new file +495 -0

495 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_drv.h new file +451 -0

451 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_gem.c new file +324 -0

324 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_gem.h new file +37 -0
new file mode 100644
index 000000000000..7e05e453b733
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef __LSDC_GEM_H__
+#define __LSDC_GEM_H__
+
+#include <drm/drm_device.h>
+#include <drm/drm_gem.h>
+
+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);
+
+int lsdc_dumb_create(struct drm_file *file,
+		     struct drm_device *ddev,
+		     struct drm_mode_create_dumb *args);
+
+void lsdc_gem_init(struct drm_device *ddev);
+int lsdc_show_buffer_object(struct seq_file *m, void *arg);
+
+struct drm_gem_object *
+lsdc_gem_object_create(struct drm_device *ddev,
+		       u32 domain,
+		       size_t size,
+		       bool kerenl,
+		       struct sg_table *sg,
+		       struct dma_resv *resv);
+
+#endif
drivers/gpu/drm/loongson/lsdc_gfxpll.c new file +199 -0

199 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_gfxpll.h new file +52 -0

38 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_i2c.c new file +179 -0

179 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_i2c.h new file +29 -0
new file mode 100644
index 000000000000..c3dadc2c423d

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

drivers/gpu/drm/loongson/lsdc_irq.c new file +71 -0

71 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_irq.h new file +16 -0
new file mode 100644
index 000000000000..c7003461051e

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

drivers/gpu/drm/loongson/lsdc_output.h new file +21 -0
new file mode 100644
index 000000000000..e3c375298568

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

drivers/gpu/drm/loongson/lsdc_output_7a1000.c new file +161 -0

161 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_output_7a2000.c new file +531 -0

531 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_pixpll.c new file +481 -0

481 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_pixpll.h new file +86 -0

86 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_plane.c new file +781 -0

781 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_probe.c new file +56 -0

56 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_probe.h new file +12 -0
new file mode 100644
index 000000000000..7a96bec49ab9

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

drivers/gpu/drm/loongson/lsdc_regs.h new file +402 -0

402 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_ttm.c new file +610 -0

610 lines not on this page · raw message

drivers/gpu/drm/loongson/lsdc_ttm.h new file +99 -0

99 lines not on this page · raw message

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

Signature · 1 line
2.25.1

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

#2 lore raw

Hi,

Someone else in a discussion group brought my attention to this series, that I've neglected for a long time because [email protected] isn't on the Cc list and I'm not subscribed to dri-devel.

While I'm reasonably familiar with LoongArch internals and Linux in general, I don't regularly tinker with the graphics things, so I'm mainly focusing on the natural language usage and general code smells for my reviews below. Pardon me if some of the questions seem silly.

(After going through the entirety of this: *please* spell-check your comment blocks, and correct obvious grammatical nits as best as you can. From my first impression, although a reader not familiar with LoongArch nor Chinese could go a long way in understanding this, some of the rest would be misunderstood, or don't make sense at all. And like 90% of the sentences are grammatically incorrect, i.e. are obvious "Chinglish". Maybe something like those ChatGPT-based services or someone in your company would help.)

Also, publicly available documentation and references to them would be hugely beneficial. For now we have to trust your description here (that's very pictorial and pretty complete with explanations, by the way, and thanks for that), but it could be even better to provide more citations like "According to Section xx.xx of Loongson 7A1000 User Manual v1.0. I don't know how people usually handle the "pre-release hardware without docs yet" situation in drm side, though; we should adhere to the conventions if my understanding is not aligning with it.

And finally, thanks for your patience all along.

Quoted 8 lines · Sui Jingfeng

From: Sui Jingfeng <[email protected]>

Loongson display controller IP has been integrated in both Loongson north bridge chipset(ls7a1000/ls7a2000) and Loongson SoCs(ls2k1000/ls2k2000), it has been even included in Loongson self-made BMC products.

This display controller is a PCI device. It has two display pipes and each display pipe support a primary plane and a cursor plane. For the DC in the

"supports"

Quoted 2 lines

ls7a1000 and ls2k1000, each display pipe has a DVO output interface which provide RGB888 signals, vertical & horizontal synchronisations and pixel

"synchronisation"

Quoted 1 line

clock. Each CRTC is able to support 1920x1080@60Hz, the maximum resolution

"is capable of" sounds more natural?

Quoted 4 lines

of each display pipe is 2048x2048 according to the hardware spec.

For the DC in LS7A2000, each display pipe is equipped with a built-in HDMI encoder which is compliant with the HDMI 1.4 specification, thus it support

"supporting up to 3840x2160@30Hz"

Quoted 2 lines

3840x2160@30Hz. The first display pipe is also equipped with a transparent vga encoder which is parallel with the HDMI encoder. The DC in LS7A2000 is

"The first display pipe additionally has a transparent VGA encoder"?

Quoted 4 lines

more complete compare with the one in old chips, besides above feature, it has two hardware cursors, two hardware vblank counter and two scanout position recorders unit. It also support tiled framebuffer format which can be scanout the tiled framebuffer rendered by the LoongGPU directly.

"The DC in LS7A2000 is more feature-complete compared with the older revision: in addition to the above, it also has two hardware cursors, two hardware vblank counters and two scanout position recorders. It also supports tiled framebuffer format so the tiled output from the LoongGPU can be scanned out directly."

Quoted 229 lines

v1 -> v2:
1) Use hpd status reg when polling for ls7a2000
2) Fix all warnings emerged when compile with W=1

v2 -> v3:
1) Add COMPILE_TEST in Kconfig and make the driver off by default
2) Alphabetical sorting headers (Thomas)
3) Untangle register access functions as much as possible (Thomas)
4) Switch to TTM based memory manager and prefer cached mapping for Loongson SoC (Thomas)
5) Add chip id detection method, now all models are distinguishable.
6) Revise builtin HDMI phy driver, nearly all main stream mode below 4K@30Hz is tested, this driver supported these mode very well including clone display mode and extend display mode.

v3 -> v4:
1) Quickly fix a small mistake.

v4 -> v5:
1) Drop potential support for Loongson 2K series SoC temporary, this part should be resend with the DT binding patch in the future.
2) Add per display pipe debugfs support to the builtin HDMI encoder.
3) Rewrite atomic_update() for hardware cursors plane(Thomas)
4) Rewrite encoder and connector initialization part, untangle it according to the chip(Thomas).

v5 -> v6:
1) Remove stray code which didn't get used, say lsdc_of_get_reserved_ram
2) Fix all typos I could found, make sentences and code more readable
3) Untangle lsdc_hdmi*_connector_detect() function according to the pipe
4) After a serious consideration, we rename this driver as loongson. Because we also have drivers toward the LoongGPU IP in LS7A2000 and LS2K2000. Besides, there are also drivers about the external encoder, HDMI audio driver and vbios support etc. This patch only provide DC driver part, my teammate Li Yi believe that loongson will be more suitable for loongson graphics than lsdc in the long run.

loongson.ko = LSDC + LoongGPU + encoders driver + vbios/DT ...

v6 -> v7:
1) Add prime support, self-sharing is works. sharing buffer with etnaviv is also tested, and its works with limitation.
2) Implement buffer objects tracking with list_head.
3) S3(sleep to RAM) is tested on ls3a5000+ls7a2000 evb and it works.
4) Rewrite lsdc_bo_move, since ttm core stop allocating resources during BO creation. Patch V1 ~ V6 of this series no longer works on latest kernel. Thus, we send V7 to revival them.

v7 -> v8:
1) Zero a compile warnnings on 32-bit platform, compile with W=1
2) Revise lsdc_bo_gpu_offset() and minor cleanup
3) Pageflip tested on the virtual terminal with following commands

     modetest -M loongson -s 32:1920x1080 -v
     modetest -M loongson -s 34:1920x1080 -v -F tiles

    It works like a charm, when running pageflip test with dual screnn
    configuration, another two additional bo created by the modetest
    emerged, VRAM usage up to 40+MB, well we have at least 64MB, still
    enough.

    # cat bos

        bo[0000]: size:     8112kB VRAM
        bo[0001]: size:       16kB VRAM
        bo[0002]: size:       16kB VRAM
        bo[0003]: size:    16208kB VRAM
        bo[0004]: size:     8112kB VRAM
        bo[0005]: size:     8112kB VRAM

v8 -> v9:
1) Select I2C and I2C_ALGOBIT in Kconfig and should depend on MMU.
2) Using pci_get_domain_bus_and_slot to get the GPU device.
3) Other minor improvements.

Those patches are tested on ls3a5000 + ls7a1000 CRB, ls3a5000 + ls7a2000 evb, and lemote a1901 board(ls3a4000 + ls7a1000). On loongson mips CPU, the write combine support should be enabled, to get a decent performance for writing framebuffer data to the VRAM.

v9 -> v10:
1) Revise lsdc_drm_freeze() to implement S3 completely and correctly. I suddenly realized that pinned buffer can not move and VRAM lost power when sleep to RAM. Thus, the data in the buffer who is pinned in VRAM will get lost when resume. Yet it's not big problem because we are software rendering solution which relay on the CPU update the front framebuffer. We can see the garbage data when resume from S3, but the screen will show correct image as I move the cursor. This is due to the cpu repaint. v10 of this patch make S3 perfect by unpin all of BOs in VRAM, evict them all to system RAM.

v10 -> v11:
1) On double screen case, the single giant framebuffer is referenced by two GEM object, hence, it will be pinned by prepare_fb() at lease two times. This cause its pin count > 1. V10 of this patch only unpin VRAM BOs once when suspend, which is not correct on double screen case. V11 of this patch unpin BOs until its pin count reach to zero when suspend. Then, we make the S3 support complete finally. With v11, I can't see any garbage data after resume. Tested on both ls7a1000 and ls7a2000 platform, with single screen and double screen configuration.
2) Fix vblank wait timeout when disable CRTC.
3) Test against IGT, at least fbdev test and kms_flip test passed.
4) Rewrite pixel PLL update function, magic numbers eliminated (Emil)
5) Drop a few common hardware features description in lsdc_desc (Emil)
6) Drop lsdc_mode_config_mode_valid(), instead add restrictions in dumb create function. (Emil)
7) Untangle the ls7a1000 case and ls7a2000 case completely (Thomas)

v11 -> v12:
none

v12 -> v13:
1) Add benchmark to figure out the bandwidth of the hardware platform. Usage:
# cd /sys/kernel/debug/dri/0/
# cat benchmark

2) VRAM is filled with garbage data if uninitialized, add a buffer clearing procedure, clear it on the BO creation time.
3) Update copyrights and adjust coding style (Huacai)

v13 -> v14:
1) Trying to add async update support for cursor plane.

Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sumit Semwal <[email protected]>
Cc "Christian König" <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Javier Martinez Canillas <[email protected]>
---
  drivers/gpu/drm/Kconfig                       |    2 +
  drivers/gpu/drm/Makefile                      |    1 +
  drivers/gpu/drm/loongson/Kconfig              |   17 +
  drivers/gpu/drm/loongson/Makefile             |   20 +
  drivers/gpu/drm/loongson/lsdc_benchmark.c     |  133 ++
  drivers/gpu/drm/loongson/lsdc_benchmark.h     |   13 +
  drivers/gpu/drm/loongson/lsdc_crtc.c          | 1066 +++++++++++++++++
  drivers/gpu/drm/loongson/lsdc_debugfs.c       |   91 ++
  drivers/gpu/drm/loongson/lsdc_device.c        |  104 ++
  drivers/gpu/drm/loongson/lsdc_drv.c           |  495 ++++++++
  drivers/gpu/drm/loongson/lsdc_drv.h           |  451 +++++++
  drivers/gpu/drm/loongson/lsdc_gem.c           |  324 +++++
  drivers/gpu/drm/loongson/lsdc_gem.h           |   37 +
  drivers/gpu/drm/loongson/lsdc_gfxpll.c        |  199 +++
  drivers/gpu/drm/loongson/lsdc_gfxpll.h        |   52 +
  drivers/gpu/drm/loongson/lsdc_i2c.c           |  179 +++
  drivers/gpu/drm/loongson/lsdc_i2c.h           |   29 +
  drivers/gpu/drm/loongson/lsdc_irq.c           |   71 ++
  drivers/gpu/drm/loongson/lsdc_irq.h           |   16 +
  drivers/gpu/drm/loongson/lsdc_output.h        |   21 +
  drivers/gpu/drm/loongson/lsdc_output_7a1000.c |  161 +++
  drivers/gpu/drm/loongson/lsdc_output_7a2000.c |  531 ++++++++
  drivers/gpu/drm/loongson/lsdc_pixpll.c        |  481 ++++++++
  drivers/gpu/drm/loongson/lsdc_pixpll.h        |   86 ++
  drivers/gpu/drm/loongson/lsdc_plane.c         |  781 ++++++++++++
  drivers/gpu/drm/loongson/lsdc_probe.c         |   56 +
  drivers/gpu/drm/loongson/lsdc_probe.h         |   12 +
  drivers/gpu/drm/loongson/lsdc_regs.h          |  402 +++++++
  drivers/gpu/drm/loongson/lsdc_ttm.c           |  610 ++++++++++
  drivers/gpu/drm/loongson/lsdc_ttm.h           |   99 ++
  30 files changed, 6540 insertions(+)

create mode 100644 drivers/gpu/drm/loongson/Kconfig create mode 100644 drivers/gpu/drm/loongson/Makefile create mode 100644 drivers/gpu/drm/loongson/lsdc_benchmark.c create mode 100644 drivers/gpu/drm/loongson/lsdc_benchmark.h create mode 100644 drivers/gpu/drm/loongson/lsdc_crtc.c create mode 100644 drivers/gpu/drm/loongson/lsdc_debugfs.c create mode 100644 drivers/gpu/drm/loongson/lsdc_device.c create mode 100644 drivers/gpu/drm/loongson/lsdc_drv.c create mode 100644 drivers/gpu/drm/loongson/lsdc_drv.h create mode 100644 drivers/gpu/drm/loongson/lsdc_gem.c create mode 100644 drivers/gpu/drm/loongson/lsdc_gem.h create mode 100644 drivers/gpu/drm/loongson/lsdc_gfxpll.c create mode 100644 drivers/gpu/drm/loongson/lsdc_gfxpll.h create mode 100644 drivers/gpu/drm/loongson/lsdc_i2c.c create mode 100644 drivers/gpu/drm/loongson/lsdc_i2c.h create mode 100644 drivers/gpu/drm/loongson/lsdc_irq.c create mode 100644 drivers/gpu/drm/loongson/lsdc_irq.h create mode 100644 drivers/gpu/drm/loongson/lsdc_output.h create mode 100644 drivers/gpu/drm/loongson/lsdc_output_7a1000.c create mode 100644 drivers/gpu/drm/loongson/lsdc_output_7a2000.c create mode 100644 drivers/gpu/drm/loongson/lsdc_pixpll.c create mode 100644 drivers/gpu/drm/loongson/lsdc_pixpll.h create mode 100644 drivers/gpu/drm/loongson/lsdc_plane.c create mode 100644 drivers/gpu/drm/loongson/lsdc_probe.c create mode 100644 drivers/gpu/drm/loongson/lsdc_probe.h create mode 100644 drivers/gpu/drm/loongson/lsdc_regs.h create mode 100644 drivers/gpu/drm/loongson/lsdc_ttm.c create mode 100644 drivers/gpu/drm/loongson/lsdc_ttm.h

drivers/gpu/drm/Kconfig +2 -0
index ba3fb04bb691..d1fa87d2acb7 100644
@@ -331,6 +331,8 @@ source "drivers/gpu/drm/v3d/Kconfig"
 
  source "drivers/gpu/drm/vc4/Kconfig"
 
+source "drivers/gpu/drm/loongson/Kconfig"
+
  source "drivers/gpu/drm/etnaviv/Kconfig"
 
  source "drivers/gpu/drm/hisilicon/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index a33257d2bc7f..131531453b8e 100644
@@ -194,3 +194,4 @@ obj-y			+= gud/
  obj-$(CONFIG_DRM_HYPERV) += hyperv/
  obj-y			+= solomon/
  obj-$(CONFIG_DRM_SPRD) += sprd/
+obj-$(CONFIG_DRM_LOONGSON) += loongson/
drivers/gpu/drm/loongson/Kconfig new file +1 -0
new file mode 100644
index 000000000000..df6946d505fa
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0

drivers/gpu/drm/loongson/Kconfig line 11

Quoted 10 lines
drivers/gpu/drm/loongson/Kconfig new file +10 -0
+
+config DRM_LOONGSON
+	tristate "DRM support for Loongson Graphics"
+	depends on DRM && PCI && MMU
+	select DRM_KMS_HELPER
+	select DRM_TTM
+	select I2C
+	select I2C_ALGOBIT
+	help
+	  This is a DRM driver for Loongson Graphics, it may including

Drop "it may"; "including" should be enough.

drivers/gpu/drm/loongson/Kconfig line 15

Quoted 4 lines
drivers/gpu/drm/loongson/Kconfig new file +4 -0
+	  LS7A2000, LS7A1000, LS2K2000 and LS2K1000 etc. Loongson LS7A
+	  series are bridge chipset, while Loongson LS2K series are SoC.
+
+	  If "M" is selected, the module will be called loongson.

Just "loongson"? I know it's like this for ages (at least dating back to the MIPS days) but you really don't want to imply Loongson is mainly a GPU company. Something like "loongson_drm" or "lsdc" or "gsgpu" could be better.

Quoted 34 lines
drivers/gpu/drm/loongson/Kconfig new file +2 -0
+
+	  If in doubt, say "N".
drivers/gpu/drm/loongson/Makefile new file +20 -0
new file mode 100644
index 000000000000..9158816ece8e
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0
+
+loongson-y := \
+	lsdc_benchmark.o \
+	lsdc_crtc.o \
+	lsdc_debugfs.o \
+	lsdc_device.o \
+	lsdc_drv.o \
+	lsdc_gem.o \
+	lsdc_gfxpll.o \
+	lsdc_i2c.o \
+	lsdc_irq.o \
+	lsdc_output_7a1000.o \
+	lsdc_output_7a2000.o \
+	lsdc_plane.o \
+	lsdc_pixpll.o \
+	lsdc_probe.o \
+	lsdc_ttm.o
+
+obj-$(CONFIG_DRM_LOONGSON) += loongson.o
drivers/gpu/drm/loongson/lsdc_benchmark.c new file +0 -0
new file mode 100644
index 000000000000..82961531d84c

drivers/gpu/drm/loongson/lsdc_benchmark.c line 1

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_benchmark.c new file +1 -0
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0+

Is it GPL-2.0, GPL-2.0-only, or GPL-2.0+? Please make sure all license IDs are consistent.

Quoted 214 lines
drivers/gpu/drm/loongson/lsdc_benchmark.c new file +132 -0
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <drm/drm_debugfs.h>
+
+#include "lsdc_benchmark.h"
+#include "lsdc_drv.h"
+#include "lsdc_gem.h"
+#include "lsdc_ttm.h"
+
+typedef void (*lsdc_copy_proc_t)(struct lsdc_bo *src_bo,
+				 struct lsdc_bo *dst_bo,
+				 unsigned int size,
+				 int n);
+
+static void lsdc_copy_gtt_to_vram_cpu(struct lsdc_bo *src_bo,
+				      struct lsdc_bo *dst_bo,
+				      unsigned int size,
+				      int n)
+{
+	lsdc_bo_kmap(src_bo);
+	lsdc_bo_kmap(dst_bo);
+
+	while (n--)
+		memcpy_toio(dst_bo->kptr, src_bo->kptr, size);
+
+	lsdc_bo_kunmap(src_bo);
+	lsdc_bo_kunmap(dst_bo);
+}
+
+static void lsdc_copy_vram_to_gtt_cpu(struct lsdc_bo *src_bo,
+				      struct lsdc_bo *dst_bo,
+				      unsigned int size,
+				      int n)
+{
+	lsdc_bo_kmap(src_bo);
+	lsdc_bo_kmap(dst_bo);
+
+	while (n--)
+		memcpy_fromio(dst_bo->kptr, src_bo->kptr, size);
+
+	lsdc_bo_kunmap(src_bo);
+	lsdc_bo_kunmap(dst_bo);
+}
+
+static void lsdc_copy_gtt_to_gtt_cpu(struct lsdc_bo *src_bo,
+				     struct lsdc_bo *dst_bo,
+				     unsigned int size,
+				     int n)
+{
+	lsdc_bo_kmap(src_bo);
+	lsdc_bo_kmap(dst_bo);
+
+	while (n--)
+		memcpy(dst_bo->kptr, src_bo->kptr, size);
+
+	lsdc_bo_kunmap(src_bo);
+	lsdc_bo_kunmap(dst_bo);
+}
+
+static void lsdc_benchmark_copy(struct lsdc_device *ldev,
+				unsigned int size,
+				unsigned int n,
+				u32 src_domain,
+				u32 dst_domain,
+				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;
+	unsigned long end_jiffies;
+	unsigned int throughput;
+	unsigned int time;
+
+	src_bo = lsdc_bo_create_kernel_pinned(ddev, src_domain, size);
+	dst_bo = lsdc_bo_create_kernel_pinned(ddev, dst_domain, size);
+
+	start_jiffies = jiffies;
+
+	copy_proc(src_bo, dst_bo, size, n);
+
+	end_jiffies = jiffies;
+
+	lsdc_bo_free_kernel_pinned(src_bo);
+	lsdc_bo_free_kernel_pinned(dst_bo);
+
+	time = jiffies_to_msecs(end_jiffies - start_jiffies);
+
+	throughput = (n * (size >> 10)) / time;
+
+	drm_printf(p,
+		   "Copy bo of %ukB %u times from %s to %s in %ums: %uMB/s\n",
+		   size >> 10, n,
+		   lsdc_domain_to_str(src_domain),
+		   lsdc_domain_to_str(dst_domain),
+		   time, throughput);
+}
+
+int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct drm_printer *p)
+{
+	unsigned int buffer_size = 1920 * 1080 * 4;
+	unsigned int iteration = 60;
+
+	lsdc_benchmark_copy(ldev,
+			    buffer_size,
+			    iteration,
+			    LSDC_GEM_DOMAIN_GTT,
+			    LSDC_GEM_DOMAIN_GTT,
+			    lsdc_copy_gtt_to_gtt_cpu,
+			    p);
+
+	lsdc_benchmark_copy(ldev,
+			    buffer_size,
+			    iteration,
+			    LSDC_GEM_DOMAIN_GTT,
+			    LSDC_GEM_DOMAIN_VRAM,
+			    lsdc_copy_gtt_to_vram_cpu,
+			    p);
+
+	lsdc_benchmark_copy(ldev,
+			    buffer_size,
+			    iteration,
+			    LSDC_GEM_DOMAIN_VRAM,
+			    LSDC_GEM_DOMAIN_GTT,
+			    lsdc_copy_vram_to_gtt_cpu,
+			    p);
+
+	return 0;
+}
drivers/gpu/drm/loongson/lsdc_benchmark.h new file +13 -0
new file mode 100644
index 000000000000..2bf9406eae9c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef __LSDC_BENCHMARK_H__
+#define __LSDC_BENCHMARK_H__
+
+#include "lsdc_drv.h"
+
+int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct drm_printer *p);
+
+#endif
drivers/gpu/drm/loongson/lsdc_crtc.c new file +57 -0
new file mode 100644
index 000000000000..de2c1d514baa
@@ -0,0 +1,1066 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <linux/delay.h>
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_debugfs.h>
+#include <drm/drm_vblank.h>
+
+#include "lsdc_drv.h"
+
+/*
+ * The soft reset cause the vblank counter reset to zero, but the address
+ * and other settings in the crtc register remains.
+ */
+
+static void lsdc_crtc0_soft_reset(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	u32 val;
+
+	val = lsdc_rreg32(ldev, LSDC_CRTC0_CFG_REG);
+
+	val &= CFG_VALID_BITS_MASK;
+
+	/* soft reset bit, active low */
+	val &= ~CFG_RESET_N;
+
+	val &= ~CFG_PIX_FMT_MASK;
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val);
+
+	udelay(5);
+
+	val |= CFG_RESET_N | LSDC_PF_XRGB8888 | CFG_OUTPUT_ENABLE;
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val);
+
+	mdelay(20);
+}
+
+static void lsdc_crtc1_soft_reset(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	u32 val;
+
+	val = lsdc_rreg32(ldev, LSDC_CRTC1_CFG_REG);
+
+	val &= CFG_VALID_BITS_MASK;
+
+	/* soft reset bit, active low */
+	val &= ~CFG_RESET_N;
+
+	val &= ~CFG_PIX_FMT_MASK;

drivers/gpu/drm/loongson/lsdc_crtc.c line 67

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val);
+
+	udelay(5);
+
+	val |= CFG_RESET_N | LSDC_PF_XRGB8888 | CFG_OUTPUT_ENABLE;
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val);
+
+	msleep(20);

So many magic sleeps without documentation?

drivers/gpu/drm/loongson/lsdc_crtc.c line 78

Quoted 11 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +11 -0
+}
+
+static void lsdc_crtc0_enable(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	u32 val;
+
+	val = lsdc_rreg32(ldev, LSDC_CRTC0_CFG_REG);
+
+	/*
+	 * This may happens on extremely rare case, luckily, a soft reset

"may happen on extremely rare cases;"

drivers/gpu/drm/loongson/lsdc_crtc.c line 79

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_crtc.c new file +1 -0
+	 * can helps to bring it back to normal. We add a warn here, hope

"can help bringing it back to normal. We issue a warning here, hoping to"

Quoted 20 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +20 -0
+	 * to catch something if it happens.
+	 */
+
+	if (val & CRTC_ANCHORED) {
+		drm_warn(&ldev->base, "%s anchored\n", lcrtc->base.name);
+		return lsdc_crtc0_soft_reset(lcrtc);
+	}
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val | CFG_OUTPUT_ENABLE);
+}
+
+static void lsdc_crtc0_disable(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_clr(ldev, LSDC_CRTC0_CFG_REG, CFG_OUTPUT_ENABLE);
+
+	udelay(9);
+}
+

drivers/gpu/drm/loongson/lsdc_crtc.c line 109

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+static void lsdc_crtc1_enable(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	u32 val;
+
+	val = lsdc_rreg32(ldev, LSDC_CRTC1_CFG_REG);
+	if (val & CRTC_ANCHORED) {
+		drm_warn(&ldev->base, "%s anchored\n", lcrtc->base.name);
+		return lsdc_crtc1_soft_reset(lcrtc);
+	}

Duplication of code? You may want to duplicate the comment here too as de-duplication with macro seems too heavy here.

Quoted 4 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +4 -0
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val | CFG_OUTPUT_ENABLE);
+}
+

drivers/gpu/drm/loongson/lsdc_crtc.c line 123

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+static void lsdc_crtc1_disable(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_clr(ldev, LSDC_CRTC1_CFG_REG, CFG_OUTPUT_ENABLE);
+
+	udelay(9);
+}
+
+/* All loongson display controller support scanout position hardware */

Commit message implies only 7A2000+ LSDC IPs have the "scanout position recorders". Either that part or this code would need tweaking...

Quoted 57 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +57 -0
+
+static void lsdc_crtc0_scan_pos(struct lsdc_crtc *lcrtc, int *hpos, int *vpos)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	u32 val;
+
+	val = lsdc_rreg32(ldev, LSDC_CRTC0_SCAN_POS_REG);
+
+	*hpos = val >> 16;
+	*vpos = val & 0xffff;
+}
+
+static void lsdc_crtc1_scan_pos(struct lsdc_crtc *lcrtc, int *hpos, int *vpos)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	u32 val;
+
+	val = lsdc_rreg32(ldev, LSDC_CRTC1_SCAN_POS_REG);
+
+	*hpos = val >> 16;
+	*vpos = val & 0xffff;
+}
+
+static void lsdc_crtc0_enable_vblank(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_set(ldev, LSDC_INT_REG, INT_CRTC0_VSYNC_EN);
+}
+
+static void lsdc_crtc0_disable_vblank(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_clr(ldev, LSDC_INT_REG, INT_CRTC0_VSYNC_EN);
+}
+
+static void lsdc_crtc1_enable_vblank(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_set(ldev, LSDC_INT_REG, INT_CRTC1_VSYNC_EN);
+}
+
+static void lsdc_crtc1_disable_vblank(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_clr(ldev, LSDC_INT_REG, INT_CRTC1_VSYNC_EN);
+}
+
+static void lsdc_crtc0_flip(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_set(ldev, LSDC_CRTC0_CFG_REG, CFG_PAGE_FLIP);
+}

drivers/gpu/drm/loongson/lsdc_crtc.c line 190

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+
+static void lsdc_crtc1_flip(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_set(ldev, LSDC_CRTC1_CFG_REG, CFG_PAGE_FLIP);
+}
+
+/*
+ * CRTC0 clone from CRTC1 or CRTC1 clone from CRTC0 using hardware logic.

"Hardware-assisted cloning between CRTCs"?

drivers/gpu/drm/loongson/lsdc_crtc.c line 191

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_crtc.c new file +1 -0
+ * Hardware engineer say this would help to saving bandwidth on clone mode.

"Hardware engineers say this would help save bandwidth in clone mode"

drivers/gpu/drm/loongson/lsdc_crtc.c line 193

Quoted 2 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +2 -0
+ *
+ * This may useful on custom clone application.

"This may be useful for custom applications of clone mode"?

Quoted 46 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +46 -0
+ */
+
+static void lsdc_crtc0_clone(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_set(ldev, LSDC_CRTC0_CFG_REG, CFG_HW_CLONE);
+}
+
+static void lsdc_crtc1_clone(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_ureg32_set(ldev, LSDC_CRTC1_CFG_REG, CFG_HW_CLONE);
+}
+
+static void lsdc_crtc0_set_mode(struct lsdc_crtc *lcrtc,
+				const struct drm_display_mode *mode)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_HDISPLAY_REG,
+		    (mode->crtc_htotal << 16) | mode->crtc_hdisplay);
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_VDISPLAY_REG,
+		    (mode->crtc_vtotal << 16) | mode->crtc_vdisplay);
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_HSYNC_REG,
+		    (mode->crtc_hsync_end << 16) | mode->crtc_hsync_start | HSYNC_EN);
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_VSYNC_REG,
+		    (mode->crtc_vsync_end << 16) | mode->crtc_vsync_start | VSYNC_EN);
+}
+
+static void lsdc_crtc1_set_mode(struct lsdc_crtc *lcrtc,
+				const struct drm_display_mode *mode)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_HDISPLAY_REG,
+		    (mode->crtc_htotal << 16) | mode->crtc_hdisplay);
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_VDISPLAY_REG,
+		    (mode->crtc_vtotal << 16) | mode->crtc_vdisplay);
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_HSYNC_REG,

drivers/gpu/drm/loongson/lsdc_crtc.c line 249

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+		    (mode->crtc_hsync_end << 16) | mode->crtc_hsync_start | HSYNC_EN);
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_VSYNC_REG,
+		    (mode->crtc_vsync_end << 16) | mode->crtc_vsync_start | VSYNC_EN);
+}
+
+/*
+ * This is required for S3 support.
+ *
+ * After resume from suspend, LSDC_CRTCx_CFG_REG (x=0 or 1)is filled with

"resuming", "are filled"

drivers/gpu/drm/loongson/lsdc_crtc.c line 250

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_crtc.c new file +1 -0
+ * garbarge value which may cause the CRTC completely hang. This function

"to completely hang"

drivers/gpu/drm/loongson/lsdc_crtc.c line 251

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_crtc.c new file +1 -0
+ * give a minimal setting to the affected registers. This also override

"minimally resets the affected registers"

drivers/gpu/drm/loongson/lsdc_crtc.c line 252

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_crtc.c new file +1 -0
+ * the firmware's setting on startup, eliminate potential blinding setting.

"This also overrides the boot-time setting by the firmware, eliminating potentially blinding settings"?

drivers/gpu/drm/loongson/lsdc_crtc.c line 254

Quoted 2 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +2 -0
+ *
+ * Making the CRTC works on our own now, this is similar with the functional

What do you mean by "work on our own"? Do you mean re-initializing the CRTC without firmware help?

drivers/gpu/drm/loongson/lsdc_crtc.c line 267

Quoted 13 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +13 -0
+ * of GPU POST(Power On Self Test). Only touch CRTC hardware related part.
+ */
+
+static void lsdc_crtc0_reset(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	struct drm_crtc *crtc = &lcrtc->base;
+	u32 val;
+
+	val = lsdc_rreg32(ldev, LSDC_CRTC0_CFG_REG);
+
+	/* This help to see what is it */
+	drm_dbg(&ldev->base, "value of %s configure register: %x\n",

"config register" should be enough?

drivers/gpu/drm/loongson/lsdc_crtc.c line 279

Quoted 12 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +12 -0
+		crtc->name, val);
+
+	/*
+	 * Help the CRTC get out of soft reset sate, as the CRTC is completely
+	 * halt on soft reset mode (BIT(20) = 0). It does not event generate
+	 * vblank, cause vblank wait timeout. This happends when resume from
+	 * S3.
+	 *
+	 * Also give a sane format, after resume from suspend S3, this
+	 * register is filled with garbarge value. A meaningless value may
+	 * also cause the CRTC halt or stall.
+	 */

This block of comment is mostly a duplication of the function's doc comment above; I'd suggest removing this block.

Quoted 5 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +5 -0
+
+	val = CFG_RESET_N | LSDC_PF_XRGB8888;
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val);
+}

drivers/gpu/drm/loongson/lsdc_crtc.c line 294

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+
+static void lsdc_crtc1_reset(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	struct drm_crtc *crtc = &lcrtc->base;
+	u32 val;
+
+	val = lsdc_rreg32(ldev, LSDC_CRTC1_CFG_REG);
+
+	drm_dbg(&ldev->base, "value of %s configue register: %x\n",

"config"

Quoted 31 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +31 -0
+		crtc->name, val);
+
+	/*
+	 * Help the CRTC get out of soft reset sate, give a sane format,
+	 * Otherwise it will halt or stall there.
+	 */
+	val = CFG_RESET_N | LSDC_PF_XRGB8888;
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val);
+}
+
+static const struct lsdc_crtc_hw_ops ls7a1000_crtc_hw_ops[2] = {
+	{
+		.enable = lsdc_crtc0_enable,
+		.disable = lsdc_crtc0_disable,
+		.enable_vblank = lsdc_crtc0_enable_vblank,
+		.disable_vblank = lsdc_crtc0_disable_vblank,
+		.flip = lsdc_crtc0_flip,
+		.clone = lsdc_crtc0_clone,
+		.set_mode = lsdc_crtc0_set_mode,
+		.get_scan_pos = lsdc_crtc0_scan_pos,
+		.soft_reset = lsdc_crtc0_soft_reset,
+		.reset = lsdc_crtc0_reset,
+	},
+	{
+		.enable = lsdc_crtc1_enable,
+		.disable = lsdc_crtc1_disable,
+		.enable_vblank = lsdc_crtc1_enable_vblank,
+		.disable_vblank = lsdc_crtc1_disable_vblank,
+		.flip = lsdc_crtc1_flip,
+		.clone = lsdc_crtc1_clone,

drivers/gpu/drm/loongson/lsdc_crtc.c line 335

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+		.set_mode = lsdc_crtc1_set_mode,
+		.get_scan_pos = lsdc_crtc1_scan_pos,
+		.soft_reset = lsdc_crtc1_soft_reset,
+		.reset = lsdc_crtc1_reset,
+	},
+};
+
+/*
+ * The 32-bit hardware vblank counter is available since ls7a2000/ls2k2000,
+ * The counter grow up even the CRTC is being disabled, it will got reset

"The counters increase even when the CRTC is disabled, and will be reset if the crtc is soft-reset"

I don't think you're describing the transient behavior when the CRTC is *being* disabled / soft-reset, i.e. *in the middle of* disabling/soft-resetting, hence I've fixed the tenses for you.

Also please change all mentions of lowercase "ls7a2000" or "ls2k2000" in comments to consistent uppercase equivalents; it's easier for human eyes that way.

drivers/gpu/drm/loongson/lsdc_crtc.c line 339

Quoted 4 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +4 -0
+ * if the crtc is being soft reset.
+ *
+ * Those registers are also readable for ls7a1000, but its value does not
+ * change.

"but the values cannot be changed"

Quoted 9 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +9 -0
+ */
+
+static u32 lsdc_crtc0_get_vblank_count(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	return lsdc_rreg32(ldev, LSDC_CRTC0_VSYNC_COUNTER_REG);
+}
+

drivers/gpu/drm/loongson/lsdc_crtc.c line 358

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+static u32 lsdc_crtc1_get_vblank_count(struct lsdc_crtc *lcrtc)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+
+	return lsdc_rreg32(ldev, LSDC_CRTC1_VSYNC_COUNTER_REG);
+}
+
+/*
+ * The DMA step bit field is available since ls7a2000/ls2k2000, for support
+ * odd resolutions. But a large DMA step may save bandwidth. Behavior of

"for supporting"; "a larger"

drivers/gpu/drm/loongson/lsdc_crtc.c line 359

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_crtc.c new file +1 -0
+ * writing thoes bits field on ls7a1000/ls2k1000 is underfined.

"those bitfields"; "undefined"

Quoted 66 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +66 -0
+ */
+
+static void lsdc_crtc0_set_dma_step(struct lsdc_crtc *lcrtc,
+				    enum lsdc_dma_steps dma_step)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	u32 val = lsdc_rreg32(ldev, LSDC_CRTC0_CFG_REG);
+
+	val &= ~CFG_DMA_STEP_MASK;
+	val |= dma_step << CFG_DMA_STEP_SHIFT;
+
+	lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val);
+}
+
+static void lsdc_crtc1_set_dma_step(struct lsdc_crtc *lcrtc,
+				    enum lsdc_dma_steps dma_step)
+{
+	struct lsdc_device *ldev = lcrtc->ldev;
+	u32 val = lsdc_rreg32(ldev, LSDC_CRTC1_CFG_REG);
+
+	val &= ~CFG_DMA_STEP_MASK;
+	val |= dma_step << CFG_DMA_STEP_SHIFT;
+
+	lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val);
+}
+
+static const struct lsdc_crtc_hw_ops ls7a2000_crtc_hw_ops[2] = {
+	{
+		.enable = lsdc_crtc0_enable,
+		.disable = lsdc_crtc0_disable,
+		.enable_vblank = lsdc_crtc0_enable_vblank,
+		.disable_vblank = lsdc_crtc0_disable_vblank,
+		.flip = lsdc_crtc0_flip,
+		.clone = lsdc_crtc0_clone,
+		.set_mode = lsdc_crtc0_set_mode,
+		.soft_reset = lsdc_crtc0_soft_reset,
+		.get_scan_pos = lsdc_crtc0_scan_pos,
+		.set_dma_step = lsdc_crtc0_set_dma_step,
+		.get_vblank_counter = lsdc_crtc0_get_vblank_count,
+		.reset = lsdc_crtc0_reset,
+	},
+	{
+		.enable = lsdc_crtc1_enable,
+		.disable = lsdc_crtc1_disable,
+		.enable_vblank = lsdc_crtc1_enable_vblank,
+		.disable_vblank = lsdc_crtc1_disable_vblank,
+		.flip = lsdc_crtc1_flip,
+		.clone = lsdc_crtc1_clone,
+		.set_mode = lsdc_crtc1_set_mode,
+		.get_scan_pos = lsdc_crtc1_scan_pos,
+		.soft_reset = lsdc_crtc1_soft_reset,
+		.set_dma_step = lsdc_crtc1_set_dma_step,
+		.get_vblank_counter = lsdc_crtc1_get_vblank_count,
+		.reset = lsdc_crtc1_reset,
+	},
+};
+
+static void lsdc_crtc_reset(struct drm_crtc *crtc)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+	struct lsdc_crtc_state *priv_crtc_state;
+
+	if (crtc->state)
+		crtc->funcs->atomic_destroy_state(crtc, crtc->state);
+

drivers/gpu/drm/loongson/lsdc_crtc.c line 435

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+	priv_crtc_state = kzalloc(sizeof(*priv_crtc_state), GFP_KERNEL);
+
+	if (!priv_crtc_state)
+		__drm_atomic_helper_crtc_reset(crtc, NULL);
+	else
+		__drm_atomic_helper_crtc_reset(crtc, &priv_crtc_state->base);
+
+	/*
+	 * Reset the crtc hardware, this is need for S3 support,
+	 * otherwise, wait for vblank timeout may happen.

"Reset the crtc hardware which is needed for S3, otherwise vblank timeout may happen"?

Quoted 54 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +54 -0
+	 */
+	ops->reset(lcrtc);
+}
+
+static void lsdc_crtc_atomic_destroy_state(struct drm_crtc *crtc,
+					   struct drm_crtc_state *state)
+{
+	struct lsdc_crtc_state *priv_state = to_lsdc_crtc_state(state);
+
+	__drm_atomic_helper_crtc_destroy_state(&priv_state->base);
+
+	kfree(priv_state);
+}
+
+static struct drm_crtc_state *
+lsdc_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+	struct lsdc_crtc_state *new_priv_state;
+	struct lsdc_crtc_state *old_priv_state;
+
+	new_priv_state = kzalloc(sizeof(*new_priv_state), GFP_KERNEL);
+	if (!new_priv_state)
+		return NULL;
+
+	__drm_atomic_helper_crtc_duplicate_state(crtc, &new_priv_state->base);
+
+	old_priv_state = to_lsdc_crtc_state(crtc->state);
+
+	memcpy(&new_priv_state->pparms, &old_priv_state->pparms,
+	       sizeof(new_priv_state->pparms));
+
+	return &new_priv_state->base;
+}
+
+static u32 lsdc_crtc_get_vblank_counter(struct drm_crtc *crtc)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+
+	return ops->get_vblank_counter(lcrtc);
+}
+
+static int lsdc_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+
+	ops->enable_vblank(lcrtc);
+
+	return 0;
+}
+
+static void lsdc_crtc_disable_vblank(struct drm_crtc *crtc)
+{

drivers/gpu/drm/loongson/lsdc_crtc.c line 499

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+
+	ops->disable_vblank(lcrtc);
+}
+
+/*
+ * CRTC related debugfs
+ *
+ * Primary planes and cursor planes are also belong to the CRTC for our case,

"also belong to the CRTC in our cases"

drivers/gpu/drm/loongson/lsdc_crtc.c line 500

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_crtc.c new file +1 -0
+ * so also append other registers to here, for sake of convenient.

"so the other registers are also appended here for convenience"

Quoted 233 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +233 -0
+ */
+
+#define REG_DEF(reg) { \
+	.name = __stringify_1(LSDC_##reg##_REG), \
+	.offset = LSDC_##reg##_REG, \
+}
+
+static const struct lsdc_reg32 lsdc_crtc_regs_array[2][21] = {
+	[0] = {
+		REG_DEF(CRTC0_CFG),
+		REG_DEF(CRTC0_FB_ORIGIN),
+		REG_DEF(CRTC0_PANEL_CONF),
+		REG_DEF(CRTC0_HDISPLAY),
+		REG_DEF(CRTC0_HSYNC),
+		REG_DEF(CRTC0_VDISPLAY),
+		REG_DEF(CRTC0_VSYNC),
+		REG_DEF(CRTC0_GAMMA_INDEX),
+		REG_DEF(CRTC0_GAMMA_DATA),
+		REG_DEF(CRTC0_SYNC_DEVIATION),
+		REG_DEF(CRTC0_VSYNC_COUNTER),
+		REG_DEF(CRTC0_SCAN_POS),
+		REG_DEF(CRTC0_STRIDE),
+		REG_DEF(CRTC0_FB1_ADDR_HI),
+		REG_DEF(CRTC0_FB1_ADDR_LO),
+		REG_DEF(CRTC0_FB0_ADDR_HI),
+		REG_DEF(CRTC0_FB0_ADDR_LO),
+		REG_DEF(CURSOR0_CFG),
+		REG_DEF(CURSOR0_POSITION),
+		REG_DEF(CURSOR0_BG_COLOR),
+		REG_DEF(CURSOR0_FG_COLOR),
+	},
+	[1] = {
+		REG_DEF(CRTC1_CFG),
+		REG_DEF(CRTC1_FB_ORIGIN),
+		REG_DEF(CRTC1_PANEL_CONF),
+		REG_DEF(CRTC1_HDISPLAY),
+		REG_DEF(CRTC1_HSYNC),
+		REG_DEF(CRTC1_VDISPLAY),
+		REG_DEF(CRTC1_VSYNC),
+		REG_DEF(CRTC1_GAMMA_INDEX),
+		REG_DEF(CRTC1_GAMMA_DATA),
+		REG_DEF(CRTC1_SYNC_DEVIATION),
+		REG_DEF(CRTC1_VSYNC_COUNTER),
+		REG_DEF(CRTC1_SCAN_POS),
+		REG_DEF(CRTC1_STRIDE),
+		REG_DEF(CRTC1_FB1_ADDR_HI),
+		REG_DEF(CRTC1_FB1_ADDR_LO),
+		REG_DEF(CRTC1_FB0_ADDR_HI),
+		REG_DEF(CRTC1_FB0_ADDR_LO),
+		REG_DEF(CURSOR1_CFG),
+		REG_DEF(CURSOR1_POSITION),
+		REG_DEF(CURSOR1_BG_COLOR),
+		REG_DEF(CURSOR1_FG_COLOR),
+	},
+};
+
+static int lsdc_crtc_show_regs(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct lsdc_crtc *lcrtc = (struct lsdc_crtc *)node->info_ent->data;
+	struct lsdc_device *ldev = lcrtc->ldev;
+	unsigned int i;
+
+	for (i = 0; i < lcrtc->nreg; i++) {
+		const struct lsdc_reg32 *preg = &lcrtc->preg[i];
+		u32 offset = preg->offset;
+
+		seq_printf(m, "%s (0x%04x): 0x%08x\n",
+			   preg->name, offset, lsdc_rreg32(ldev, offset));
+	}
+
+	return 0;
+}
+
+static int lsdc_crtc_show_scan_position(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct lsdc_crtc *lcrtc = (struct lsdc_crtc *)node->info_ent->data;
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+	int x, y;
+
+	ops->get_scan_pos(lcrtc, &x, &y);
+
+	seq_printf(m, "scanout position: x: %08u, y: %08u\n", x, y);
+
+	return 0;
+}
+
+static int lsdc_crtc_show_vblank_counter(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct lsdc_crtc *lcrtc = (struct lsdc_crtc *)node->info_ent->data;
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+
+	if (ops->get_vblank_counter)
+		seq_printf(m, "%s vblank counter: %08u\n\n",
+			   lcrtc->base.name,
+			   ops->get_vblank_counter(lcrtc));
+
+	return 0;
+}
+
+static int lsdc_pixpll_show_clock(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct lsdc_crtc *lcrtc = (struct lsdc_crtc *)node->info_ent->data;
+	struct lsdc_pixpll *pixpll = &lcrtc->pixpll;
+	const struct lsdc_pixpll_funcs *funcs = pixpll->funcs;
+	struct drm_crtc *crtc = &lcrtc->base;
+	struct drm_display_mode *mode = &crtc->state->mode;
+	struct drm_printer printer = drm_seq_file_printer(m);
+	unsigned int out_khz;
+
+	out_khz = funcs->get_rate(pixpll);
+
+	seq_printf(m, "%s: %dx%d@%d\n", crtc->name,
+		   mode->hdisplay, mode->vdisplay, drm_mode_vrefresh(mode));
+
+	seq_printf(m, "Pixel clock required: %d kHz\n", mode->clock);
+	seq_printf(m, "Actual frequency output: %u kHz\n", out_khz);
+	seq_printf(m, "Diff: %d kHz\n", out_khz - mode->clock);
+
+	funcs->print(pixpll, &printer);
+
+	return 0;
+}
+
+static struct drm_info_list lsdc_crtc_debugfs_list[2][4] = {
+	[0] = {
+		{ "regs", lsdc_crtc_show_regs, 0, NULL },
+		{ "pixclk", lsdc_pixpll_show_clock, 0, NULL },
+		{ "scanpos", lsdc_crtc_show_scan_position, 0, NULL },
+		{ "vblanks", lsdc_crtc_show_vblank_counter, 0, NULL },
+	},
+	[1] = {
+		{ "regs", lsdc_crtc_show_regs, 0, NULL },
+		{ "pixclk", lsdc_pixpll_show_clock, 0, NULL },
+		{ "scanpos", lsdc_crtc_show_scan_position, 0, NULL },
+		{ "vblanks", lsdc_crtc_show_vblank_counter, 0, NULL },
+	},
+};
+
+/* operate manually */
+
+static int lsdc_crtc_man_op_show(struct seq_file *m, void *data)
+{
+	seq_puts(m, "soft_reset: soft reset this CRTC\n");
+	seq_puts(m, "enable: enable this CRTC\n");
+	seq_puts(m, "disable: disable this CRTC\n");
+	seq_puts(m, "flip: trigger the page flip\n");
+	seq_puts(m, "clone: clone the another crtc with hardware logic\n");
+
+	return 0;
+}
+
+static int lsdc_crtc_man_op_open(struct inode *inode, struct file *file)
+{
+	struct drm_crtc *crtc = inode->i_private;
+
+	return single_open(file, lsdc_crtc_man_op_show, crtc);
+}
+
+static ssize_t lsdc_crtc_man_op_write(struct file *file,
+				      const char __user *ubuf,
+				      size_t len,
+				      loff_t *offp)
+{
+	struct seq_file *m = file->private_data;
+	struct lsdc_crtc *lcrtc = m->private;
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+
+	char buf[16];
+
+	if (len > sizeof(buf) - 1)
+		return -EINVAL;
+
+	if (copy_from_user(buf, ubuf, len))
+		return -EFAULT;
+
+	buf[len] = '\0';
+
+	if (sysfs_streq(buf, "soft_reset"))
+		ops->soft_reset(lcrtc);
+	else if (sysfs_streq(buf, "enable"))
+		ops->enable(lcrtc);
+	else if (sysfs_streq(buf, "disable"))
+		ops->disable(lcrtc);
+	else if (sysfs_streq(buf, "flip"))
+		ops->flip(lcrtc);
+	else if (sysfs_streq(buf, "clone"))
+		ops->clone(lcrtc);
+
+	return len;
+}
+
+static const struct file_operations lsdc_crtc_man_op_fops = {
+	.owner = THIS_MODULE,
+	.open = lsdc_crtc_man_op_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+	.write = lsdc_crtc_man_op_write,
+};
+
+static int lsdc_crtc_late_register(struct drm_crtc *crtc)
+{
+	struct lsdc_display_pipe *dispipe = crtc_to_display_pipe(crtc);
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	struct drm_minor *minor = crtc->dev->primary;
+	unsigned int index = dispipe->index;
+	unsigned int i;
+
+	lcrtc->preg = lsdc_crtc_regs_array[index];
+	lcrtc->nreg = ARRAY_SIZE(lsdc_crtc_regs_array[index]);
+	lcrtc->p_info_list = lsdc_crtc_debugfs_list[index];
+	lcrtc->n_info_list = ARRAY_SIZE(lsdc_crtc_debugfs_list[index]);
+
+	for (i = 0; i < lcrtc->n_info_list; ++i)
+		lcrtc->p_info_list[i].data = lcrtc;
+
+	drm_debugfs_create_files(lcrtc->p_info_list,
+				 lcrtc->n_info_list,
+				 crtc->debugfs_entry,
+				 minor);
+
+	/* supported manual operations */
+	debugfs_create_file("ops", 0644, crtc->debugfs_entry, lcrtc,
+			    &lsdc_crtc_man_op_fops);
+
+	return 0;
+}
+
+static void lsdc_crtc_atomic_print_state(struct drm_printer *p,

drivers/gpu/drm/loongson/lsdc_crtc.c line 743

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+					 const struct drm_crtc_state *state)
+{
+	const struct lsdc_crtc_state *priv_state;
+	const struct lsdc_pixpll_parms *pparms;
+
+	priv_state = container_of_const(state, struct lsdc_crtc_state, base);
+	pparms = &priv_state->pparms;
+
+	drm_printf(p, "\tInput clock divider = %u\n", pparms->div_ref);
+	drm_printf(p, "\tMedium clock Multiplier = %u\n", pparms->loopc);

"multiplier" for consistent casing

Quoted 47 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +47 -0
+	drm_printf(p, "\tOutput clock divider = %u\n", pparms->div_out);
+}
+
+static const struct drm_crtc_funcs ls7a1000_crtc_funcs = {
+	.reset = lsdc_crtc_reset,
+	.destroy = drm_crtc_cleanup,
+	.set_config = drm_atomic_helper_set_config,
+	.page_flip = drm_atomic_helper_page_flip,
+	.atomic_duplicate_state = lsdc_crtc_atomic_duplicate_state,
+	.atomic_destroy_state = lsdc_crtc_atomic_destroy_state,
+	.late_register = lsdc_crtc_late_register,
+	.enable_vblank = lsdc_crtc_enable_vblank,
+	.disable_vblank = lsdc_crtc_disable_vblank,
+	.get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp,
+	.atomic_print_state = lsdc_crtc_atomic_print_state,
+};
+
+static const struct drm_crtc_funcs ls7a2000_crtc_funcs = {
+	.reset = lsdc_crtc_reset,
+	.destroy = drm_crtc_cleanup,
+	.set_config = drm_atomic_helper_set_config,
+	.page_flip = drm_atomic_helper_page_flip,
+	.atomic_duplicate_state = lsdc_crtc_atomic_duplicate_state,
+	.atomic_destroy_state = lsdc_crtc_atomic_destroy_state,
+	.late_register = lsdc_crtc_late_register,
+	.get_vblank_counter = lsdc_crtc_get_vblank_counter,
+	.enable_vblank = lsdc_crtc_enable_vblank,
+	.disable_vblank = lsdc_crtc_disable_vblank,
+	.get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp,
+	.atomic_print_state = lsdc_crtc_atomic_print_state,
+};
+
+static enum drm_mode_status
+lsdc_crtc_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode)
+{
+	struct drm_device *ddev = crtc->dev;
+	struct lsdc_device *ldev = to_lsdc(ddev);
+	const struct lsdc_desc *descp = ldev->descp;
+	unsigned int pitch;
+
+	if (mode->hdisplay > descp->max_width)
+		return MODE_BAD_HVALUE;
+
+	if (mode->vdisplay > descp->max_height)
+		return MODE_BAD_VVALUE;
+
+	if (mode->clock > descp->max_pixel_clk) {

drivers/gpu/drm/loongson/lsdc_crtc.c line 800

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+		drm_dbg_kms(ddev, "mode %dx%d, pixel clock=%d is too high\n",
+			    mode->hdisplay, mode->vdisplay, mode->clock);
+		return MODE_CLOCK_HIGH;
+	}
+
+	/* 4 for DRM_FORMAT_XRGB8888 */
+	pitch = mode->hdisplay * 4;
+
+	if (pitch % descp->pitch_align) {
+		drm_dbg_kms(ddev, "aligned to %u bytes is required: %u\n",

"alignment of %u bytes"

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+			    descp->pitch_align, pitch);
+		return MODE_BAD_WIDTH;
+	}
+
+	return MODE_OK;
+}
+
+static int lsdc_pixpll_atomic_check(struct drm_crtc *crtc,
+				    struct drm_crtc_state *state)
+{

drivers/gpu/drm/loongson/lsdc_crtc.c line 820

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	struct lsdc_pixpll *pixpll = &lcrtc->pixpll;
+	const struct lsdc_pixpll_funcs *pfuncs = pixpll->funcs;
+	struct lsdc_crtc_state *priv_state = to_lsdc_crtc_state(state);
+	unsigned int clock = state->mode.clock;
+	int ret;
+
+	ret = pfuncs->compute(pixpll, clock, &priv_state->pparms);
+	if (ret) {
+		drm_warn(crtc->dev, "find PLL parms for %ukHz failed\n", clock);

"failed to find PLL params for"

Quoted 25 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +25 -0
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int lsdc_crtc_helper_atomic_check(struct drm_crtc *crtc,
+					 struct drm_atomic_state *state)
+{
+	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+
+	if (!crtc_state->enable)
+		return 0;
+
+	return lsdc_pixpll_atomic_check(crtc, crtc_state);
+}
+
+static void lsdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	const struct lsdc_crtc_hw_ops *crtc_hw_ops = lcrtc->hw_ops;
+	struct lsdc_pixpll *pixpll = &lcrtc->pixpll;
+	const struct lsdc_pixpll_funcs *pixpll_funcs = pixpll->funcs;
+	struct drm_crtc_state *state = crtc->state;
+	struct drm_display_mode *mode = &state->mode;

drivers/gpu/drm/loongson/lsdc_crtc.c line 855

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+	struct lsdc_crtc_state *priv_state = to_lsdc_crtc_state(state);
+
+	pixpll_funcs->update(pixpll, &priv_state->pparms);
+
+	if (crtc_hw_ops->set_dma_step) {
+		unsigned int width_in_bytes = mode->hdisplay * 4;
+		enum lsdc_dma_steps dma_step;
+
+		/*
+		 * Using large dma step as much as possible, for improving

"Using DMA step as large as possible"

Quoted 16 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +16 -0
+		 * hardware DMA efficiency.
+		 */
+		if (width_in_bytes % 256 == 0)
+			dma_step = LSDC_DMA_STEP_256_BYTES;
+		else if (width_in_bytes % 128 == 0)
+			dma_step = LSDC_DMA_STEP_128_BYTES;
+		else if (width_in_bytes % 64 == 0)
+			dma_step = LSDC_DMA_STEP_64_BYTES;
+		else  /* width_in_bytes % 32 == 0 */
+			dma_step = LSDC_DMA_STEP_32_BYTES;
+
+		crtc_hw_ops->set_dma_step(lcrtc, dma_step);
+	}
+
+	crtc_hw_ops->set_mode(lcrtc, mode);
+}

drivers/gpu/drm/loongson/lsdc_crtc.c line 881

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+
+static void lsdc_crtc_send_vblank(struct drm_crtc *crtc)
+{
+	struct drm_device *ddev = crtc->dev;
+	unsigned long flags;
+
+	if (!crtc->state || !crtc->state->event)
+		return;
+
+	drm_dbg(ddev, "send vblank manually\n");

"manually sending vblank"

Quoted 6 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +6 -0
+
+	spin_lock_irqsave(&ddev->event_lock, flags);
+	drm_crtc_send_vblank_event(crtc, crtc->state->event);
+	crtc->state->event = NULL;
+	spin_unlock_irqrestore(&ddev->event_lock, flags);
+}

drivers/gpu/drm/loongson/lsdc_crtc.c line 897

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+
+static void lsdc_crtc_atomic_enable(struct drm_crtc *crtc,
+				    struct drm_atomic_state *state)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+
+	drm_crtc_vblank_on(crtc);
+
+	drm_dbg(crtc->dev, "%s enable\n", crtc->name);

"enabling %s\n"

Quoted 5 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +5 -0
+
+	ops->enable(lcrtc);
+}
+
+static void lsdc_crtc_atomic_disable(struct drm_crtc *crtc,

drivers/gpu/drm/loongson/lsdc_crtc.c line 912

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+				     struct drm_atomic_state *state)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+
+	drm_crtc_vblank_off(crtc);
+
+	ops->disable(lcrtc);
+
+	drm_dbg(crtc->dev, "%s disable\n", crtc->name);

"disabling %s\n"

drivers/gpu/drm/loongson/lsdc_crtc.c line 916

Quoted 4 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +4 -0
+
+	/*
+	 * Make sure we issue a vblank event after disabling the CRTC if
+	 * someone was waiting it.

"waiting for"

Quoted 71 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +71 -0
+	 */
+	lsdc_crtc_send_vblank(crtc);
+}
+
+static void lsdc_crtc_atomic_flush(struct drm_crtc *crtc,
+				   struct drm_atomic_state *state)
+{
+	spin_lock_irq(&crtc->dev->event_lock);
+	if (crtc->state->event) {
+		if (drm_crtc_vblank_get(crtc) == 0)
+			drm_crtc_arm_vblank_event(crtc, crtc->state->event);
+		else
+			drm_crtc_send_vblank_event(crtc, crtc->state->event);
+		crtc->state->event = NULL;
+	}
+	spin_unlock_irq(&crtc->dev->event_lock);
+}
+
+static bool lsdc_crtc_get_scanout_position(struct drm_crtc *crtc,
+					   bool in_vblank_irq,
+					   int *vpos,
+					   int *hpos,
+					   ktime_t *stime,
+					   ktime_t *etime,
+					   const struct drm_display_mode *mode)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	const struct lsdc_crtc_hw_ops *ops = lcrtc->hw_ops;
+	int vsw, vbp, vactive_start, vactive_end, vfp_end;
+	int x, y;
+
+	vsw = mode->crtc_vsync_end - mode->crtc_vsync_start;
+	vbp = mode->crtc_vtotal - mode->crtc_vsync_end;
+
+	vactive_start = vsw + vbp + 1;
+	vactive_end = vactive_start + mode->crtc_vdisplay;
+
+	/* last scan line before VSYNC */
+	vfp_end = mode->crtc_vtotal;
+
+	if (stime)
+		*stime = ktime_get();
+
+	ops->get_scan_pos(lcrtc, &x, &y);
+
+	if (y > vactive_end)
+		y = y - vfp_end - vactive_start;
+	else
+		y -= vactive_start;
+
+	*vpos = y;
+	*hpos = x;
+
+	if (etime)
+		*etime = ktime_get();
+
+	return true;
+}
+
+static const struct drm_crtc_helper_funcs lsdc_crtc_helper_funcs = {
+	.mode_valid = lsdc_crtc_mode_valid,
+	.mode_set_nofb = lsdc_crtc_mode_set_nofb,
+	.atomic_enable = lsdc_crtc_atomic_enable,
+	.atomic_disable = lsdc_crtc_atomic_disable,
+	.atomic_check = lsdc_crtc_helper_atomic_check,
+	.atomic_flush = lsdc_crtc_atomic_flush,
+	.get_scanout_position = lsdc_crtc_get_scanout_position,
+};
+
+int ls7a1000_crtc_init(struct drm_device *ddev,
+		       struct drm_crtc *crtc,

drivers/gpu/drm/loongson/lsdc_crtc.c line 997

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+		       struct drm_plane *primary,
+		       struct drm_plane *cursor,
+		       unsigned int index)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	int ret;
+
+	ret = lsdc_pixpll_init(&lcrtc->pixpll, ddev, index);
+	if (ret) {
+		drm_err(ddev, "crtc init with pll failed: %d\n", ret);

"crtc pll init failed"?

Quoted 91 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +69 -0
+		return ret;
+	}
+
+	lcrtc->ldev = to_lsdc(ddev);
+	lcrtc->hw_ops = &ls7a1000_crtc_hw_ops[index];
+
+	ret = drm_crtc_init_with_planes(ddev,
+					crtc,
+					primary,
+					cursor,
+					&ls7a1000_crtc_funcs,
+					"CRTC-%d",
+					index);
+	if (ret) {
+		drm_err(ddev, "crtc init with planes failed: %d\n", ret);
+		return ret;
+	}
+
+	drm_crtc_helper_add(crtc, &lsdc_crtc_helper_funcs);
+
+	ret = drm_mode_crtc_set_gamma_size(crtc, 256);
+	if (ret)
+		return ret;
+
+	drm_crtc_enable_color_mgmt(crtc, 0, false, 256);
+
+	return 0;
+}
+
+int ls7a2000_crtc_init(struct drm_device *ddev,
+		       struct drm_crtc *crtc,
+		       struct drm_plane *primary,
+		       struct drm_plane *cursor,
+		       unsigned int index)
+{
+	struct lsdc_crtc *lcrtc = to_lsdc_crtc(crtc);
+	int ret;
+
+	ret = lsdc_pixpll_init(&lcrtc->pixpll, ddev, index);
+	if (ret) {
+		drm_err(ddev, "crtc init with pll failed: %d\n", ret);
+		return ret;
+	}
+
+	lcrtc->ldev = to_lsdc(ddev);
+	lcrtc->hw_ops = &ls7a2000_crtc_hw_ops[index];
+
+	ret = drm_crtc_init_with_planes(ddev,
+					crtc,
+					primary,
+					cursor,
+					&ls7a2000_crtc_funcs,
+					"CRTC-%d",
+					index);
+	if (ret) {
+		drm_err(ddev, "crtc init with planes failed: %d\n", ret);
+		return ret;
+	}
+
+	drm_crtc_helper_add(crtc, &lsdc_crtc_helper_funcs);
+
+	ret = drm_mode_crtc_set_gamma_size(crtc, 256);
+	if (ret)
+		return ret;
+
+	drm_crtc_enable_color_mgmt(crtc, 0, false, 256);
+
+	return 0;
+}
drivers/gpu/drm/loongson/lsdc_debugfs.c new file +16 -0
new file mode 100644
index 000000000000..9ad2c5a0add2
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <drm/drm_debugfs.h>
+
+#include "lsdc_benchmark.h"
+#include "lsdc_drv.h"
+#include "lsdc_gem.h"
+#include "lsdc_probe.h"
+#include "lsdc_ttm.h"
+
+/* device level debugfs */
+
+static int lsdc_identify(struct seq_file *m, void *arg)

drivers/gpu/drm/loongson/lsdc_debugfs.c line 26

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_debugfs.c new file +10 -0
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
+	const struct loongson_gfx_desc *gfx = to_loongson_gfx(ldev->descp);
+	u8 impl, rev;
+
+	loongson_cpu_get_prid(&impl, &rev);
+
+	seq_printf(m, "Running on cpu 0x%x, cpu revision: 0x%x\n",
+		   impl, rev);

Is this really needed/relevant for LSDC identification? AFAICS the loongson_cpu_get_prid helper has only one use (that's here), so if it's not absolutely necessary you can just get rid of that function and lsdc_probe.h altogether.

drivers/gpu/drm/loongson/lsdc_debugfs.c line 28

Quoted 2 lines
drivers/gpu/drm/loongson/lsdc_debugfs.c new file +2 -0
+
+	seq_printf(m, "Contained in: %s\n", gfx->model);

"model: " would be more appropriate for a piece of info looking like a "gfx->model"?

Quoted 41 lines
drivers/gpu/drm/loongson/lsdc_debugfs.c new file +41 -0
+
+	return 0;
+}
+
+static int lsdc_show_mm(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct drm_device *ddev = node->minor->dev;
+	struct drm_printer p = drm_seq_file_printer(m);
+
+	drm_mm_print(&ddev->vma_offset_manager->vm_addr_space_mm, &p);
+
+	return 0;
+}
+
+static int lsdc_show_gfxpll_clock(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
+	struct drm_printer printer = drm_seq_file_printer(m);
+	struct loongson_gfxpll *gfxpll = ldev->gfxpll;
+
+	gfxpll->funcs->print(gfxpll, &printer, true);
+
+	return 0;
+}
+
+static int lsdc_show_benchmark(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct lsdc_device *ldev = (struct lsdc_device *)node->info_ent->data;
+	struct drm_printer printer = drm_seq_file_printer(m);
+
+	lsdc_show_benchmark_copy(ldev, &printer);
+
+	return 0;
+}
+
+static struct drm_info_list lsdc_debugfs_list[] = {
+	{ "chips",       lsdc_identify, 0, NULL },
+	{ "clocks",      lsdc_show_gfxpll_clock, 0, NULL },

drivers/gpu/drm/loongson/lsdc_debugfs.c line 79

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_debugfs.c new file +10 -0
+	{ "mm",          lsdc_show_mm, 0, NULL },
+	{ "bos",         lsdc_show_buffer_object, 0, NULL },
+	{ "benchmark",   lsdc_show_benchmark, 0, NULL },
+};
+
+void lsdc_debugfs_init(struct drm_minor *minor)
+{
+	struct drm_device *ddev = minor->dev;
+	struct lsdc_device *ldev = to_lsdc(ddev);
+	unsigned int N = ARRAY_SIZE(lsdc_debugfs_list);

"n" because it's not a macro definition?

Quoted 79 lines
drivers/gpu/drm/loongson/lsdc_debugfs.c new file +12 -0
+	unsigned int i;
+
+	for (i = 0; i < N; ++i)
+		lsdc_debugfs_list[i].data = ldev;
+
+	drm_debugfs_create_files(lsdc_debugfs_list,
+				 N,
+				 minor->debugfs_root,
+				 minor);
+
+	lsdc_ttm_debugfs_init(ldev);
+}
drivers/gpu/drm/loongson/lsdc_device.c new file +61 -0
new file mode 100644
index 000000000000..b4152f228beb
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <linux/pci.h>
+
+#include "lsdc_drv.h"
+
+static const struct lsdc_kms_funcs ls7a1000_kms_funcs = {
+	.create_i2c = lsdc_create_i2c_chan,
+	.irq_handler = ls7a1000_dc_irq_handler,
+	.output_init = ls7a1000_output_init,
+	.cursor_plane_init = ls7a1000_cursor_plane_init,
+	.primary_plane_init = lsdc_primary_plane_init,
+	.crtc_init = ls7a1000_crtc_init,
+};
+
+static const struct lsdc_kms_funcs ls7a2000_kms_funcs = {
+	.create_i2c = lsdc_create_i2c_chan,
+	.irq_handler = ls7a2000_dc_irq_handler,
+	.output_init = ls7a2000_output_init,
+	.cursor_plane_init = ls7a2000_cursor_plane_init,
+	.primary_plane_init = lsdc_primary_plane_init,
+	.crtc_init = ls7a2000_crtc_init,
+};
+
+static const struct loongson_gfx_desc ls7a1000_gfx = {
+	.dc = {
+		.num_of_crtc = 2,
+		.max_pixel_clk = 200000,
+		.max_width = 2048,
+		.max_height = 2048,
+		.num_of_hw_cursor = 1,
+		.hw_cursor_w = 32,
+		.hw_cursor_h = 32,
+		.pitch_align = 256,
+		.mc_bits = 40,
+		.has_vblank_counter = false,
+		.funcs = &ls7a1000_kms_funcs,
+	},
+	.conf_reg_base = LS7A1000_CONF_REG_BASE,
+	.gfxpll = {
+		.reg_offset = LS7A1000_PLL_GFX_REG,
+		.reg_size = 8,
+	},
+	.pixpll = {
+		[0] = {
+			.reg_offset = LS7A1000_PIXPLL0_REG,
+			.reg_size = 8,
+		},
+		[1] = {
+			.reg_offset = LS7A1000_PIXPLL1_REG,
+			.reg_size = 8,
+		},
+	},
+	.chip_id = CHIP_LS7A1000,
+	.model = "LS7A1000 bridge chipset",
+};
+
+static const struct loongson_gfx_desc ls7a2000_gfx = {

drivers/gpu/drm/loongson/lsdc_device.c line 71

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_device.c new file +10 -0
+	.dc = {
+		.num_of_crtc = 2,
+		.max_pixel_clk = 350000,
+		.max_width = 4096,
+		.max_height = 4096,
+		.num_of_hw_cursor = 2,
+		.hw_cursor_w = 64,
+		.hw_cursor_h = 64,
+		.pitch_align = 64,
+		.mc_bits = 40, /* Support 48 but using 40 for backward compatibility */

For compatibility with what?

Quoted 20 lines
drivers/gpu/drm/loongson/lsdc_device.c new file +20 -0
+		.has_vblank_counter = true,
+		.funcs = &ls7a2000_kms_funcs,
+	},
+	.conf_reg_base = LS7A2000_CONF_REG_BASE,
+	.gfxpll = {
+		.reg_offset = LS7A2000_PLL_GFX_REG,
+		.reg_size = 8,
+	},
+	.pixpll = {
+		[0] = {
+			.reg_offset = LS7A2000_PIXPLL0_REG,
+			.reg_size = 8,
+		},
+		[1] = {
+			.reg_offset = LS7A2000_PIXPLL1_REG,
+			.reg_size = 8,
+		},
+	},
+	.chip_id = CHIP_LS7A2000,
+	.model = "LS7A2000 bridge chipset",

drivers/gpu/drm/loongson/lsdc_device.c line 101

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_device.c new file +10 -0
+};
+
+const struct lsdc_desc *
+lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip_id)
+{
+	if (chip_id == CHIP_LS7A1000)
+		return &ls7a1000_gfx.dc;
+
+	if (chip_id == CHIP_LS7A2000)
+		return &ls7a2000_gfx.dc;

I suppose more are to be added later, so better use a switch statement here.

Quoted 29 lines
drivers/gpu/drm/loongson/lsdc_device.c new file +3 -0
+
+	return ERR_PTR(-ENODEV);
+}
drivers/gpu/drm/loongson/lsdc_drv.c new file +20 -0
new file mode 100644
index 000000000000..98e2c28f886f
@@ -0,0 +1,495 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <linux/pci.h>
+
+#include <video/nomodeset.h>
+
+#include <drm/drm_aperture.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_fbdev_generic.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_ioctl.h>
+#include <drm/drm_modeset_helper.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+

drivers/gpu/drm/loongson/lsdc_drv.c line 30

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+#include "lsdc_drv.h"
+#include "lsdc_gem.h"
+#include "lsdc_i2c.h"
+#include "lsdc_irq.h"
+#include "lsdc_output.h"
+#include "lsdc_probe.h"
+#include "lsdc_ttm.h"
+
+#define DRIVER_AUTHOR           "Sui Jingfeng <[email protected]>"
+#define DRIVER_NAME             "loongson"

I'd strongly suggest "loongson_drm" or some other name here. See the comment on the Kconfig change above.

Quoted 39 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +39 -0
+#define DRIVER_DESC             "drm driver for loongson graphics"
+#define DRIVER_DATE             "20220701"
+#define DRIVER_MAJOR            1
+#define DRIVER_MINOR            0
+#define DRIVER_PATCHLEVEL       0
+
+DEFINE_DRM_GEM_FOPS(lsdc_gem_fops);
+
+static const struct drm_driver lsdc_drm_driver = {
+	.driver_features = DRIVER_MODESET | DRIVER_RENDER | DRIVER_GEM | DRIVER_ATOMIC,
+	.fops = &lsdc_gem_fops,
+
+	.name = DRIVER_NAME,
+	.desc = DRIVER_DESC,
+	.date = DRIVER_DATE,
+	.major = DRIVER_MAJOR,
+	.minor = DRIVER_MINOR,
+	.patchlevel = DRIVER_PATCHLEVEL,
+
+	.debugfs_init = lsdc_debugfs_init,
+	.dumb_create = lsdc_dumb_create,
+	.dumb_map_offset = lsdc_dumb_map_offset,
+	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
+	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+	.gem_prime_import_sg_table = lsdc_prime_import_sg_table,
+	.gem_prime_mmap = drm_gem_prime_mmap,
+};
+
+static const struct drm_mode_config_funcs lsdc_mode_config_funcs = {
+	.fb_create = drm_gem_fb_create,
+	.atomic_check = drm_atomic_helper_check,
+	.atomic_commit = drm_atomic_helper_commit,
+};
+
+/* Display related */
+
+static int lsdc_modeset_init(struct lsdc_device *ldev,
+			     unsigned int num_crtc,
+			     const struct lsdc_kms_funcs *funcs)

drivers/gpu/drm/loongson/lsdc_drv.c line 79

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+{
+	struct drm_device *ddev = &ldev->base;
+	struct lsdc_display_pipe *dispipe;
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < num_crtc; i++) {
+		dispipe = &ldev->dispipe[i];
+
+		/* We need a index before crtc is initialized */

"an index"

Quoted 75 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +75 -0
+		dispipe->index = i;
+
+		ret = funcs->create_i2c(ddev, dispipe, i);
+		if (ret)
+			return ret;
+	}
+
+	for (i = 0; i < num_crtc; i++) {
+		struct i2c_adapter *ddc = NULL;
+
+		dispipe = &ldev->dispipe[i];
+		if (dispipe->li2c)
+			ddc = &dispipe->li2c->adapter;
+
+		ret = funcs->output_init(ddev, dispipe, ddc, i);
+		if (ret)
+			return ret;
+
+		ldev->num_output++;
+	}
+
+	for (i = 0; i < num_crtc; i++) {
+		dispipe = &ldev->dispipe[i];
+
+		ret = funcs->primary_plane_init(ddev, &dispipe->primary.base, i);
+		if (ret)
+			return ret;
+
+		ret = funcs->cursor_plane_init(ddev, &dispipe->cursor.base, i);
+		if (ret)
+			return ret;
+
+		ret = funcs->crtc_init(ddev,
+				       &dispipe->crtc.base,
+				       &dispipe->primary.base,
+				       &dispipe->cursor.base,
+				       i);
+		if (ret)
+			return ret;
+	}
+
+	drm_info(ddev, "total %u outputs\n", ldev->num_output);
+
+	return 0;
+}
+
+static const struct drm_mode_config_helper_funcs
+lsdc_mode_config_helper_funcs = {
+	.atomic_commit_tail = drm_atomic_helper_commit_tail,
+};
+
+static int lsdc_mode_config_init(struct drm_device *ddev,
+				 const struct lsdc_desc *descp)
+{
+	int ret;
+
+	ret = drmm_mode_config_init(ddev);
+	if (ret)
+		return ret;
+
+	ddev->mode_config.funcs = &lsdc_mode_config_funcs;
+	ddev->mode_config.min_width = 1;
+	ddev->mode_config.min_height = 1;
+	ddev->mode_config.max_width = descp->max_width * LSDC_NUM_CRTC;
+	ddev->mode_config.max_height = descp->max_height * LSDC_NUM_CRTC;
+	ddev->mode_config.preferred_depth = 24;
+	ddev->mode_config.prefer_shadow = 1;
+
+	ddev->mode_config.cursor_width = descp->hw_cursor_h;
+	ddev->mode_config.cursor_height = descp->hw_cursor_h;
+
+	/* Indicates support for immediate flip */
+	ddev->mode_config.async_page_flip = true;
+
+	ddev->mode_config.helper_private = &lsdc_mode_config_helper_funcs;

drivers/gpu/drm/loongson/lsdc_drv.c line 164

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+
+	if (descp->has_vblank_counter)
+		ddev->max_vblank_count = 0xffffffff;
+
+	return ret;
+}
+
+/*
+ * The GPU and display controller in LS7A1000/LS7A2000 are separated
+ * PCIE devices, they are two devices not one. The DC does not has a

"does not have"

drivers/gpu/drm/loongson/lsdc_drv.c line 165

Quoted 1 line
drivers/gpu/drm/loongson/lsdc_drv.c new file +1 -0
+ * dedicate VRAM bar, because the BIOS engineer choose to assign the

"the firmware people chose to"

drivers/gpu/drm/loongson/lsdc_drv.c line 167

Quoted 2 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +2 -0
+ * VRAM to the GPU device. Sadly, after years application, this form
+ * as a convention for loongson integrated graphics. Bar 2 of the GPU

"this became a convention for Loongson integrated graphics years after"

<rant>Seriously, you *could* change something now, it's 2023 and LoongArch is already a thing after all so you're no longer constrained by anything else...</rant>

drivers/gpu/drm/loongson/lsdc_drv.c line 170

Quoted 3 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +3 -0
+ * device contain the base address and size of the VRAM, both the GPU
+ * and the DC can access the on-board VRAM as long as the DMA address
+ * emitted fall in [base, base + size).

"the DMA address falls in"? Not very sure what "emitted" is about.

Quoted 46 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +46 -0
+ */
+static int lsdc_get_dedicated_vram(struct lsdc_device *ldev,
+				   struct pci_dev *pdev_dc,
+				   const struct lsdc_desc *descp)
+{
+	struct drm_device *ddev = &ldev->base;
+	struct pci_dev *pdev_gpu;
+	resource_size_t base, size;
+
+	/*
+	 * The GPU has 00:06.0 as its BDF, while the DC has 00:06.1,
+	 * This is sure for LS7A1000, LS7A2000 and LS2K2000.
+	 */
+	pdev_gpu = pci_get_domain_bus_and_slot(pci_domain_nr(pdev_dc->bus),
+					       pdev_dc->bus->number,
+					       PCI_DEVFN(6, 0));
+	if (!pdev_gpu) {
+		drm_err(ddev, "No GPU device, then no VRAM\n");
+		return -ENODEV;
+	}
+
+	base = pci_resource_start(pdev_gpu, 2);
+	size = pci_resource_len(pdev_gpu, 2);
+
+	ldev->vram_base = base;
+	ldev->vram_size = size;
+	ldev->gpu = pdev_gpu;
+
+	drm_info(ddev, "dedicated vram start: 0x%llx, size: %uMB\n",
+		 (u64)base, (u32)(size >> 20));
+
+	return 0;
+}
+
+static struct lsdc_device *
+lsdc_create_device(struct pci_dev *pdev,
+		   const struct lsdc_desc *descp,
+		   const struct drm_driver *drv)
+{
+	struct lsdc_device *ldev;
+	struct drm_device *ddev;
+	int ret;
+
+	ldev = devm_drm_dev_alloc(&pdev->dev, drv, struct lsdc_device, base);
+	if (IS_ERR(ldev))
+		return ldev;

drivers/gpu/drm/loongson/lsdc_drv.c line 226

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+
+	ddev = &ldev->base;
+
+	ldev->descp = descp;
+
+	loongson_gfxpll_create(ddev, &ldev->gfxpll);
+
+	ret = lsdc_get_dedicated_vram(ldev, pdev, descp);
+	if (ret) {
+		drm_err(ddev, "Init VRAM failed: %d\n", ret);

"VRAM init failed"

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+		return ERR_PTR(ret);
+	}
+
+	ret = drm_aperture_remove_conflicting_framebuffers(ldev->vram_base,
+							   ldev->vram_size,
+							   drv);
+	if (ret) {
+		drm_err(ddev, "remove firmware framebuffers failed: %d\n", ret);
+		return ERR_PTR(ret);
+	}

drivers/gpu/drm/loongson/lsdc_drv.c line 246

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+
+	ret = lsdc_ttm_init(ldev);
+	if (ret) {
+		drm_err(ddev, "memory manager init failed: %d\n", ret);
+		return ERR_PTR(ret);
+	}
+
+	lsdc_gem_init(ddev);
+
+	/* BAR 0 of the DC device contain registers base address */

"contains"

Quoted 92 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +92 -0
+	ldev->reg_base = pcim_iomap(pdev, 0, 0);
+	if (!ldev->reg_base)
+		return ERR_PTR(-ENODEV);
+
+	spin_lock_init(&ldev->reglock);
+
+	ret = lsdc_mode_config_init(ddev, descp);
+	if (ret)
+		return ERR_PTR(ret);
+
+	ret = lsdc_modeset_init(ldev, descp->num_of_crtc, descp->funcs);
+	if (ret)
+		return ERR_PTR(ret);
+
+	drm_mode_config_reset(ddev);
+
+	ret = drm_vblank_init(ddev, descp->num_of_crtc);
+	if (ret)
+		return ERR_PTR(ret);
+
+	drm_kms_helper_poll_init(ddev);
+
+	return ldev;
+}
+
+static int lsdc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+{
+	const struct lsdc_desc *descp;
+	struct drm_device *ddev;
+	struct lsdc_device *ldev;
+	int ret;
+
+	ret = pcim_enable_device(pdev);
+	if (ret)
+		return ret;
+
+	pci_set_master(pdev);
+
+	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
+	if (ret)
+		return ret;
+
+	descp = lsdc_device_probe(pdev, ent->driver_data);
+	if (IS_ERR_OR_NULL(descp))
+		return -ENODEV;
+
+	dev_info(&pdev->dev, "Found %s, revision: %u",
+		 to_loongson_gfx(descp)->model, pdev->revision);
+
+	ldev = lsdc_create_device(pdev, descp, &lsdc_drm_driver);
+	if (IS_ERR(ldev))
+		return PTR_ERR(ldev);
+
+	ldev->dc = pdev;
+
+	ddev = &ldev->base;
+
+	pci_set_drvdata(pdev, ddev);
+
+	ret = devm_request_irq(&pdev->dev,
+			       pdev->irq,
+			       descp->funcs->irq_handler,
+			       IRQF_SHARED,
+			       dev_name(&pdev->dev),
+			       ddev);
+	if (ret) {
+		drm_err(ddev, "Failed to register interrupt: %d\n", ret);
+		return ret;
+	}
+
+	ret = drm_dev_register(ddev, 0);
+	if (ret)
+		return ret;
+
+	drm_fbdev_generic_setup(ddev, 32);
+
+	return 0;
+}
+
+static void lsdc_pci_remove(struct pci_dev *pdev)
+{
+	struct drm_device *ddev = pci_get_drvdata(pdev);
+
+	drm_dev_unregister(ddev);
+	drm_atomic_helper_shutdown(ddev);
+}
+
+static int lsdc_drm_freeze(struct drm_device *ddev)
+{
+	struct lsdc_device *ldev = to_lsdc(ddev);
+	struct lsdc_bo *lbo;
+	int ret;

drivers/gpu/drm/loongson/lsdc_drv.c line 348

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+
+	/* unpin all of buffers in the vram */
+	mutex_lock(&ldev->gem.mutex);
+	list_for_each_entry(lbo, &ldev->gem.objects, list) {
+		struct ttm_buffer_object *tbo = &lbo->tbo;
+		struct ttm_resource *resource = tbo->resource;
+		unsigned int pin_count = tbo->pin_count;
+
+		drm_dbg(ddev,
+			"bo[%p], size: %zuKB, type: %s, pin count: %u\n",

"KiB" for extra clarity?

Quoted 7 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +7 -0
+			lbo,
+			lsdc_bo_size(lbo) >> 10,
+			lsdc_mem_type_to_str(resource->mem_type),
+			pin_count);
+
+		if (!pin_count)
+			continue;

drivers/gpu/drm/loongson/lsdc_drv.c line 365

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+
+		if (resource->mem_type == TTM_PL_VRAM) {
+			ret = lsdc_bo_reserve(lbo);
+			if (unlikely(ret)) {
+				drm_err(ddev, "bo reserve failed: %d\n", ret);
+				continue;
+			}
+
+			/*
+			 * For double screen usage case, multiple crtc may

"For double screen case, multiple crtcs may reference the single ..."

drivers/gpu/drm/loongson/lsdc_drv.c line 369

Quoted 4 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +4 -0
+			 * reference to the single giant framebuffer bo.
+			 * The single giant fb bo get pinned by multiple time.
+			 * thus, it need to unpin until its pin counter reach
+			 * zero.

"The single giant fb bo is pinned multiple times, hence it needs to be unpinned until ..."

Quoted 98 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +98 -0
+			 */
+			do {
+				lsdc_bo_unpin(lbo);
+				--pin_count;
+			} while (pin_count);
+
+			lsdc_bo_unreserve(lbo);
+		}
+	}
+	mutex_unlock(&ldev->gem.mutex);
+
+	lsdc_bo_evict_vram(ddev);
+
+	ret = drm_mode_config_helper_suspend(ddev);
+	if (unlikely(ret)) {
+		drm_err(ddev, "freeze error: %d", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int lsdc_drm_resume(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct drm_device *ddev = pci_get_drvdata(pdev);
+
+	return drm_mode_config_helper_resume(ddev);
+}
+
+static int lsdc_pm_freeze(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct drm_device *ddev = pci_get_drvdata(pdev);
+
+	return lsdc_drm_freeze(ddev);
+}
+
+static int lsdc_pm_thaw(struct device *dev)
+{
+	return lsdc_drm_resume(dev);
+}
+
+static int lsdc_pm_suspend(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	int error;
+
+	error = lsdc_pm_freeze(dev);
+	if (error)
+		return error;
+
+	pci_save_state(pdev);
+	/* Shut down the device */
+	pci_disable_device(pdev);
+	pci_set_power_state(pdev, PCI_D3hot);
+
+	return 0;
+}
+
+static int lsdc_pm_resume(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+
+	pci_set_power_state(pdev, PCI_D0);
+
+	pci_restore_state(pdev);
+
+	if (pcim_enable_device(pdev))
+		return -EIO;
+
+	return lsdc_pm_thaw(dev);
+}
+
+static const struct dev_pm_ops lsdc_pm_ops = {
+	.suspend = lsdc_pm_suspend,
+	.resume = lsdc_pm_resume,
+	.freeze = lsdc_pm_freeze,
+	.thaw = lsdc_pm_thaw,
+	.poweroff = lsdc_pm_freeze,
+	.restore = lsdc_pm_resume,
+};
+
+static const struct pci_device_id lsdc_pciid_list[] = {
+	{PCI_VENDOR_ID_LOONGSON, 0x7a06, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_LS7A1000},
+	{PCI_VENDOR_ID_LOONGSON, 0x7a36, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_LS7A2000},
+	{0, 0, 0, 0, 0, 0, 0}
+};
+
+static struct pci_driver lsdc_pci_driver = {
+	.name = DRIVER_NAME,
+	.id_table = lsdc_pciid_list,
+	.probe = lsdc_pci_probe,
+	.remove = lsdc_pci_remove,
+	.driver.pm = &lsdc_pm_ops,
+};
+
+static int __init loongson_module_init(void)

drivers/gpu/drm/loongson/lsdc_drv.c line 477

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +10 -0
+{
+	struct pci_dev *pdev = NULL;
+
+	if (video_firmware_drivers_only())
+		return -ENODEV;
+
+	/* Multiple video card workaround */
+	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev))) {
+		if (pdev->vendor != PCI_VENDOR_ID_LOONGSON) {
+			pr_info("Discrete graphic card detected, abort\n");

Why is it that the iGPU cannot be used together with a dGPU? I can't see why this is technically the case so some more explanations could be beneficial to other readers and LoongArch devs.

Quoted 40 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +18 -0
+			return 0;
+		}
+	}
+
+	return pci_register_driver(&lsdc_pci_driver);
+}
+module_init(loongson_module_init);
+
+static void __exit loongson_module_exit(void)
+{
+	pci_unregister_driver(&lsdc_pci_driver);
+}
+module_exit(loongson_module_exit);
+
+MODULE_DEVICE_TABLE(pci, lsdc_pciid_list);
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
drivers/gpu/drm/loongson/lsdc_drv.h new file +16 -0
new file mode 100644
index 000000000000..25636787191f
@@ -0,0 +1,451 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef __LSDC_DRV_H__
+#define __LSDC_DRV_H__
+
+#include <linux/pci.h>
+
+#include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
+#include <drm/drm_device.h>
+#include <drm/drm_encoder.h>
+#include <drm/drm_file.h>
+#include <drm/drm_plane.h>

drivers/gpu/drm/loongson/lsdc_drv.h line 26

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_drv.h new file +10 -0
+#include <drm/ttm/ttm_device.h>
+
+#include "lsdc_i2c.h"
+#include "lsdc_irq.h"
+#include "lsdc_gfxpll.h"
+#include "lsdc_output.h"
+#include "lsdc_pixpll.h"
+#include "lsdc_regs.h"
+
+/* Currently, all loongson display controller has two display pipes */

"... controllers have ..."

drivers/gpu/drm/loongson/lsdc_drv.h line 30

Quoted 4 lines
drivers/gpu/drm/loongson/lsdc_drv.h new file +4 -0
+#define LSDC_NUM_CRTC           2
+
+/*
+ * LS7A1000/LS7A2000 bridge chipset function as south & north of the Loongson

"south & north bridges"

drivers/gpu/drm/loongson/lsdc_drv.h line 33

Quoted 3 lines
drivers/gpu/drm/loongson/lsdc_drv.h new file +3 -0
+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Also the description about the Loongson 2K series is a bit irrelevant (we're focusing on VRAM here) so you could simplify the sentence a bit.

drivers/gpu/drm/loongson/lsdc_drv.h line 35

Quoted 2 lines
drivers/gpu/drm/loongson/lsdc_drv.h new file +2 -0
+ *
+ * LS7A2000 integrated a 32-bit DDR4@2400 video memtory controller, while

"integrates a 32-bit DDR4-2400 video memory controller"

Maybe you can spell-check your code before submitting... it's getting tiresome pointing out every misspelling and unnatural English usage. I'm not doing so for the rest of my review.

drivers/gpu/drm/loongson/lsdc_plane.c

Quoted 2,782 lines
drivers/gpu/drm/loongson/lsdc_drv.h new file +416 -0
+ * it is just 16-bit DDR3 for LS7A1000. LS7A2000 integrate Loongson self
+ * maded LoongGPU, LS7A1000 integrate GC1000 due to historical reasons.
+ *
+ * The display controller in LS7A1000 has only two-way DVO interface exported,
+ * thus, external encoder(TX chip) is required except connected with DPI panel
+ * directly.
+ *       ___________________                                     _________
+ *      |            -------|                                   |         |
+ *      |  CRTC0 --> | DVO0 ----> Encoder0 ---> Connector0 ---> | Display |
+ *      |  _   _     -------|        ^             ^            |_________|
+ *      | | | | |  +------+ |        |             |
+ *      | |_| |_|  | i2c6 | <--------+-------------+
+ *      |          +------+ |
+ *      |                   |
+ *      |  DC in LS7A1000   |
+ *      |                   |
+ *      |  _   _   +------+ |
+ *      | | | | |  | i2c7 | <--------+-------------+
+ *      | |_| |_|  +------+ |        |             |             _________
+ *      |            -------|        |             |            |         |
+ *      |  CRTC1 --> | DVO1 ----> Encoder1 ---> Connector1 ---> |  Panel  |
+ *      |            -------|                                   |_________|
+ *      |___________________|
+ *
+ * The display controller in LS7A2000 has two display pipe, yet it has
+ * integrated three encoders, display pipe 0 is attached with a transparent
+ * VGA encoder and a HDMI encoder, they are parallel. Display pipe 1 has
+ * only one HDMI phy connected.
+ *
+ *       ______________________                          _____________
+ *      |             +-----+  |                        |             |
+ *      | CRTC0 -+--> | VGA |  ----> VGA Connector ---> | VGA Monitor |<---+
+ *      |        |    +-----+  |                        |_____________|    |
+ *      |        |             |                         ______________    |
+ *      |        |    +------+ |                        |              |   |
+ *      |        +--> | HDMI | ----> HDMI Connector --> | HDMI Monitor |<--+
+ *      |             +------+ |                        |______________|   |
+ *      |            +------+  |                                           |
+ *      |            | i2c6 |  <-------------------------------------------+
+ *      |            +------+  |
+ *      |                      |
+ *      |    DC in LS7A2000    |
+ *      |                      |
+ *      |            +------+  |
+ *      |            | i2c7 |  <--------------------------------+
+ *      |            +------+  |                                |
+ *      |                      |                          ______|_______
+ *      |            +------+  |                         |              |
+ *      | CRTC1 ---> | HDMI |  ----> HDMI Connector ---> | HDMI Monitor |
+ *      |            +------+  |                         |______________|
+ *      |______________________|
+ *
+ *
+ * There is only a 1:1 mapping of crtcs, encoders and connectors for the DC,
+ * display pipe 0 = crtc0 + dvo0 + encoder0 + connector0 + cursor0 + primary0
+ * display pipe 1 = crtc1 + dvo1 + encoder1 + connectro1 + cursor1 + primary1
+ * Each CRTC has two FB address registers.
+ *
+ * The DC in LS7A1000/LS2K1000 has the pci vendor/device ID: 0x0014:0x7a06,
+ * The DC in LS7A2000/LS2K2000 has the pci vendor/device ID: 0x0014:0x7a36.
+ *
+ * The GPU in LS7A1000 has the pci vendor/device ID: 0x0014:0x7a15,
+ * The GPU in LS7A2000 has the pci vendor/device ID: 0x0014:0x7a25.
+ *
+ * LS7A1000/LS7A2000 can only be used with desktop or server class CPUs, such
+ * as LS3A4000, LS3A5000 and LS3A6000. Thus, CPU PRID can be used to
+ * distinguish Loongson SoC from those the desktop class CPU on the runtime.
+ */
+enum loongson_chip_id {
+	CHIP_LS7A1000 = 0,
+	CHIP_LS7A2000 = 1,
+	CHIP_LS_LAST,
+};
+
+const struct lsdc_desc *
+lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip);
+
+struct lsdc_kms_funcs;
+
+/* DC specific */
+
+struct lsdc_desc {
+	u32 num_of_crtc;
+	u32 max_pixel_clk;
+	u32 max_width;
+	u32 max_height;
+	u32 num_of_hw_cursor;
+	u32 hw_cursor_w;
+	u32 hw_cursor_h;
+	u32 pitch_align;         /* CRTC DMA alignment constraint */
+	u64 mc_bits;             /* physical address bus bit width */
+	bool has_vblank_counter; /* 32 bit hw vsync counter */
+
+	/* device dependent ops, dc side */
+	const struct lsdc_kms_funcs *funcs;
+};
+
+/* GFX related resources wrangler */
+
+struct loongson_gfx_desc {
+	struct lsdc_desc dc;
+
+	u32 conf_reg_base;
+
+	/* GFXPLL shared by the DC, GMC and GPU */
+	struct {
+		u32 reg_offset;
+		u32 reg_size;
+	} gfxpll;
+
+	/* Pixel PLL, per display pipe */
+	struct {
+		u32 reg_offset;
+		u32 reg_size;
+	} pixpll[LSDC_NUM_CRTC];
+
+	enum loongson_chip_id chip_id;
+	char model[64];
+};
+
+static inline const struct loongson_gfx_desc *
+to_loongson_gfx(const struct lsdc_desc *dcp)
+{
+	return container_of_const(dcp, struct loongson_gfx_desc, dc);
+};
+
+struct lsdc_reg32 {
+	char *name;
+	u32 offset;
+};
+
+/* crtc hardware related ops */
+
+struct lsdc_crtc;
+
+struct lsdc_crtc_hw_ops {
+	void (*enable)(struct lsdc_crtc *lcrtc);
+	void (*disable)(struct lsdc_crtc *lcrtc);
+	void (*enable_vblank)(struct lsdc_crtc *lcrtc);
+	void (*disable_vblank)(struct lsdc_crtc *lcrtc);
+	void (*flip)(struct lsdc_crtc *lcrtc);
+	void (*clone)(struct lsdc_crtc *lcrtc);
+	void (*get_scan_pos)(struct lsdc_crtc *lcrtc, int *hpos, int *vpos);
+	void (*set_mode)(struct lsdc_crtc *lcrtc, const struct drm_display_mode *mode);
+	void (*soft_reset)(struct lsdc_crtc *lcrtc);
+	void (*reset)(struct lsdc_crtc *lcrtc);
+
+	u32  (*get_vblank_counter)(struct lsdc_crtc *lcrtc);
+	void (*set_dma_step)(struct lsdc_crtc *lcrtc, enum lsdc_dma_steps step);
+};
+
+struct lsdc_crtc {
+	struct drm_crtc base;
+	struct lsdc_pixpll pixpll;
+	struct lsdc_device *ldev;
+	const struct lsdc_crtc_hw_ops *hw_ops;
+	const struct lsdc_reg32 *preg;
+	unsigned int nreg;
+	struct drm_info_list *p_info_list;
+	unsigned int n_info_list;
+};
+
+/* primary plane hardware related ops */
+
+struct lsdc_primary;
+
+struct lsdc_primary_plane_ops {
+	void (*update_fb_addr)(struct lsdc_primary *plane, u64 addr);
+	void (*update_fb_stride)(struct lsdc_primary *plane, u32 stride);
+	void (*update_fb_format)(struct lsdc_primary *plane,
+				 const struct drm_format_info *format);
+};
+
+struct lsdc_primary {
+	struct drm_plane base;
+	const struct lsdc_primary_plane_ops *ops;
+	struct lsdc_device *ldev;
+};
+
+/* cursor plane hardware related ops */
+
+struct lsdc_cursor;
+
+struct lsdc_cursor_plane_ops {
+	void (*update_bo_addr)(struct lsdc_cursor *plane, u64 addr);
+	void (*update_cfg)(struct lsdc_cursor *plane,
+			   enum lsdc_cursor_size cursor_size,
+			   enum lsdc_cursor_format);
+	void (*update_position)(struct lsdc_cursor *plane, int x, int y);
+};
+
+struct lsdc_cursor {
+	struct drm_plane base;
+	const struct lsdc_cursor_plane_ops *ops;
+	struct lsdc_device *ldev;
+};
+
+struct lsdc_output {
+	struct drm_encoder encoder;
+	struct drm_connector connector;
+};
+
+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);
+}
+
+struct lsdc_display_pipe {
+	struct lsdc_crtc crtc;
+	struct lsdc_primary primary;
+	struct lsdc_cursor cursor;
+	struct lsdc_output output;
+	struct lsdc_i2c *li2c;
+	unsigned int index;
+};
+
+static inline struct lsdc_display_pipe *
+output_to_display_pipe(struct lsdc_output *output)
+{
+	return container_of(output, struct lsdc_display_pipe, output);
+}
+
+struct lsdc_kms_funcs {
+	irqreturn_t (*irq_handler)(int irq, void *arg);
+
+	int (*create_i2c)(struct drm_device *ddev,
+			  struct lsdc_display_pipe *dispipe,
+			  unsigned int index);
+
+	int (*output_init)(struct drm_device *ddev,
+			   struct lsdc_display_pipe *dispipe,
+			   struct i2c_adapter *ddc,
+			   unsigned int index);
+
+	int (*cursor_plane_init)(struct drm_device *ddev,
+				 struct drm_plane *plane,
+				 unsigned int index);
+
+	int (*primary_plane_init)(struct drm_device *ddev,
+				  struct drm_plane *plane,
+				  unsigned int index);
+
+	int (*crtc_init)(struct drm_device *ddev,
+			 struct drm_crtc *crtc,
+			 struct drm_plane *primary,
+			 struct drm_plane *cursor,
+			 unsigned int index);
+};
+
+static inline struct lsdc_crtc *
+to_lsdc_crtc(struct drm_crtc *crtc)
+{
+	return container_of(crtc, struct lsdc_crtc, base);
+}
+
+static inline struct lsdc_display_pipe *
+crtc_to_display_pipe(struct drm_crtc *crtc)
+{
+	return container_of(crtc, struct lsdc_display_pipe, crtc.base);
+}
+
+static inline struct lsdc_primary *
+to_lsdc_primary(struct drm_plane *plane)
+{
+	return container_of(plane, struct lsdc_primary, base);
+}
+
+static inline struct lsdc_cursor *
+to_lsdc_cursor(struct drm_plane *plane)
+{
+	return container_of(plane, struct lsdc_cursor, base);
+}
+
+struct lsdc_crtc_state {
+	struct drm_crtc_state base;
+	struct lsdc_pixpll_parms pparms;
+};
+
+struct lsdc_gem {
+	/* @mutex: protect objects list */
+	struct mutex mutex;
+	struct list_head objects;
+};
+
+struct lsdc_device {
+	struct drm_device base;
+	struct ttm_device bdev;
+
+	/* @descp: features description of the DC variant */
+	const struct lsdc_desc *descp;
+	struct pci_dev *dc;
+	struct pci_dev *gpu;
+
+	struct loongson_gfxpll *gfxpll;
+
+	/* @reglock: protects concurrent access */
+	spinlock_t reglock;
+
+	void __iomem *reg_base;
+	resource_size_t vram_base;
+	resource_size_t vram_size;
+
+	resource_size_t gtt_base;
+	resource_size_t gtt_size;
+
+	struct lsdc_display_pipe dispipe[LSDC_NUM_CRTC];
+
+	struct lsdc_gem gem;
+
+	u32 irq_status;
+
+	/* tracking pinned memory */
+	size_t vram_pinned_size;
+	size_t gtt_pinned_size;
+
+	/* @num_output: count the number of active display pipe */
+	unsigned int num_output;
+};
+
+static inline struct lsdc_device *tdev_to_ldev(struct ttm_device *bdev)
+{
+	return container_of(bdev, struct lsdc_device, bdev);
+}
+
+static inline struct lsdc_device *to_lsdc(struct drm_device *ddev)
+{
+	return container_of(ddev, struct lsdc_device, base);
+}
+
+static inline struct lsdc_crtc_state *
+to_lsdc_crtc_state(struct drm_crtc_state *base)
+{
+	return container_of(base, struct lsdc_crtc_state, base);
+}
+
+void lsdc_debugfs_init(struct drm_minor *minor);
+
+int ls7a1000_crtc_init(struct drm_device *ddev,
+		       struct drm_crtc *crtc,
+		       struct drm_plane *primary,
+		       struct drm_plane *cursor,
+		       unsigned int index);
+
+int ls7a2000_crtc_init(struct drm_device *ddev,
+		       struct drm_crtc *crtc,
+		       struct drm_plane *primary,
+		       struct drm_plane *cursor,
+		       unsigned int index);
+
+int lsdc_primary_plane_init(struct drm_device *ddev,
+			    struct drm_plane *plane,
+			    unsigned int index);
+
+int ls7a1000_cursor_plane_init(struct drm_device *ddev,
+			       struct drm_plane *plane,
+			       unsigned int index);
+
+int ls7a2000_cursor_plane_init(struct drm_device *ddev,
+			       struct drm_plane *plane,
+			       unsigned int index);
+
+/* registers access helpers */
+
+static inline u32 lsdc_rreg32(struct lsdc_device *ldev, u32 offset)
+{
+	return readl(ldev->reg_base + offset);
+}
+
+static inline void lsdc_wreg32(struct lsdc_device *ldev, u32 offset, u32 val)
+{
+	writel(val, ldev->reg_base + offset);
+}
+
+static inline void lsdc_ureg32_set(struct lsdc_device *ldev,
+				   u32 offset,
+				   u32 mask)
+{
+	void __iomem *addr = ldev->reg_base + offset;
+	u32 val = readl(addr);
+
+	writel(val | mask, addr);
+}
+
+static inline void lsdc_ureg32_clr(struct lsdc_device *ldev,
+				   u32 offset,
+				   u32 mask)
+{
+	void __iomem *addr = ldev->reg_base + offset;
+	u32 val = readl(addr);
+
+	writel(val & ~mask, addr);
+}
+
+static inline u32 lsdc_pipe_rreg32(struct lsdc_device *ldev,
+				   u32 offset,
+				   u32 pipe)
+{
+	return readl(ldev->reg_base + offset + pipe * CRTC_PIPE_OFFSET);
+}
+
+static inline void lsdc_pipe_wreg32(struct lsdc_device *ldev,
+				    u32 offset,
+				    u32 pipe,
+				    u32 val)
+{
+	writel(val, ldev->reg_base + offset + pipe * CRTC_PIPE_OFFSET);
+}
+
+#endif
drivers/gpu/drm/loongson/lsdc_gem.c new file +324 -0
new file mode 100644
index 000000000000..f21942b2a3b8
@@ -0,0 +1,324 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <linux/dma-buf.h>
+
+#include <drm/drm_debugfs.h>
+#include <drm/drm_file.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_prime.h>
+
+#include "lsdc_drv.h"
+#include "lsdc_gem.h"
+#include "lsdc_ttm.h"
+
+static int lsdc_gem_prime_pin(struct drm_gem_object *obj)
+{
+	struct lsdc_bo *lbo = gem_to_lsdc_bo(obj);
+	int ret;
+
+	ret = lsdc_bo_reserve(lbo);
+	if (unlikely(ret))
+		return ret;
+
+	ret = lsdc_bo_pin(lbo, LSDC_GEM_DOMAIN_GTT, NULL);
+	if (likely(ret == 0))
+		lbo->sharing_count++;
+
+	lsdc_bo_unreserve(lbo);
+
+	return ret;
+}
+
+static void lsdc_gem_prime_unpin(struct drm_gem_object *obj)
+{
+	struct lsdc_bo *lbo = gem_to_lsdc_bo(obj);
+	int ret;
+
+	ret = lsdc_bo_reserve(lbo);
+	if (unlikely(ret))
+		return;
+
+	lsdc_bo_unpin(lbo);
+	if (lbo->sharing_count)
+		lbo->sharing_count--;
+
+	lsdc_bo_unreserve(lbo);
+}
+
+static struct sg_table *lsdc_gem_prime_get_sg_table(struct drm_gem_object *obj)
+{
+	struct ttm_buffer_object *tbo = to_ttm_bo(obj);
+	struct ttm_tt *tt = tbo->ttm;
+
+	if (!tt) {
+		drm_err(obj->dev, "sharing a buffer without backing memory\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	return drm_prime_pages_to_sg(obj->dev, tt->pages, tt->num_pages);
+}
+
+static void lsdc_gem_object_free(struct drm_gem_object *obj)
+{
+	struct ttm_buffer_object *tbo = to_ttm_bo(obj);
+
+	if (tbo)
+		ttm_bo_put(tbo);
+}
+
+static int lsdc_gem_object_vmap(struct drm_gem_object *obj,
+				struct iosys_map *map)
+{
+	struct ttm_buffer_object *tbo = to_ttm_bo(obj);
+	struct lsdc_bo *lbo = to_lsdc_bo(tbo);
+	int ret;
+
+	if (lbo->vmap_count > 0) {
+		++lbo->vmap_count;
+		goto out;
+	}
+
+	ret = lsdc_bo_pin(lbo, 0, NULL);
+	if (unlikely(ret)) {
+		drm_err(obj->dev, "pin %p for vmap failed\n", lbo);
+		return ret;
+	}
+
+	ret = ttm_bo_vmap(tbo, &lbo->map);
+	if (ret) {
+		drm_err(obj->dev, "ttm bo vmap failed\n");
+		lsdc_bo_unpin(lbo);
+		return ret;
+	}
+
+	lbo->vmap_count = 1;
+
+out:
+	*map = lbo->map;
+
+	return 0;
+}
+
+static void lsdc_gem_object_vunmap(struct drm_gem_object *obj,
+				   struct iosys_map *map)
+{
+	struct ttm_buffer_object *tbo = to_ttm_bo(obj);
+	struct lsdc_bo *lbo = to_lsdc_bo(tbo);
+
+	if (unlikely(!lbo->vmap_count)) {
+		drm_warn(obj->dev, "%p is not mapped\n", lbo);
+		return;
+	}
+
+	--lbo->vmap_count;
+	if (lbo->vmap_count == 0) {
+		ttm_bo_vunmap(tbo, &lbo->map);
+
+		lsdc_bo_unpin(lbo);
+	}
+}
+
+static int lsdc_gem_object_mmap(struct drm_gem_object *obj,
+				struct vm_area_struct *vma)
+{
+	struct ttm_buffer_object *tbo = to_ttm_bo(obj);
+	int ret;
+
+	ret = ttm_bo_mmap_obj(vma, tbo);
+	if (unlikely(ret)) {
+		drm_warn(obj->dev, "mmap %p failed\n", tbo);
+		return ret;
+	}
+
+	drm_gem_object_put(obj);
+
+	return 0;
+}
+
+static const struct drm_gem_object_funcs lsdc_gem_object_funcs = {
+	.free = lsdc_gem_object_free,
+	.export = drm_gem_prime_export,
+	.pin = lsdc_gem_prime_pin,
+	.unpin = lsdc_gem_prime_unpin,
+	.get_sg_table = lsdc_gem_prime_get_sg_table,
+	.vmap = lsdc_gem_object_vmap,
+	.vunmap = lsdc_gem_object_vunmap,
+	.mmap = lsdc_gem_object_mmap,
+};
+
+struct drm_gem_object *
+lsdc_gem_object_create(struct drm_device *ddev,
+		       u32 domain,
+		       size_t size,
+		       bool kerenl,
+		       struct sg_table *sg,
+		       struct dma_resv *resv)
+{
+	struct lsdc_device *ldev = to_lsdc(ddev);
+	struct drm_gem_object *gobj;
+	struct lsdc_bo *lbo;
+	int ret;
+
+	lbo = lsdc_bo_create(ddev, domain, size, kerenl, sg, resv);
+	if (IS_ERR(lbo)) {
+		ret = PTR_ERR(lbo);
+		return ERR_PTR(ret);
+	}
+
+	/* VRAM is filled with random data */
+	lsdc_bo_clear(lbo);
+
+	gobj = &lbo->tbo.base;
+	gobj->funcs = &lsdc_gem_object_funcs;
+
+	/* tracking the BOs we created */
+	mutex_lock(&ldev->gem.mutex);
+	list_add_tail(&lbo->list, &ldev->gem.objects);
+	mutex_unlock(&ldev->gem.mutex);
+
+	return gobj;
+}
+
+struct drm_gem_object *
+lsdc_prime_import_sg_table(struct drm_device *ddev,
+			   struct dma_buf_attachment *attach,
+			   struct sg_table *sg)
+{
+	struct dma_resv *resv = attach->dmabuf->resv;
+	u64 size = attach->dmabuf->size;
+	struct drm_gem_object *gobj;
+	struct lsdc_bo *lbo;
+
+	dma_resv_lock(resv, NULL);
+	gobj = lsdc_gem_object_create(ddev, LSDC_GEM_DOMAIN_GTT, size, false,
+				      sg, resv);
+	dma_resv_unlock(resv);
+
+	if (IS_ERR(gobj)) {
+		drm_err(ddev, "Failed to import sg table\n");
+		return gobj;
+	}
+
+	lbo = gem_to_lsdc_bo(gobj);
+	lbo->sharing_count = 1;
+
+	return gobj;
+}
+
+int lsdc_dumb_create(struct drm_file *file,
+		     struct drm_device *ddev,
+		     struct drm_mode_create_dumb *args)
+{
+	struct lsdc_device *ldev = to_lsdc(ddev);
+	const struct lsdc_desc *descp = ldev->descp;
+	u32 domain = LSDC_GEM_DOMAIN_VRAM;
+	struct drm_gem_object *gobj;
+	size_t size;
+	u32 pitch;
+	u32 handle;
+	int ret;
+
+	if (!args->width || !args->height)
+		return -EINVAL;
+
+	/* Loongson diaplay controller only support 32-bit and 16-bit FB */
+	if (args->bpp != 32 && args->bpp != 16)
+		return -EINVAL;
+
+	pitch = args->width * args->bpp / 8;
+	pitch = ALIGN(pitch, descp->pitch_align);
+	size = pitch * args->height;
+	size = ALIGN(size, PAGE_SIZE);
+
+	/* Maximum bo size allowed is the half vram size available */
+	if (size > ldev->vram_size / 2) {
+		drm_err(ddev, "Requesting(%zuMB) more than owned(%uMB)\n",
+			size >> 20, (u32)(ldev->vram_size >> 20));
+		return -ENOMEM;
+	}
+
+	gobj = lsdc_gem_object_create(ddev,
+				      domain,
+				      size,
+				      false,
+				      NULL,
+				      NULL);
+	if (IS_ERR(gobj)) {
+		drm_err(ddev, "Failed to create gem object\n");
+		return PTR_ERR(gobj);
+	}
+
+	ret = drm_gem_handle_create(file, gobj, &handle);
+
+	/* drop reference from allocate, handle holds it now */
+	drm_gem_object_put(gobj);
+	if (ret)
+		return ret;
+
+	args->pitch = pitch;
+	args->size = size;
+	args->handle = handle;
+
+	return 0;
+}
+
+int lsdc_dumb_map_offset(struct drm_file *filp,
+			 struct drm_device *ddev,
+			 u32 handle,
+			 uint64_t *offset)
+{
+	struct drm_gem_object *gobj;
+
+	gobj = drm_gem_object_lookup(filp, handle);
+	if (!gobj)
+		return -ENOENT;
+
+	*offset = drm_vma_node_offset_addr(&gobj->vma_node);
+
+	drm_gem_object_put(gobj);
+
+	return 0;
+}
+
+void lsdc_gem_init(struct drm_device *ddev)
+{
+	struct lsdc_device *ldev = to_lsdc(ddev);
+
+	mutex_init(&ldev->gem.mutex);
+	INIT_LIST_HEAD(&ldev->gem.objects);
+}
+
+int lsdc_show_buffer_object(struct seq_file *m, void *arg)
+{
+	struct drm_info_node *node = (struct drm_info_node *)m->private;
+	struct drm_device *ddev = node->minor->dev;
+	struct lsdc_device *ldev = to_lsdc(ddev);
+	struct lsdc_bo *lbo;
+	unsigned int i;
+
+	mutex_lock(&ldev->gem.mutex);
+
+	i = 0;
+
+	list_for_each_entry(lbo, &ldev->gem.objects, list) {
+		struct ttm_buffer_object *tbo = &lbo->tbo;
+		struct ttm_resource *resource = tbo->resource;
+
+		seq_printf(m, "bo[%04u][%p]: size: %8zu KB %s offset: %8llx\n",
+			   i, lbo,
+			   lsdc_bo_size(lbo) >> 10,
+			   lsdc_mem_type_to_str(resource->mem_type),
+			   lsdc_bo_gpu_offset(lbo));
+		i++;
+	}
+
+	mutex_unlock(&ldev->gem.mutex);
+
+	seq_printf(m, "Pinned BO size: VRAM: %zu KB, GTT: %zu KB\n",
+		   ldev->vram_pinned_size >> 10, ldev->gtt_pinned_size >> 10);
+
+	return 0;
+}
drivers/gpu/drm/loongson/lsdc_gem.h new file +37 -0
new file mode 100644
index 000000000000..7e05e453b733
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef __LSDC_GEM_H__
+#define __LSDC_GEM_H__
+
+#include <drm/drm_device.h>
+#include <drm/drm_gem.h>
+
+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);
+
+int lsdc_dumb_create(struct drm_file *file,
+		     struct drm_device *ddev,
+		     struct drm_mode_create_dumb *args);
+
+void lsdc_gem_init(struct drm_device *ddev);
+int lsdc_show_buffer_object(struct seq_file *m, void *arg);
+
+struct drm_gem_object *
+lsdc_gem_object_create(struct drm_device *ddev,
+		       u32 domain,
+		       size_t size,
+		       bool kerenl,
+		       struct sg_table *sg,
+		       struct dma_resv *resv);
+
+#endif
drivers/gpu/drm/loongson/lsdc_gfxpll.c new file +199 -0
new file mode 100644
index 000000000000..977b12dcb73c
@@ -0,0 +1,199 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <linux/delay.h>
+
+#include <drm/drm_file.h>
+#include <drm/drm_managed.h>
+#include <drm/drm_print.h>
+
+#include "lsdc_drv.h"
+
+/*
+ * GFX PLL is the PLL used by DC, GMC and GPU, the structure of the GFX PLL
+ * may suffer from change across chip variants.
+ *
+ *
+ *                                            +-------------+  sel_out_dc
+ *                                       +----| / div_out_0 | _____/ _____ DC
+ *                                       |    +-------------+
+ * refclk   +---------+      +-------+   |    +-------------+  sel_out_gmc
+ * ---+---> | div_ref | ---> | loopc | --+--> | / div_out_1 | _____/ _____ GMC
+ *    |     +---------+      +-------+   |    +-------------+
+ *    |          /               *       |    +-------------+  sel_out_gpu
+ *    |                                  +----| / div_out_2 | _____/ _____ GPU
+ *    |                                       +-------------+
+ *    |                                                         ^
+ *    |                                                         |
+ *    +--------------------------- bypass ----------------------+
+ */
+
+struct loongson_gfxpll_bitmap {
+	/* Byte 0 ~ Byte 3 */
+	unsigned div_out_dc    : 7;  /*  6 : 0    DC output clock divider  */
+	unsigned div_out_gmc   : 7;  /* 13 : 7    GMC output clock divider */
+	unsigned div_out_gpu   : 7;  /* 20 : 14   GPU output clock divider */
+	unsigned loopc         : 9;  /* 29 : 21   clock multiplier         */
+	unsigned _reserved_1_  : 2;  /* 31 : 30                            */
+
+	/* Byte 4 ~ Byte 7 */
+	unsigned div_ref       : 7;   /* 38 : 32   Input clock divider    */
+	unsigned locked        : 1;   /* 39        PLL locked indicator   */
+	unsigned sel_out_dc    : 1;   /* 40        dc output clk enable   */
+	unsigned sel_out_gmc   : 1;   /* 41        gmc output clk enable  */
+	unsigned sel_out_gpu   : 1;   /* 42        gpu output clk enable  */
+	unsigned set_param     : 1;   /* 43        Trigger the update     */
+	unsigned bypass        : 1;   /* 44                               */
+	unsigned powerdown     : 1;   /* 45                               */
+	unsigned _reserved_2_  : 18;  /* 46 : 63   no use                 */
+};
+
+union loongson_gfxpll_reg_bitmap {
+	struct loongson_gfxpll_bitmap bitmap;
+	u32 w[2];
+	u64 d;
+};
+
+static void __gfxpll_rreg(struct loongson_gfxpll *this,
+			  union loongson_gfxpll_reg_bitmap *reg)
+{
+#if defined(CONFIG_64BIT)
+	reg->d = readq(this->mmio);
+#else
+	reg->w[0] = readl(this->mmio);
+	reg->w[1] = readl(this->mmio + 4);
+#endif
+}
+
+/* Update new parameters to the hardware */
+
+static int loongson_gfxpll_update(struct loongson_gfxpll * const this,
+				  struct loongson_gfxpll_parms const *pin)
+{
+	/* None, TODO */
+
+	return 0;
+}
+
+static void loongson_gfxpll_get_rates(struct loongson_gfxpll * const this,
+				      unsigned int *dc,
+				      unsigned int *gmc,
+				      unsigned int *gpu)
+{
+	struct loongson_gfxpll_parms *pparms = &this->parms;
+	union loongson_gfxpll_reg_bitmap gfxpll_reg;
+	unsigned int pre_output;
+	unsigned int dc_mhz;
+	unsigned int gmc_mhz;
+	unsigned int gpu_mhz;
+
+	__gfxpll_rreg(this, &gfxpll_reg);
+
+	pparms->div_ref = gfxpll_reg.bitmap.div_ref;
+	pparms->loopc = gfxpll_reg.bitmap.loopc;
+
+	pparms->div_out_dc = gfxpll_reg.bitmap.div_out_dc;
+	pparms->div_out_gmc = gfxpll_reg.bitmap.div_out_gmc;
+	pparms->div_out_gpu = gfxpll_reg.bitmap.div_out_gpu;
+
+	pre_output = pparms->ref_clock / pparms->div_ref * pparms->loopc;
+
+	dc_mhz = pre_output / pparms->div_out_dc / 1000;
+	gmc_mhz = pre_output / pparms->div_out_gmc / 1000;
+	gpu_mhz = pre_output / pparms->div_out_gpu / 1000;
+
+	if (dc)
+		*dc = dc_mhz;
+
+	if (gmc)
+		*gmc = gmc_mhz;
+
+	if (gpu)
+		*gpu = gpu_mhz;
+}
+
+static void loongson_gfxpll_print(struct loongson_gfxpll * const this,
+				  struct drm_printer *p,
+				  bool verbose)
+{
+	struct loongson_gfxpll_parms *parms = &this->parms;
+	unsigned int dc, gmc, gpu;
+
+	if (verbose) {
+		drm_printf(p, "reference clock: %u\n", parms->ref_clock);
+		drm_printf(p, "div_ref = %u\n", parms->div_ref);
+		drm_printf(p, "loopc = %u\n", parms->loopc);
+
+		drm_printf(p, "div_out_dc = %u\n", parms->div_out_dc);
+		drm_printf(p, "div_out_gmc = %u\n", parms->div_out_gmc);
+		drm_printf(p, "div_out_gpu = %u\n", parms->div_out_gpu);
+	}
+
+	this->funcs->get_rates(this, &dc, &gmc, &gpu);
+
+	drm_printf(p, "dc: %uMHz, gmc: %uMHz, gpu: %uMHz\n", dc, gmc, gpu);
+}
+
+/* GFX (DC, GPU, GMC) PLL initialization and destroy function */
+
+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)
+{
+	struct loongson_gfxpll_parms *pparms = &this->parms;
+	struct drm_printer printer = drm_info_printer(this->ddev->dev);
+
+	pparms->ref_clock = LSDC_PLL_REF_CLK;
+
+	this->mmio = ioremap(this->reg_base, this->reg_size);
+	if (IS_ERR_OR_NULL(this->mmio))
+		return -ENOMEM;
+
+	this->funcs->print(this, &printer, false);
+
+	return 0;
+}
+
+static const struct loongson_gfxpll_funcs lsdc_gmc_gpu_funcs = {
+	.init = loongson_gfxpll_init,
+	.update = loongson_gfxpll_update,
+	.get_rates = loongson_gfxpll_get_rates,
+	.print = loongson_gfxpll_print,
+};
+
+int loongson_gfxpll_create(struct drm_device *ddev,
+			   struct loongson_gfxpll **ppout)
+{
+	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;
+
+	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);
+}
drivers/gpu/drm/loongson/lsdc_gfxpll.h new file +52 -0
new file mode 100644
index 000000000000..f5eba6765812
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef __LSDC_GFXPLL_H__
+#define __LSDC_GFXPLL_H__
+
+#include <drm/drm_device.h>
+
+struct loongson_gfxpll;
+
+struct loongson_gfxpll_parms {
+	unsigned int ref_clock;
+	unsigned int div_ref;
+	unsigned int loopc;
+	unsigned int div_out_dc;
+	unsigned int div_out_gmc;
+	unsigned int div_out_gpu;
+};
+
+struct loongson_gfxpll_funcs {
+	int (*init)(struct loongson_gfxpll * const this);
+
+	int (*update)(struct loongson_gfxpll * const this,
+		      struct loongson_gfxpll_parms const *pin);
+
+	void (*get_rates)(struct loongson_gfxpll * const this,
+			  unsigned int *dc, unsigned int *gmc, unsigned int *gpu);
+
+	void (*print)(struct loongson_gfxpll * const this,
+		      struct drm_printer *printer, bool verbose);
+};
+
+struct loongson_gfxpll {
+	struct drm_device *ddev;
+	void __iomem *mmio;
+
[… more lines in the raw message]

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

drivers/gpu/drm/loongson/lsdc_i2c.c new file +179 -0
new file mode 100644
index 000000000000..d64712a46098

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

drivers/gpu/drm/loongson/lsdc_i2c.h new file +29 -0
new file mode 100644
index 000000000000..c3dadc2c423d

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

drivers/gpu/drm/loongson/lsdc_irq.c new file +71 -0
new file mode 100644
index 000000000000..e4ee0b608023

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

drivers/gpu/drm/loongson/lsdc_irq.h new file +16 -0
new file mode 100644
index 000000000000..c7003461051e

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

drivers/gpu/drm/loongson/lsdc_output.h new file +21 -0
new file mode 100644
index 000000000000..e3c375298568

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

drivers/gpu/drm/loongson/lsdc_output_7a1000.c new file +161 -0
new file mode 100644
index 000000000000..45602cc7ccf9

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

drivers/gpu/drm/loongson/lsdc_output_7a2000.c new file +531 -0
new file mode 100644
index 000000000000..ccc35283e1dc

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

drivers/gpu/drm/loongson/lsdc_pixpll.c new file +481 -0
new file mode 100644
index 000000000000..0364c49585dc

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

drivers/gpu/drm/loongson/lsdc_pixpll.h new file +86 -0
new file mode 100644
index 000000000000..06ebcdfc1733

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

drivers/gpu/drm/loongson/lsdc_plane.c new file +95 -0
new file mode 100644
index 000000000000..6d1447c7bff1

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

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

IIRC block comments should start with the first line being just "/*", with the content starting from the next line.

drivers/gpu/drm/loongson/lsdc_probe.c

Quoted 722 lines
drivers/gpu/drm/loongson/lsdc_plane.c new file +686 -0

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

drivers/gpu/drm/loongson/lsdc_probe.c new file +30 -0
new file mode 100644
index 000000000000..48ba69bb8a98

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

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

As I've noted before, this is actually not used anywhere, except seemingly when displaying some debug information. Please consider removing this altogether and add back if necessary in the future.

drivers/gpu/drm/loongson/lsdc_regs.h

Quoted 65 lines
drivers/gpu/drm/loongson/lsdc_probe.c new file +26 -0

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

drivers/gpu/drm/loongson/lsdc_probe.h new file +12 -0
new file mode 100644
index 000000000000..7a96bec49ab9

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

drivers/gpu/drm/loongson/lsdc_regs.h new file +15 -0
new file mode 100644
index 000000000000..30ff0450ddcd

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

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

Consider naming it like "LSDC_PLL_REF_CLK_KHZ" for it to be self-documenting?

drivers/gpu/drm/loongson/lsdc_regs.h

Quoted 113 lines
drivers/gpu/drm/loongson/lsdc_regs.h new file +113 -0

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

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

"CRTC1"

Quoted 995 lines
drivers/gpu/drm/loongson/lsdc_regs.h new file +274 -0

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

drivers/gpu/drm/loongson/lsdc_ttm.c new file +610 -0
new file mode 100644
index 000000000000..fd2ccf5670b1

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

drivers/gpu/drm/loongson/lsdc_ttm.h new file +99 -0
new file mode 100644
index 000000000000..6ef31d702dca

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

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

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/

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

#3 lore raw

Hi,

I love your reviews,

Quoted 8 lines · WANG Xuerui

Hi,

Someone else in a discussion group brought my attention to this series, that I've neglected for a long time because [email protected] isn't on the Cc list and I'm not subscribed to dri-devel.

While I'm reasonably familiar with LoongArch internals and Linux in general, I don't regularly tinker with the graphics things, so I'm mainly focusing on the natural language usage and general code smells for my reviews below. Pardon me if some of the questions seem silly.

(After going through the entirety of this: *please* spell-check your comment blocks, and correct obvious grammatical nits as best as you can. From my first impression, although a reader not familiar with LoongArch nor Chinese could go a long way in understanding this, some of the rest would be misunderstood, or don't make sense at all. And like 90% of the sentences are grammatically incorrect, i.e. are obvious "Chinglish". Maybe something like those ChatGPT-based services or someone in your company would help.)

OK, I didn't realize that grammar problem could up to 90%.

I'm focus on feature development previously,  I will do the grammar check before send the next version.

Quoted 2 lines

[...]

Quoted 12 lines · Sui Jingfeng
Quoted 8 lines

From: Sui Jingfeng <[email protected]>

Loongson display controller IP has been integrated in both Loongson north bridge chipset(ls7a1000/ls7a2000) and Loongson SoCs(ls2k1000/ls2k2000), it has been even included in Loongson self-made BMC products.

This display controller is a PCI device. It has two display pipes and each display pipe support a primary plane and a cursor plane. For the DC in the

"supports"

Ok, you are correct here.

Quoted 6 lines
Quoted 3 lines

ls7a1000 and ls2k1000, each display pipe has a DVO output interface which provide RGB888 signals, vertical & horizontal synchronisations and pixel

"synchronisation"

Ok, you are correct here.

Quoted 4 lines
Quoted 1 line

clock. Each CRTC is able to support 1920x1080@60Hz, the maximum resolution

"is capable of" sounds more natural?

I think they are equivalent, I can't perceive the difference.

Quoted 7 lines
Quoted 4 lines

of each display pipe is 2048x2048 according to the hardware spec.

For the DC in LS7A2000, each display pipe is equipped with a built-in HDMI encoder which is compliant with the HDMI 1.4 specification, thus it support

"supporting up to 3840x2160@30Hz"

acceptable

Quoted 5 lines
Quoted 2 lines

3840x2160@30Hz. The first display pipe is also equipped with a transparent vga encoder which is parallel with the HDMI encoder. The DC in LS7A2000 is

"The first display pipe additionally has a transparent VGA encoder"?

The first display pipe(pipe 0) also has a transparent VGA encoder.

Quoted 6 lines
Quoted 4 lines

more complete compare with the one in old chips, besides above feature, it has two hardware cursors, two hardware vblank counter and two scanout position recorders unit. It also support tiled framebuffer format which can be scanout the tiled framebuffer rendered by the LoongGPU directly.

"The DC in LS7A2000 is more feature-complete compared with the older revision: in addition to the above, it also has two hardware cursors, two hardware vblank counters and two scanout position recorders. It also supports tiled framebuffer format so the tiled output from the LoongGPU can be scanned out directly."

OK, acceptable.

#4 lore raw
In reply to WANG Xuerui

Hi,

Quoted 8 lines · WANG Xuerui
Quoted 8 lines
drivers/gpu/drm/loongson/Kconfig new file +5 -0
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_LOONGSON
+    tristate "DRM support for Loongson Graphics"
+    depends on DRM && PCI && MMU
Quoted 9 lines

drivers/gpu/drm/loongson/Kconfig line 11

Quoted 6 lines
drivers/gpu/drm/loongson/Kconfig new file +6 -0
+    select DRM_KMS_HELPER
+    select DRM_TTM
+    select I2C
+    select I2C_ALGOBIT
+    help
+      This is a DRM driver for Loongson Graphics, it may including

Drop "it may"; "including" should be enough.

'it may' is more *precise* here, because currently we don't ship with the support for loongson 2K series SoC.

I'm try to be precise as far as I can, we avoid made this driver too large by ignore loongson 2K series SoC temporary.

Quoted 6 lines

drivers/gpu/drm/loongson/Kconfig line 15

Quoted 4 lines
drivers/gpu/drm/loongson/Kconfig new file +4 -0
+      LS7A2000, LS7A1000, LS2K2000 and LS2K1000 etc. Loongson LS7A
+      series are bridge chipset, while Loongson LS2K series are SoC.
+
+      If "M" is selected, the module will be called loongson.

Just "loongson"?

Yes,  when compile this driver as module,  loongson.ko will be generated.

 drm radeon is also doing so, See drm/radeon/Kconfig.

Quoted 1 line

I know it's like this for ages (at least dating back to the MIPS days) but you really don't want to imply Loongson is mainly a GPU company. Something like "loongson_drm" or "lsdc" or "gsgpu" could be better.

No, these name may have backward compatibility problems.

Downstream driver already taken those name.

userspace driver need to differentiate them who is who.

#5 lore raw
Quoted 20 lines · Sui Jingfeng

Hi,

Quoted 8 lines · WANG Xuerui
Quoted 8 lines
drivers/gpu/drm/loongson/Kconfig new file +5 -0
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_LOONGSON
+    tristate "DRM support for Loongson Graphics"
+    depends on DRM && PCI && MMU
Quoted 9 lines

drivers/gpu/drm/loongson/Kconfig line 11

Quoted 6 lines
drivers/gpu/drm/loongson/Kconfig new file +6 -0
+    select DRM_KMS_HELPER
+    select DRM_TTM
+    select I2C
+    select I2C_ALGOBIT
+    help
+      This is a DRM driver for Loongson Graphics, it may including

Drop "it may"; "including" should be enough.

Quoted 3 lines

'it may' is more *precise* here, because currently we don't ship with the support for loongson 2K series SoC.

I'm try to be precise as far as I can, we avoid made this driver too large by ignore loongson 2K series SoC temporary.

That's a good idea! For now the patch is so large that my review reply is said to be dropped by the lists. Focusing on one bunch of similar models first then adding support for the rest not-so-similar models is very friendly towards the reviewing process and will help code quality too.

Quoted 12 lines
Quoted 7 lines

drivers/gpu/drm/loongson/Kconfig line 15

Quoted 5 lines
drivers/gpu/drm/loongson/Kconfig new file +4 -0
+      LS7A2000, LS7A1000, LS2K2000 and LS2K1000 etc. Loongson LS7A
+      series are bridge chipset, while Loongson LS2K series are SoC.
+
+      If "M" is selected, the module will be called loongson.

Just "loongson"?

Yes,  when compile this driver as module,  loongson.ko will be generated.

 drm radeon is also doing so, See drm/radeon/Kconfig.

Quoted 7 lines
Quoted 1 line

I know it's like this for ages (at least dating back to the MIPS days) but you really don't want to imply Loongson is mainly a GPU company. Something like "loongson_drm" or "lsdc" or "gsgpu" could be better.

No, these name may have backward compatibility problems.

Downstream driver already taken those name.

userspace driver need to differentiate them who is who.

IMO this shouldn't be a problem. Let me try explaining this: currently, upstream / the "new world" doesn't have any support for this driver at all, so any name will work; just use whatever is appropriate from an upstream's perspective, then make the userspace bits recognize both variants, and you'll be fine. And the "existing" userspace drivers can also carry the change, it'll just be a branch never taken in that setup.

So, I'm still in favor of keeping the upstream "clean" without dubious names like this (bare "loongson"). What do you think about my suggestion above?

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#6 lore raw
Quoted 43 lines · WANG Xuerui
Quoted 20 lines · Sui Jingfeng

Hi,

Quoted 8 lines · WANG Xuerui
Quoted 8 lines
drivers/gpu/drm/loongson/Kconfig new file +5 -0
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_LOONGSON
+    tristate "DRM support for Loongson Graphics"
+    depends on DRM && PCI && MMU
Quoted 9 lines

drivers/gpu/drm/loongson/Kconfig line 11

Quoted 6 lines
drivers/gpu/drm/loongson/Kconfig new file +6 -0
+    select DRM_KMS_HELPER
+    select DRM_TTM
+    select I2C
+    select I2C_ALGOBIT
+    help
+      This is a DRM driver for Loongson Graphics, it may including

Drop "it may"; "including" should be enough.

Quoted 3 lines

'it may' is more *precise* here, because currently we don't ship with the support for loongson 2K series SoC.

I'm try to be precise as far as I can, we avoid made this driver too large by ignore loongson 2K series SoC temporary.

That's a good idea! For now the patch is so large that my review reply is said to be dropped by the lists. Focusing on one bunch of similar models first then adding support for the rest not-so-similar models is very friendly towards the reviewing process and will help code quality too.

Quoted 16 lines
Quoted 7 lines

drivers/gpu/drm/loongson/Kconfig line 15

Quoted 5 lines
drivers/gpu/drm/loongson/Kconfig new file +4 -0
+      LS7A2000, LS7A1000, LS2K2000 and LS2K1000 etc. Loongson LS7A
+      series are bridge chipset, while Loongson LS2K series are SoC.
+
+      If "M" is selected, the module will be called loongson.

Just "loongson"?

Yes,  when compile this driver as module,  loongson.ko will be generated.

  drm radeon is also doing so, See drm/radeon/Kconfig.

Quoted 1 line

I know it's like this for ages (at least dating back to the MIPS days) but you really don't want to imply Loongson is mainly a GPU company. Something like "loongson_drm" or "lsdc" or "gsgpu" could be better.

No, these name may have backward compatibility problems.

Quoted 8 lines
Quoted 3 lines

Downstream driver already taken those name.

userspace driver need to differentiate them who is who.

IMO this shouldn't be a problem. Let me try explaining this: currently, upstream / the "new world" doesn't have any support for this driver at all, so any name will work; just use whatever is appropriate from an upstream's perspective, then make the userspace bits recognize both variants, and you'll be fine. And the "existing" userspace drivers can also carry the change, it'll just be a branch never taken in that setup.

So, I'm still in favor of keeping the upstream "clean" without dubious names like this (bare "loongson"). What do you think about my suggestion above?

No,

there is a 'arm' folder in the drivers/gpu/drm/,  It doesn't say that arm is a pure gpu company.

there is a 'ingenic' folder in the drivers/gpu/drm/, ingenic also have their own custom CPUs.

there is a 'amd' folder in the drivers/gpu/drm/, these doesn't imply amd is mainly a GPU company.

when a folder emerged in drm/, it stand for the GPU related part of this company.

#7 lore raw
Quoted 45 lines · Sui Jingfeng
Quoted 33 lines · WANG Xuerui
Quoted 32 lines · Sui Jingfeng

Hi,

Quoted 12 lines · WANG Xuerui
Quoted 12 lines
drivers/gpu/drm/loongson/Kconfig new file +9 -0
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_LOONGSON
+    tristate "DRM support for Loongson Graphics"
+    depends on DRM && PCI && MMU
+    select DRM_KMS_HELPER
+    select DRM_TTM
+    select I2C
+    select I2C_ALGOBIT
Quoted 8 lines

drivers/gpu/drm/loongson/Kconfig line 15

Quoted 6 lines
drivers/gpu/drm/loongson/Kconfig new file +6 -0
+    help
+      This is a DRM driver for Loongson Graphics, it may including
+      LS7A2000, LS7A1000, LS2K2000 and LS2K1000 etc. Loongson LS7A
+      series are bridge chipset, while Loongson LS2K series are SoC.
+
+      If "M" is selected, the module will be called loongson.

Just "loongson"?

Yes,  when compile this driver as module,  loongson.ko will be generated.

  drm radeon is also doing so, See drm/radeon/Kconfig.

Quoted 1 line

I know it's like this for ages (at least dating back to the MIPS days) but you really don't want to imply Loongson is mainly a GPU company. Something like "loongson_drm" or "lsdc" or "gsgpu" could be better.

No, these name may have backward compatibility problems.

Quoted 8 lines
Quoted 3 lines

Downstream driver already taken those name.

userspace driver need to differentiate them who is who.

IMO this shouldn't be a problem. Let me try explaining this: currently, upstream / the "new world" doesn't have any support for this driver at all, so any name will work; just use whatever is appropriate from an upstream's perspective, then make the userspace bits recognize both variants, and you'll be fine. And the "existing" userspace drivers can also carry the change, it'll just be a branch never taken in that setup.

So, I'm still in favor of keeping the upstream "clean" without dubious names like this (bare "loongson"). What do you think about my suggestion above?

No,

Quoted 7 lines

there is a 'arm' folder in the drivers/gpu/drm/,  It doesn't say that arm is a pure gpu company.

there is a 'ingenic' folder in the drivers/gpu/drm/, ingenic also have their own custom CPUs.

there is a 'amd' folder in the drivers/gpu/drm/, these doesn't imply amd is mainly a GPU company.

when a folder emerged in drm/, it stand for the GPU related part of this company.

What you said is correct, but I'm referring to the module name, instead of the directory name. For example the AMD GPU driver is called "amdgpu", not "amd"; similarly, the Ingenic DRM driver is called "ingenic-drm", not "ingenic".

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
reviewer
#8 lore raw
In reply to WANG Xuerui
Quoted 25 lines · WANG Xuerui
Quoted 23 lines · Sui Jingfeng

Hi,

Quoted 8 lines · WANG Xuerui
Quoted 8 lines
drivers/gpu/drm/loongson/Kconfig new file +5 -0
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_LOONGSON
+    tristate "DRM support for Loongson Graphics"
+    depends on DRM && PCI && MMU
Quoted 9 lines

drivers/gpu/drm/loongson/Kconfig line 11

Quoted 6 lines
drivers/gpu/drm/loongson/Kconfig new file +6 -0
+    select DRM_KMS_HELPER
+    select DRM_TTM
+    select I2C
+    select I2C_ALGOBIT
+    help
+      This is a DRM driver for Loongson Graphics, it may including

Drop "it may"; "including" should be enough.

'it may' is more *precise* here, because currently we don't ship with the support for loongson 2K series SoC.

Quoted 7 lines
Quoted 2 lines

I'm try to be precise as far as I can, we avoid made this driver too large by ignore loongson 2K series SoC temporary.

That's a good idea! For now the patch is so large that my review reply is said to be dropped by the lists. Focusing on one bunch of similar models first then adding support for the rest not-so-similar models is very friendly towards the reviewing process and will help code quality too.

I suggest split the LS2K parts to a separate patch, but keep it in the same series to get them upstreamed together.

Huacai

Quoted 39 lines
Quoted 17 lines
Quoted 8 lines

drivers/gpu/drm/loongson/Kconfig line 15

Quoted 6 lines
drivers/gpu/drm/loongson/Kconfig new file +4 -0
+      LS7A2000, LS7A1000, LS2K2000 and LS2K1000 etc. Loongson LS7A
+      series are bridge chipset, while Loongson LS2K series are SoC.
+
+      If "M" is selected, the module will be called loongson.

Just "loongson"?

Yes, when compile this driver as module, loongson.ko will be generated.

drm radeon is also doing so, See drm/radeon/Kconfig.

Quoted 3 lines

I know it's like this for ages (at least dating back to the MIPS days) but you really don't want to imply Loongson is mainly a GPU company. Something like "loongson_drm" or "lsdc" or "gsgpu" could be better.

Quoted 5 lines

No, these name may have backward compatibility problems.

Downstream driver already taken those name.

userspace driver need to differentiate them who is who.

IMO this shouldn't be a problem. Let me try explaining this: currently, upstream / the "new world" doesn't have any support for this driver at all, so any name will work; just use whatever is appropriate from an upstream's perspective, then make the userspace bits recognize both variants, and you'll be fine. And the "existing" userspace drivers can also carry the change, it'll just be a branch never taken in that setup.

So, I'm still in favor of keeping the upstream "clean" without dubious names like this (bare "loongson"). What do you think about my suggestion above?

--
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/

#9 lore raw

Hi,

Quoted 2 lines · Huacai Chen

I suggest split the LS2K parts to a separate patch, but keep it in the same series to get them upstreamed together.

Nice idea!

Yet, it is really deserve  for  a dedicated patch.

The skill and effort needed is overwhelming.

Our graphics group have limited human power,

We trying to add the support in the future, with another patch.

Thanks for the suggestion.

Quoted 1 line

Huacai

Signature · 1 line
Jingfeng
#10 lore raw
In reply to WANG Xuerui

Hi,

Quoted 29 lines · WANG Xuerui
Quoted 29 lines
(quoted diff) +2 -0
+
+      If in doubt, say "N".
drivers/gpu/drm/loongson/Makefile new file +20 -0
new file mode 100644
index 000000000000..9158816ece8e
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0
+
+loongson-y := \
+    lsdc_benchmark.o \
+    lsdc_crtc.o \
+    lsdc_debugfs.o \
+    lsdc_device.o \
+    lsdc_drv.o \
+    lsdc_gem.o \
+    lsdc_gfxpll.o \
+    lsdc_i2c.o \
+    lsdc_irq.o \
+    lsdc_output_7a1000.o \
+    lsdc_output_7a2000.o \
+    lsdc_plane.o \
+    lsdc_pixpll.o \
+    lsdc_probe.o \
+    lsdc_ttm.o
+
+obj-$(CONFIG_DRM_LOONGSON) += loongson.o
drivers/gpu/drm/loongson/lsdc_benchmark.c +0 -0
Quoted 8 lines

drivers/gpu/drm/loongson/lsdc_benchmark.c line 1

Quoted 6 lines

new file mode 100644
index 000000000000..82961531d84c

drivers/gpu/drm/loongson/lsdc_benchmark.c new file +1 -0
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0+

Is it GPL-2.0, GPL-2.0-only, or GPL-2.0+? Please make sure all license IDs are consistent.

I see drm/vkms is also writing the copyrights similar.

with "# SPDX-License-Identifier: GPL-2.0-only" in the Makefile,

while "// SPDX-License-Identifier: GPL-2.0+" in the C source file.

Sorry, I'm stupid, I can't figure out the difference between them.

Personally, I really don't care about this as along as checkpatch.pl don't complain.

I respect the maintainers of DRM, they didn't told me to change it.

I assume there is no problem.

#11 lore raw
Quoted 48 lines · Sui Jingfeng

Hi,

Quoted 29 lines · WANG Xuerui
Quoted 29 lines
(quoted diff) +2 -0
+
+      If in doubt, say "N".
drivers/gpu/drm/loongson/Makefile new file +20 -0
new file mode 100644
index 000000000000..9158816ece8e
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0
+
+loongson-y := \
+    lsdc_benchmark.o \
+    lsdc_crtc.o \
+    lsdc_debugfs.o \
+    lsdc_device.o \
+    lsdc_drv.o \
+    lsdc_gem.o \
+    lsdc_gfxpll.o \
+    lsdc_i2c.o \
+    lsdc_irq.o \
+    lsdc_output_7a1000.o \
+    lsdc_output_7a2000.o \
+    lsdc_plane.o \
+    lsdc_pixpll.o \
+    lsdc_probe.o \
+    lsdc_ttm.o
+
+obj-$(CONFIG_DRM_LOONGSON) += loongson.o
drivers/gpu/drm/loongson/lsdc_benchmark.c +0 -0
Quoted 8 lines

drivers/gpu/drm/loongson/lsdc_benchmark.c line 1

Quoted 6 lines

new file mode 100644
index 000000000000..82961531d84c

drivers/gpu/drm/loongson/lsdc_benchmark.c new file +1 -0
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0+

Is it GPL-2.0, GPL-2.0-only, or GPL-2.0+? Please make sure all license IDs are consistent.

I see drm/vkms is also writing the copyrights similar.

with "# SPDX-License-Identifier: GPL-2.0-only" in the Makefile,

while "// SPDX-License-Identifier: GPL-2.0+" in the C source file.

Quoted 7 lines

Sorry, I'm stupid, I can't figure out the difference between them.

Personally, I really don't care about this as along as checkpatch.pl don't complain.

I respect the maintainers of DRM, they didn't told me to change it.

I assume there is no problem.

It's your work after all, so you get to license the work however you want (inside the kernel project's licensing requirements, of course), so maintainers won't interfere with that.

I'm suggesting the license double-check because the whole driver is one piece of work, so it's better to be extra clear (you DO want to make sure things are clear when it comes to copyright, compliance & etc.) and make it as consistent as possible, but ultimately it's of course down to you. I think you may keep things as-is if others don't voice their concerns in the coming days.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#12 lore raw
In reply to WANG Xuerui

Hi,

Quoted 222 lines · WANG Xuerui
Quoted 222 lines
drivers/gpu/drm/loongson/lsdc_benchmark.c new file +102 -0
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <drm/drm_debugfs.h>
+
+#include "lsdc_benchmark.h"
+#include "lsdc_drv.h"
+#include "lsdc_gem.h"
+#include "lsdc_ttm.h"
+
+typedef void (*lsdc_copy_proc_t)(struct lsdc_bo *src_bo,
+                 struct lsdc_bo *dst_bo,
+                 unsigned int size,
+                 int n);
+
+static void lsdc_copy_gtt_to_vram_cpu(struct lsdc_bo *src_bo,
+                      struct lsdc_bo *dst_bo,
+                      unsigned int size,
+                      int n)
+{
+    lsdc_bo_kmap(src_bo);
+    lsdc_bo_kmap(dst_bo);
+
+    while (n--)
+        memcpy_toio(dst_bo->kptr, src_bo->kptr, size);
+
+    lsdc_bo_kunmap(src_bo);
+    lsdc_bo_kunmap(dst_bo);
+}
+
+static void lsdc_copy_vram_to_gtt_cpu(struct lsdc_bo *src_bo,
+                      struct lsdc_bo *dst_bo,
+                      unsigned int size,
+                      int n)
+{
+    lsdc_bo_kmap(src_bo);
+    lsdc_bo_kmap(dst_bo);
+
+    while (n--)
+        memcpy_fromio(dst_bo->kptr, src_bo->kptr, size);
+
+    lsdc_bo_kunmap(src_bo);
+    lsdc_bo_kunmap(dst_bo);
+}
+
+static void lsdc_copy_gtt_to_gtt_cpu(struct lsdc_bo *src_bo,
+                     struct lsdc_bo *dst_bo,
+                     unsigned int size,
+                     int n)
+{
+    lsdc_bo_kmap(src_bo);
+    lsdc_bo_kmap(dst_bo);
+
+    while (n--)
+        memcpy(dst_bo->kptr, src_bo->kptr, size);
+
+    lsdc_bo_kunmap(src_bo);
+    lsdc_bo_kunmap(dst_bo);
+}
+
+static void lsdc_benchmark_copy(struct lsdc_device *ldev,
+                unsigned int size,
+                unsigned int n,
+                u32 src_domain,
+                u32 dst_domain,
+                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;
+    unsigned long end_jiffies;
+    unsigned int throughput;
+    unsigned int time;
+
+    src_bo = lsdc_bo_create_kernel_pinned(ddev, src_domain, size);
+    dst_bo = lsdc_bo_create_kernel_pinned(ddev, dst_domain, size);
+
+    start_jiffies = jiffies;
+
+    copy_proc(src_bo, dst_bo, size, n);
+
+    end_jiffies = jiffies;
+
+    lsdc_bo_free_kernel_pinned(src_bo);
+    lsdc_bo_free_kernel_pinned(dst_bo);
+
+    time = jiffies_to_msecs(end_jiffies - start_jiffies);
+
+    throughput = (n * (size >> 10)) / time;
+
+    drm_printf(p,
+           "Copy bo of %ukB %u times from %s to %s in %ums: %uMB/s\n",
+           size >> 10, n,
+           lsdc_domain_to_str(src_domain),
+           lsdc_domain_to_str(dst_domain),
+           time, throughput);
+}
+
+int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct 

drm_printer *p)

drivers/gpu/drm/loongson/lsdc_benchmark.c new file +30 -0
+{
+    unsigned int buffer_size = 1920 * 1080 * 4;
+    unsigned int iteration = 60;
+
+    lsdc_benchmark_copy(ldev,
+                buffer_size,
+                iteration,
+                LSDC_GEM_DOMAIN_GTT,
+                LSDC_GEM_DOMAIN_GTT,
+                lsdc_copy_gtt_to_gtt_cpu,
+                p);
+
+    lsdc_benchmark_copy(ldev,
+                buffer_size,
+                iteration,
+                LSDC_GEM_DOMAIN_GTT,
+                LSDC_GEM_DOMAIN_VRAM,
+                lsdc_copy_gtt_to_vram_cpu,
+                p);
+
+    lsdc_benchmark_copy(ldev,
+                buffer_size,
+                iteration,
+                LSDC_GEM_DOMAIN_VRAM,
+                LSDC_GEM_DOMAIN_GTT,
+                lsdc_copy_vram_to_gtt_cpu,
+                p);
+
+    return 0;
+}
drivers/gpu/drm/loongson/lsdc_benchmark.h new file +11 -0
new file mode 100644
index 000000000000..2bf9406eae9c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef __LSDC_BENCHMARK_H__
+#define __LSDC_BENCHMARK_H__
+
+#include "lsdc_drv.h"
+
+int lsdc_show_benchmark_copy(struct lsdc_device *ldev, struct 

drm_printer *p);

drivers/gpu/drm/loongson/lsdc_benchmark.h new file +2 -0
+
+#endif
drivers/gpu/drm/loongson/lsdc_crtc.c new file +16 -0
new file mode 100644
index 000000000000..de2c1d514baa
@@ -0,0 +1,1066 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <linux/delay.h>
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_debugfs.h>
+#include <drm/drm_vblank.h>
+
+#include "lsdc_drv.h"
+
+/*
+ * The soft reset cause the vblank counter reset to zero, but the 

address
+ * and other settings in the crtc register remains.
+ */

drivers/gpu/drm/loongson/lsdc_crtc.c new file +43 -0
+
+static void lsdc_crtc0_soft_reset(struct lsdc_crtc *lcrtc)
+{
+    struct lsdc_device *ldev = lcrtc->ldev;
+    u32 val;
+
+    val = lsdc_rreg32(ldev, LSDC_CRTC0_CFG_REG);
+
+    val &= CFG_VALID_BITS_MASK;
+
+    /* soft reset bit, active low */
+    val &= ~CFG_RESET_N;
+
+    val &= ~CFG_PIX_FMT_MASK;
+
+    lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val);
+
+    udelay(5);
+
+    val |= CFG_RESET_N | LSDC_PF_XRGB8888 | CFG_OUTPUT_ENABLE;
+
+    lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val);
+
+    mdelay(20);
+}
+
+static void lsdc_crtc1_soft_reset(struct lsdc_crtc *lcrtc)
+{
+    struct lsdc_device *ldev = lcrtc->ldev;
+    u32 val;
+
+    val = lsdc_rreg32(ldev, LSDC_CRTC1_CFG_REG);
+
+    val &= CFG_VALID_BITS_MASK;
+
+    /* soft reset bit, active low */
+    val &= ~CFG_RESET_N;
+
+    val &= ~CFG_PIX_FMT_MASK;
+
+    lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val);
+
+    udelay(5);
Quoted 9 lines

drivers/gpu/drm/loongson/lsdc_crtc.c line 67

Quoted 6 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +6 -0
+
+    val |= CFG_RESET_N | LSDC_PF_XRGB8888 | CFG_OUTPUT_ENABLE;
+
+    lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val);
+
+    msleep(20);

So many magic sleeps without documentation?

It is just that you should wait the device for a while before it can reaction when doing the soft reset.

I think this is engineering...

Quoted 51 lines

drivers/gpu/drm/loongson/lsdc_crtc.c line 78

Quoted 11 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +11 -0
+}
+
+static void lsdc_crtc0_enable(struct lsdc_crtc *lcrtc)
+{
+    struct lsdc_device *ldev = lcrtc->ldev;
+    u32 val;
+
+    val = lsdc_rreg32(ldev, LSDC_CRTC0_CFG_REG);
+
+    /*
+     * This may happens on extremely rare case, luckily, a soft reset

"may happen on extremely rare cases;"

Quoted 1 line

+     * can helps to bring it back to normal. We add a warn here, hope

"can help bringing it back to normal. We issue a warning here, hoping to"

Quoted 20 lines

+     * to catch something if it happens.
+     */

drivers/gpu/drm/loongson/lsdc_crtc.c new file +18 -0
+
+    if (val & CRTC_ANCHORED) {
+        drm_warn(&ldev->base, "%s anchored\n", lcrtc->base.name);
+        return lsdc_crtc0_soft_reset(lcrtc);
+    }
+
+    lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val | CFG_OUTPUT_ENABLE);
+}
+
+static void lsdc_crtc0_disable(struct lsdc_crtc *lcrtc)
+{
+    struct lsdc_device *ldev = lcrtc->ldev;
+
+    lsdc_ureg32_clr(ldev, LSDC_CRTC0_CFG_REG, CFG_OUTPUT_ENABLE);
+
+    udelay(9);
+}
+

drivers/gpu/drm/loongson/lsdc_crtc.c line 109

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+static void lsdc_crtc1_enable(struct lsdc_crtc *lcrtc)
+{
+    struct lsdc_device *ldev = lcrtc->ldev;
+    u32 val;
+
+    val = lsdc_rreg32(ldev, LSDC_CRTC1_CFG_REG);
+    if (val & CRTC_ANCHORED) {
+        drm_warn(&ldev->base, "%s anchored\n", lcrtc->base.name);
+        return lsdc_crtc1_soft_reset(lcrtc);
+    }

Duplication of code? You may want to duplicate the comment here too as de-duplication with macro seems too heavy here.

Quoted 16 lines
Quoted 4 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +4 -0
+
+    lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val | CFG_OUTPUT_ENABLE);
+}
+

drivers/gpu/drm/loongson/lsdc_crtc.c line 123

Quoted 10 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +10 -0
+static void lsdc_crtc1_disable(struct lsdc_crtc *lcrtc)
+{
+    struct lsdc_device *ldev = lcrtc->ldev;
+
+    lsdc_ureg32_clr(ldev, LSDC_CRTC1_CFG_REG, CFG_OUTPUT_ENABLE);
+
+    udelay(9);
+}
+
+/* All loongson display controller support scanout position hardware */

Commit message implies only 7A2000+ LSDC IPs have the "scanout position recorders". Either that part or this code would need tweaking...

Both LS7A2000 and LS7A1000 have the scanout position recorders hardware.

Preciously, datasheet of LS7A1000 didn't told us if it support this feature.

I will adjust the commit message at next version, the code doesn't need change.

#13 lore raw
Quoted 57 lines · Sui Jingfeng

Hi,

Quoted 45 lines · WANG Xuerui
Quoted 45 lines

<snip>

drivers/gpu/drm/loongson/lsdc_crtc.c new file +43 -0
+
+static void lsdc_crtc0_soft_reset(struct lsdc_crtc *lcrtc)
+{
+    struct lsdc_device *ldev = lcrtc->ldev;
+    u32 val;
+
+    val = lsdc_rreg32(ldev, LSDC_CRTC0_CFG_REG);
+
+    val &= CFG_VALID_BITS_MASK;
+
+    /* soft reset bit, active low */
+    val &= ~CFG_RESET_N;
+
+    val &= ~CFG_PIX_FMT_MASK;
+
+    lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val);
+
+    udelay(5);
+
+    val |= CFG_RESET_N | LSDC_PF_XRGB8888 | CFG_OUTPUT_ENABLE;
+
+    lsdc_wreg32(ldev, LSDC_CRTC0_CFG_REG, val);
+
+    mdelay(20);
+}
+
+static void lsdc_crtc1_soft_reset(struct lsdc_crtc *lcrtc)
+{
+    struct lsdc_device *ldev = lcrtc->ldev;
+    u32 val;
+
+    val = lsdc_rreg32(ldev, LSDC_CRTC1_CFG_REG);
+
+    val &= CFG_VALID_BITS_MASK;
+
+    /* soft reset bit, active low */
+    val &= ~CFG_RESET_N;
+
+    val &= ~CFG_PIX_FMT_MASK;
+
+    lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val);
+
+    udelay(5);
Quoted 9 lines

drivers/gpu/drm/loongson/lsdc_crtc.c line 67

Quoted 6 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +6 -0
+
+    val |= CFG_RESET_N | LSDC_PF_XRGB8888 | CFG_OUTPUT_ENABLE;
+
+    lsdc_wreg32(ldev, LSDC_CRTC1_CFG_REG, val);
+
+    msleep(20);

So many magic sleeps without documentation?

Quoted 3 lines

It is just that you should wait the device for a while before it can reaction when doing the soft reset.

I think this is engineering...

As an engineer myself, I fully concur with this, but I mainly wanted some explanation as to "why 5 there? why 20 here? why 9 there?" -- where did all the discrete values come from, implied by HDL or found out by experimentations? Can these be extracted to properly named constants? Can some of the values get coalesced into one without harming functionality? Can some of them get shorter? -- questions like this.

Quoted 11 lines

<snip>

Quoted 4 lines

drivers/gpu/drm/loongson/lsdc_crtc.c line 123

Quoted 2 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +2 -0
+
+/* All loongson display controller support scanout position hardware */

Commit message implies only 7A2000+ LSDC IPs have the "scanout position recorders". Either that part or this code would need tweaking...

Both LS7A2000 and LS7A1000 have the scanout position recorders hardware.

Preciously, datasheet of LS7A1000 didn't told us if it support this feature.

I will adjust the commit message at next version, the code doesn't need change.

That's fine, the intent is always making the code more approachable and maintainable. Thanks.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#14 lore raw
In reply to WANG Xuerui

Hi,

Quoted 23 lines · WANG Xuerui
Quoted 23 lines

+++ b/drivers/gpu/drm/loongson/lsdc_debugfs.c

drivers/gpu/drm/loongson/lsdc_debugfs.c new file +19 -0
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <drm/drm_debugfs.h>
+
+#include "lsdc_benchmark.h"
+#include "lsdc_drv.h"
+#include "lsdc_gem.h"
+#include "lsdc_probe.h"
+#include "lsdc_ttm.h"
+
+/* device level debugfs */
+
+static int lsdc_identify(struct seq_file *m, void *arg)
+{
+    struct drm_info_node *node = (struct drm_info_node *)m->private;
+    struct lsdc_device *ldev = (struct lsdc_device 

*)node->info_ent->data;
+    const struct loongson_gfx_desc *gfx = to_loongson_gfx(ldev->descp);

Quoted 8 lines

drivers/gpu/drm/loongson/lsdc_debugfs.c line 26

Quoted 6 lines

+    u8 impl, rev;

drivers/gpu/drm/loongson/lsdc_debugfs.c new file +5 -0
+
+    loongson_cpu_get_prid(&impl, &rev);
+
+    seq_printf(m, "Running on cpu 0x%x, cpu revision: 0x%x\n",
+           impl, rev);

Is this really needed/relevant for LSDC identification? AFAICS the loongson_cpu_get_prid helper has only one use (that's here),

Yes, this is really needed, when doing the remote debugging, sometime you only have a ssh login the target machine.

User of the driver could know what the host is in the DRM way.

Quoted 1 line

so if it's not absolutely necessary you can just get rid of that function and lsdc_probe.h altogether.

This function it written for the future, It will not be removed.

Quoted 5 lines
Quoted 3 lines

+
+    seq_printf(m, "Contained in: %s\n", gfx->model);

"model: " would be more appropriate for a piece of info looking like a "gfx->model"?

No, these are nearly equivalent.

#15 lore raw
Quoted 35 lines · Sui Jingfeng

Hi,

Quoted 23 lines · WANG Xuerui
Quoted 23 lines

+++ b/drivers/gpu/drm/loongson/lsdc_debugfs.c

drivers/gpu/drm/loongson/lsdc_debugfs.c new file +19 -0
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#include <drm/drm_debugfs.h>
+
+#include "lsdc_benchmark.h"
+#include "lsdc_drv.h"
+#include "lsdc_gem.h"
+#include "lsdc_probe.h"
+#include "lsdc_ttm.h"
+
+/* device level debugfs */
+
+static int lsdc_identify(struct seq_file *m, void *arg)
+{
+    struct drm_info_node *node = (struct drm_info_node *)m->private;
+    struct lsdc_device *ldev = (struct lsdc_device 

*)node->info_ent->data;
+    const struct loongson_gfx_desc *gfx = to_loongson_gfx(ldev->descp);

Quoted 8 lines

drivers/gpu/drm/loongson/lsdc_debugfs.c line 26

Quoted 6 lines

+    u8 impl, rev;

drivers/gpu/drm/loongson/lsdc_debugfs.c new file +5 -0
+
+    loongson_cpu_get_prid(&impl, &rev);
+
+    seq_printf(m, "Running on cpu 0x%x, cpu revision: 0x%x\n",
+           impl, rev);

Is this really needed/relevant for LSDC identification? AFAICS the loongson_cpu_get_prid helper has only one use (that's here),

Quoted 3 lines

Yes, this is really needed, when doing the remote debugging, sometime you only have a ssh login the target machine.

User of the driver could know what the host is in the DRM way.

Okay, so it's unavoidable coupling of CPU and DC models, because the DC hardware revision cannot be determined by looking at its revision field alone (i.e. multiple actual HW makes behaving differently, but sharing one DC revision).

I've always hoped things were different in the LoongArch era, turns out someone has failed me :-/ Then probably you should mention the necessity of the coupling somewhere with comments.

Quoted 3 lines
Quoted 2 lines

so if it's not absolutely necessary you can just get rid of that function and lsdc_probe.h altogether.

This function it written for the future, It will not be removed.

Usually we only introduce code when necessary. For now if others are fine with this then I'd be fine too.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

+
+    seq_printf(m, "Contained in: %s\n", gfx->model);

"model: " would be more appropriate for a piece of info looking like a "gfx->model"?

No, these are nearly equivalent.

While I don't completely get why, it's mostly a stylistic recommendation so maybe it's okay anyway. It's just debug information after all.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#16 lore raw
In reply to WANG Xuerui

Hi,

Quoted 8 lines · WANG Xuerui
Quoted 5 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Quoted 1 line

Also the description about the Loongson 2K series is a bit irrelevant (we're focusing on VRAM here) so you could simplify the sentence a bit.

We could reserve part of system RAM as VRAM for Loongson 2K series SoC.

Either reserved with 'of reserve memory' or  reserved by the firmware.

The reserve ram will not accessible by kernel itself it this case, and can still be managed by ttm.

#17 lore raw
Quoted 9 lines · Sui Jingfeng

Hi,

Quoted 6 lines · WANG Xuerui
Quoted 5 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Quoted 6 lines
Quoted 1 line

Also the description about the Loongson 2K series is a bit irrelevant (we're focusing on VRAM here) so you could simplify the sentence a bit.

We could reserve part of system RAM as VRAM for Loongson 2K series SoC.

Either reserved with 'of reserve memory' or  reserved by the firmware.

What's an "of reserve memory"? Is it "DeviceTree-reserved"?

Quoted 1 line

The reserve ram will not accessible by kernel itself it this case, and can still be managed by ttm.

Of course. Feel free to tweak.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#18 lore raw

Hi,

Quoted 10 lines · WANG Xuerui
Quoted 9 lines · Sui Jingfeng

Hi,

Quoted 6 lines · WANG Xuerui
Quoted 5 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Then you get two name for a single chip,  take  LS7A1000 as an example.

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Quoted 13 lines
Quoted 6 lines
Quoted 1 line

Also the description about the Loongson 2K series is a bit irrelevant (we're focusing on VRAM here) so you could simplify the sentence a bit.

We could reserve part of system RAM as VRAM for Loongson 2K series SoC.

Either reserved with 'of reserve memory' or  reserved by the firmware.

What's an "of reserve memory"? Is it "DeviceTree-reserved"?

Quoted 1 line

The reserve ram will not accessible by kernel itself it this case, and can still be managed by ttm.

Of course. Feel free to tweak.

#19 lore raw
Quoted 19 lines · Sui Jingfeng

Hi,

Quoted 10 lines · WANG Xuerui
Quoted 9 lines · Sui Jingfeng

Hi,

Quoted 6 lines · WANG Xuerui
Quoted 5 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Quoted 7 lines

Then you get two name for a single chip,  take  LS7A1000 as an example.

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Nah, the existing convention is "LS7Xxxxx" for bridges and "Loongson 3Axxxx" for CPUs (SoCs like 2K fall under this category too). It's better to stick with existing practice so it would be familiar to long-time Loongson/LoongArch developers, but I personally don't think it will hamper understanding if you feel like doing otherwise.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#20 lore raw

Hi,

Quoted 22 lines · WANG Xuerui
Quoted 21 lines · Sui Jingfeng

Hi,

Quoted 10 lines · WANG Xuerui
Quoted 9 lines · Sui Jingfeng

Hi,

Quoted 6 lines · WANG Xuerui
Quoted 5 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Then you get two name for a single chip,  take  LS7A1000 as an example.

Quoted 8 lines
Quoted 5 lines

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Nah, the existing convention is "LS7Xxxxx" for bridges and "Loongson 3Axxxx" for CPUs (SoCs like 2K fall under this category too). It's better to stick with existing practice so it would be familiar to long-time Loongson/LoongArch developers, but I personally don't think it will hamper understanding if you feel like doing otherwise.

Can you explain why it is better?

is it that the already existing is better ?

#21 lore raw
Quoted 29 lines · Sui Jingfeng

Hi,

Quoted 26 lines · WANG Xuerui
Quoted 25 lines · Sui Jingfeng

Hi,

Quoted 10 lines · WANG Xuerui
Quoted 9 lines · Sui Jingfeng

Hi,

Quoted 6 lines · WANG Xuerui
Quoted 5 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Then you get two name for a single chip,  take  LS7A1000 as an example.

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

This also avoid bind the company name to a specific product, because a company can produce many product.

Nah, the existing convention is "LS7Xxxxx" for bridges and "Loongson 3Axxxx" for CPUs (SoCs like 2K fall under this category too). It's better to stick with existing practice so it would be familiar to long-time Loongson/LoongArch developers, but I personally don't think it will hamper understanding if you feel like doing otherwise.

Can you explain why it is better?

is it that the already existing is better ?

It's not about subjective perception of "better" or "worse", but about tree-wide consistency, and about reducing any potential confusion from newcomers. I remember Huacai once pointing out that outsiders usually have a hard time remembering "1, 2, and 3 are CPUs, some 2 are SoCs, 7 are bridge chips", and consistently referring to the bridge chips throughout the tree as "LS7A" helped.

In any case, for the sake of consistency, you can definitely refer to the CPU models in natural language like "LS3Axxxx"; just make sure to refactor for example every occurrence in arch/loongarch and other parts of drivers/. That's a lot of churn, though, so I don't expect such changes to get accepted, and that's why the tree-wide consistency should be favored over the local one.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#22 lore raw

Hi,

Quoted 34 lines · WANG Xuerui
Quoted 33 lines · Sui Jingfeng

Hi,

Quoted 30 lines · WANG Xuerui
Quoted 19 lines · Sui Jingfeng

Hi,

Quoted 10 lines · WANG Xuerui
Quoted 9 lines · Sui Jingfeng

Hi,

Quoted 6 lines · WANG Xuerui
Quoted 5 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Quoted 7 lines

Then you get two name for a single chip,  take  LS7A1000 as an example.

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Nah, the existing convention is "LS7Xxxxx" for bridges and "Loongson 3Axxxx" for CPUs (SoCs like 2K fall under this category too). It's better to stick with existing practice so it would be familiar to long-time Loongson/LoongArch developers, but I personally don't think it will hamper understanding if you feel like doing otherwise.

Quoted 8 lines
Quoted 3 lines

Can you explain why it is better?

is it that the already existing is better ?

It's not about subjective perception of "better" or "worse", but about tree-wide consistency, and about reducing any potential confusion from newcomers. I remember Huacai once pointing out that outsiders usually have a hard time remembering "1, 2, and 3 are CPUs, some 2 are SoCs, 7 are bridge chips", and consistently referring to the bridge chips throughout the tree as "LS7A" helped.

In any case, for the sake of consistency, you can definitely refer to the CPU models in natural language like "LS3Axxxx"; just make sure to refactor for example every occurrence in arch/loongarch and other parts of drivers/. That's a lot of churn, though, so I don't expect such changes to get accepted, and that's why the tree-wide consistency should be favored over the local one.

There are document[1] which named LS7A1000 bridge chip as Loongson 7A1000 Bridge,

which is opposed to what you have said "the existing convention is LS7Xxxxx for bridges".

there are also plenty projects[2] which encode ls2k1000 as project name, which simply

don't fall into the category as you have mentioned("Loongson 3Axxxx").

See [1][2] for reference, how to explain this phenomenon then?

[1] https://loongson.github.io/LoongArch-Documentation/Loongson-7A1000-usermanual-EN

[2] https://github.com/zhaozhi0810/pmon-ls2k1000-2022

#23 lore raw
Quoted 51 lines · Sui Jingfeng

Hi,

Quoted 35 lines · WANG Xuerui
Quoted 34 lines · Sui Jingfeng

Hi,

Quoted 31 lines · WANG Xuerui
Quoted 20 lines · Sui Jingfeng

Hi,

Quoted 11 lines · WANG Xuerui
Quoted 10 lines · Sui Jingfeng

Hi,

Quoted 7 lines · WANG Xuerui
Quoted 6 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Quoted 7 lines

Then you get two name for a single chip,  take  LS7A1000 as an example.

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Nah, the existing convention is "LS7Xxxxx" for bridges and "Loongson 3Axxxx" for CPUs (SoCs like 2K fall under this category too). It's better to stick with existing practice so it would be familiar to long-time Loongson/LoongArch developers, but I personally don't think it will hamper understanding if you feel like doing otherwise.

Quoted 8 lines
Quoted 3 lines

Can you explain why it is better?

is it that the already existing is better ?

It's not about subjective perception of "better" or "worse", but about tree-wide consistency, and about reducing any potential confusion from newcomers. I remember Huacai once pointing out that outsiders usually have a hard time remembering "1, 2, and 3 are CPUs, some 2 are SoCs, 7 are bridge chips", and consistently referring to the bridge chips throughout the tree as "LS7A" helped.

In any case, for the sake of consistency, you can definitely refer to the CPU models in natural language like "LS3Axxxx"; just make sure to refactor for example every occurrence in arch/loongarch and other parts of drivers/. That's a lot of churn, though, so I don't expect such changes to get accepted, and that's why the tree-wide consistency should be favored over the local one.

There are document[1] which named LS7A1000 bridge chip as Loongson 7A1000 Bridge,

which is opposed to what you have said "the existing convention is LS7Xxxxx for bridges".

Quoted 6 lines

there are also plenty projects[2] which encode ls2k1000 as project name, which simply

don't fall into the category as you have mentioned("Loongson 3Axxxx").

See [1][2] for reference, how to explain this phenomenon then?

Turn down the flames a little bit, okay? ;-)

What I'm describing is simply the kernel convention. Try grepping the commit log of linux: you can see almost all mentions of "Loongson 7A" is just referring to the manual which is named like that; that "LS3A" only ever appear as part of some board name; and that "LS2K" only briefly appearing when mentioned together with LS7A, maybe that's emphasis on the SoC's bridge part. "Loongson [123]" and "LS7A" are clearly the majority there.

But, as the convention was established by Huacai and I'm only reiterating his rules, you may instead just check with him and not continue the boring debate with me. Meanwhile maybe keeping all "LS3A" and/or "LS2K" is kind of acceptable, given such naming is etched right on the chip's packaging; I'd follow whatever Huacai mandates.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
reviewer
#24 lore raw
Quoted 95 lines · WANG Xuerui
Quoted 75 lines · Sui Jingfeng

Hi,

Quoted 58 lines · WANG Xuerui
Quoted 46 lines · Sui Jingfeng

Hi,

Quoted 36 lines · WANG Xuerui
Quoted 27 lines · Sui Jingfeng

Hi,

Quoted 14 lines · WANG Xuerui
Quoted 13 lines · Sui Jingfeng

Hi,

Quoted 10 lines · WANG Xuerui
Quoted 6 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Quoted 7 lines
Quoted 2 lines

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Then you get two name for a single chip, take LS7A1000 as an example.

Quoted 7 lines

You name it as Loongson 7A1000 in commit message, and then you have to define another name in the code, say LS7A1000.

"Loongson 7A1000" is too long, not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Quoted 7 lines

Nah, the existing convention is "LS7Xxxxx" for bridges and "Loongson 3Axxxx" for CPUs (SoCs like 2K fall under this category too). It's better to stick with existing practice so it would be familiar to long-time Loongson/LoongArch developers, but I personally don't think it will hamper understanding if you feel like doing otherwise.

Quoted 3 lines

Can you explain why it is better?

is it that the already existing is better ?

It's not about subjective perception of "better" or "worse", but about tree-wide consistency, and about reducing any potential confusion from newcomers. I remember Huacai once pointing out that outsiders usually have a hard time remembering "1, 2, and 3 are CPUs, some 2 are SoCs, 7 are bridge chips", and consistently referring to the bridge chips throughout the tree as "LS7A" helped.

Quoted 7 lines

In any case, for the sake of consistency, you can definitely refer to the CPU models in natural language like "LS3Axxxx"; just make sure to refactor for example every occurrence in arch/loongarch and other parts of drivers/. That's a lot of churn, though, so I don't expect such changes to get accepted, and that's why the tree-wide consistency should be favored over the local one.

There are document[1] which named LS7A1000 bridge chip as Loongson 7A1000 Bridge,

which is opposed to what you have said "the existing convention is LS7Xxxxx for bridges".

Quoted 7 lines

there are also plenty projects[2] which encode ls2k1000 as project name, which simply

don't fall into the category as you have mentioned("Loongson 3Axxxx").

See [1][2] for reference, how to explain this phenomenon then?

Turn down the flames a little bit, okay? ;-)

What I'm describing is simply the kernel convention. Try grepping the commit log of linux: you can see almost all mentions of "Loongson 7A" is just referring to the manual which is named like that; that "LS3A" only ever appear as part of some board name; and that "LS2K" only briefly appearing when mentioned together with LS7A, maybe that's emphasis on the SoC's bridge part. "Loongson [123]" and "LS7A" are clearly the majority there.

Quoted 5 lines

But, as the convention was established by Huacai and I'm only reiterating his rules, you may instead just check with him and not continue the boring debate with me. Meanwhile maybe keeping all "LS3A" and/or "LS2K" is kind of acceptable, given such naming is etched right on the chip's packaging; I'd follow whatever Huacai mandates.

Yes, I can confirm that.

For CPU: we always use the full name, "Loongson-3A".
For Bridge: we only use the full name when referring to the manuals, otherwise use the abbrev. name "LS7A".
For SoC: depending on scenarios, in architectural code we usually use the full name "Loongson-2K", and in drivers it is allowed to call "LS2K" to keep consistency, especially in DTS.

Huacai

Quoted 6 lines

--
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/

#25 lore raw
In reply to WANG Xuerui

Hi,

Quoted 52 lines · WANG Xuerui
Quoted 51 lines · Sui Jingfeng

Hi,

Quoted 35 lines · WANG Xuerui
Quoted 34 lines · Sui Jingfeng

Hi,

Quoted 31 lines · WANG Xuerui
Quoted 20 lines · Sui Jingfeng

Hi,

Quoted 11 lines · WANG Xuerui
Quoted 10 lines · Sui Jingfeng

Hi,

Quoted 7 lines · WANG Xuerui
Quoted 6 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Quoted 7 lines

Then you get two name for a single chip,  take  LS7A1000 as an example.

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Nah, the existing convention is "LS7Xxxxx" for bridges and "Loongson 3Axxxx" for CPUs (SoCs like 2K fall under this category too). It's better to stick with existing practice so it would be familiar to long-time Loongson/LoongArch developers, but I personally don't think it will hamper understanding if you feel like doing otherwise.

Quoted 8 lines
Quoted 3 lines

Can you explain why it is better?

is it that the already existing is better ?

It's not about subjective perception of "better" or "worse", but about tree-wide consistency, and about reducing any potential confusion from newcomers. I remember Huacai once pointing out that outsiders usually have a hard time remembering "1, 2, and 3 are CPUs, some 2 are SoCs, 7 are bridge chips", and consistently referring to the bridge chips throughout the tree as "LS7A" helped.

In any case, for the sake of consistency, you can definitely refer to the CPU models in natural language like "LS3Axxxx"; just make sure to refactor for example every occurrence in arch/loongarch and other parts of drivers/. That's a lot of churn, though, so I don't expect such changes to get accepted, and that's why the tree-wide consistency should be favored over the local one.

There are document[1] which named LS7A1000 bridge chip as Loongson 7A1000 Bridge,

which is opposed to what you have said "the existing convention is LS7Xxxxx for bridges".

Quoted 10 lines
Quoted 6 lines

there are also plenty projects[2] which encode ls2k1000 as project name, which simply

don't fall into the category as you have mentioned("Loongson 3Axxxx").

See [1][2] for reference, how to explain this phenomenon then?

Turn down the flames a little bit, okay? ;-)

There is no flames, its just that it need sufficient discussion when started to contribute to community.

We want more rigorous toward to our patch.

We can't adopt irresponsible ideas, especially from someone who is reluctant to give a

reasonable rationale and refused to discussion.

Such changes could probably made a damage to Loongson company.

As it tend to introduce self-contradictory between the code and comment.

Especially when we introduce DT support, there is no write space in the middle the string is allowed.

and encode model information to the compatible string is an common practice.

While at it, I will take it into another consideration if there are more professional person who

is supporting your ideas and could take the responsibility for it.

Beside this, other reviews are still acceptable, thanks for the reasonable part.

#26 lore raw
Quoted 72 lines · Sui Jingfeng

Hi,

Quoted 52 lines · WANG Xuerui
Quoted 51 lines · Sui Jingfeng

Hi,

Quoted 35 lines · WANG Xuerui
Quoted 34 lines · Sui Jingfeng

Hi,

Quoted 31 lines · WANG Xuerui
Quoted 20 lines · Sui Jingfeng

Hi,

Quoted 11 lines · WANG Xuerui
Quoted 10 lines · Sui Jingfeng

Hi,

Quoted 7 lines · WANG Xuerui
Quoted 6 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Quoted 7 lines

Then you get two name for a single chip,  take LS7A1000 as an example.

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Nah, the existing convention is "LS7Xxxxx" for bridges and "Loongson 3Axxxx" for CPUs (SoCs like 2K fall under this category too). It's better to stick with existing practice so it would be familiar to long-time Loongson/LoongArch developers, but I personally don't think it will hamper understanding if you feel like doing otherwise.

Quoted 8 lines
Quoted 3 lines

Can you explain why it is better?

is it that the already existing is better ?

It's not about subjective perception of "better" or "worse", but about tree-wide consistency, and about reducing any potential confusion from newcomers. I remember Huacai once pointing out that outsiders usually have a hard time remembering "1, 2, and 3 are CPUs, some 2 are SoCs, 7 are bridge chips", and consistently referring to the bridge chips throughout the tree as "LS7A" helped.

In any case, for the sake of consistency, you can definitely refer to the CPU models in natural language like "LS3Axxxx"; just make sure to refactor for example every occurrence in arch/loongarch and other parts of drivers/. That's a lot of churn, though, so I don't expect such changes to get accepted, and that's why the tree-wide consistency should be favored over the local one.

There are document[1] which named LS7A1000 bridge chip as Loongson 7A1000 Bridge,

which is opposed to what you have said "the existing convention is LS7Xxxxx for bridges".

Quoted 10 lines
Quoted 6 lines

there are also plenty projects[2] which encode ls2k1000 as project name, which simply

don't fall into the category as you have mentioned("Loongson 3Axxxx").

See [1][2] for reference, how to explain this phenomenon then?

Turn down the flames a little bit, okay? ;-)

There is no flames, its just that it need sufficient discussion when started to contribute to community.

We want more rigorous toward to our patch.

We can't adopt irresponsible ideas, especially from someone who is reluctant to give a

Quoted 9 lines

reasonable rationale and refused to discussion.

Such changes could probably made a damage to Loongson company.

As it tend to introduce self-contradictory between the code and comment.

Especially when we introduce DT support, there is no write space in the middle the string is allowed.

'write' -> 'white'

Quoted 10 lines

and encode model information to the compatible string is an common practice.

While at it, I will take it into another consideration if there are more professional person who

is supporting your ideas and could take the responsibility for it.

Beside this, other reviews are still acceptable, thanks for the reasonable part.

#27 lore raw
In reply to WANG Xuerui

Hi,

Quoted 22 lines · WANG Xuerui
Quoted 21 lines · Sui Jingfeng

Hi,

Quoted 10 lines · WANG Xuerui
Quoted 9 lines · Sui Jingfeng

Hi,

Quoted 6 lines · WANG Xuerui
Quoted 5 lines

+ * LS3A4000/LS3A5000/LS3A6000 CPU, they are equipped with on-board video RAM
+ * typically. While LS2K0500/LS2K1000/LS2K2000 are low cost SoCs which share
+ * the system RAM as video RAM, they don't has a dediacated VRAM.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

CPU models are not typically prefixed with "LS", so "Loongson 3A4000/3A5000/3A6000".

Here is because when you do programming, variable name should prefix with letters.

Commit messages, comments, and log messages etc. are natural language, so it's better to treat them differently. No problem to keep code as-is IMO.

Then you get two name for a single chip,  take  LS7A1000 as an example.

Quoted 7 lines
Quoted 5 lines

You name it as Loongson 7A1000 in commit message,  and then you have to define another name in the code,  say LS7A1000.

"Loongson 7A1000" is too long,  not as compact as LS7A1000.

This also avoid bind the company name to a specific product, because a company can produce many product.

Nah, the existing convention is "LS7Xxxxx" for bridges

But I see there are document[1] which named LS7A1000 bridge chip as Loongson 7A1000 Bridge,

See [1] for reference, who is wrong in this case?

[1] https://loongson.github.io/LoongArch-Documentation/Loongson-7A1000-usermanual-EN

#28 lore raw
In reply to WANG Xuerui

Hi,

Quoted 4 lines · WANG Xuerui
Quoted 4 lines
drivers/gpu/drm/loongson/lsdc_regs.h new file +4 -0
+#ifndef __LSDC_REGS_H__
+#define __LSDC_REGS_H__
+
+#include <linux/bitops.h>
Quoted 9 lines

drivers/gpu/drm/loongson/lsdc_regs.h line 15

Quoted 6 lines
drivers/gpu/drm/loongson/lsdc_regs.h new file +6 -0
+#include <linux/types.h>
+
+/*
+ * PIXEL PLL Reference clock
+ */
+#define LSDC_PLL_REF_CLK                100000           /* kHz */

Consider naming it like "LSDC_PLL_REF_CLK_KHZ" for it to be self-documenting?

Indeed, this is really reasonable.  Can be self-documenting.

thanks.

Quoted 114 lines
Quoted 114 lines
drivers/gpu/drm/loongson/lsdc_crtc.c new file +3 -0
+
+/*
+ * Those PLL registers are relative to LSxxxxx_CFG_REG_BASE. xxxxx = 

7A1000,
+ * 7A2000, 2K2000, 2K1000 etc.
+ */

drivers/gpu/drm/loongson/lsdc_regs.h new file +34 -0
+
+/* LS7A1000 */
+
+#define LS7A1000_PIXPLL0_REG            0x04B0
+#define LS7A1000_PIXPLL1_REG            0x04C0
+
+/* The DC, GPU, Graphic Memory Controller share the single gfxpll */
+#define LS7A1000_PLL_GFX_REG            0x0490
+
+#define LS7A1000_CONF_REG_BASE          0x10010000
+
+/* LS7A2000 */
+
+#define LS7A2000_PIXPLL0_REG            0x04B0
+#define LS7A2000_PIXPLL1_REG            0x04C0
+
+/* The DC, GPU, Graphic Memory Controller share the single gfxpll */
+#define LS7A2000_PLL_GFX_REG            0x0490
+
+#define LS7A2000_CONF_REG_BASE          0x10010000
+
+/* For LSDC_CRTCx_CFG_REG */
+#define CFG_PIX_FMT_MASK                GENMASK(2, 0)
+
+enum lsdc_pixel_format {
+    LSDC_PF_NONE = 0,
+    LSDC_PF_XRGB444 = 1,    /* [12 bits] */
+    LSDC_PF_XRGB555 = 2,    /* [15 bits] */
+    LSDC_PF_XRGB565 = 3,    /* RGB [16 bits] */
+    LSDC_PF_XRGB8888 = 4,   /* XRGB [32 bits] */
+};
+
+/*
+ * Each crtc has two set fb address registers usable, 

FB_REG_IN_USING bit of
+ * LSDC_CRTCx_CFG_REG indicate which fb address register is in using by the
+ * CRTC currently. CFG_PAGE_FLIP is used to trigger the switch, the switching
+ * will be finished at the very next vblank. Trigger it again if you want to
+ * switch back.
+ *
+ * If FB0_ADDR_REG is in using, we write the address to FB0_ADDR_REG,
+ * if FB1_ADDR_REG is in using, we write the address to FB1_ADDR_REG.
+ */

drivers/gpu/drm/loongson/lsdc_regs.h new file +8 -0
+#define CFG_PAGE_FLIP                   BIT(7)
+#define CFG_OUTPUT_ENABLE               BIT(8)
+#define CFG_HW_CLONE                    BIT(9)
+/* Indicate witch fb addr reg is in using, currently. read only */
+#define FB_REG_IN_USING                 BIT(11)
+#define CFG_GAMMA_EN                    BIT(12)
+
+/* The DC get soft reset if this bit changed from "1" to "0", active 

low */

(quoted diff) +2 -0
+#define CFG_RESET_N                     BIT(20)
+/* If this bit is set, it say that the CRTC stop working anymore, 

anchored. */

drivers/gpu/drm/loongson/lsdc_regs.h new file +50 -0
+#define CRTC_ANCHORED                   BIT(24)
+
+/*
+ * The DMA step of the DC in LS7A2000/LS2K2000 is configurable,
+ * setting those bits on ls7a1000 platform make no effect.
+ */
+#define CFG_DMA_STEP_MASK              GENMASK(17, 16)
+#define CFG_DMA_STEP_SHIFT             16
+enum lsdc_dma_steps {
+    LSDC_DMA_STEP_256_BYTES = 0,
+    LSDC_DMA_STEP_128_BYTES = 1,
+    LSDC_DMA_STEP_64_BYTES = 2,
+    LSDC_DMA_STEP_32_BYTES = 3,
+};
+
+#define CFG_VALID_BITS_MASK             GENMASK(20, 0)
+
+/* For LSDC_CRTCx_PANEL_CONF_REG */
+#define PHY_CLOCK_POL                   BIT(9)
+#define PHY_CLOCK_EN                    BIT(8)
+#define PHY_DE_POL                      BIT(1)
+#define PHY_DATA_EN                     BIT(0)
+
+/* For LSDC_CRTCx_HSYNC_REG */
+#define HSYNC_INV                       BIT(31)
+#define HSYNC_EN                        BIT(30)
+#define HSYNC_END_MASK                  GENMASK(28, 16)
+#define HSYNC_END_SHIFT                 16
+#define HSYNC_START_MASK                GENMASK(12, 0)
+#define HSYNC_START_SHIFT               0
+
+/* For LSDC_CRTCx_VSYNC_REG */
+#define VSYNC_INV                       BIT(31)
+#define VSYNC_EN                        BIT(30)
+#define VSYNC_END_MASK                  GENMASK(27, 16)
+#define VSYNC_END_SHIFT                 16
+#define VSYNC_START_MASK                GENMASK(11, 0)
+#define VSYNC_START_SHIFT               0
+
+/*********** CRTC0 & DISPLAY PIPE0 ***********/
+#define LSDC_CRTC0_CFG_REG              0x1240
+#define LSDC_CRTC0_FB0_ADDR_LO_REG      0x1260
+#define LSDC_CRTC0_FB0_ADDR_HI_REG      0x15A0
+#define LSDC_CRTC0_STRIDE_REG           0x1280
+#define LSDC_CRTC0_FB_ORIGIN_REG        0x1300
+#define LSDC_CRTC0_PANEL_CONF_REG       0x13C0
+#define LSDC_CRTC0_HDISPLAY_REG         0x1400
+#define LSDC_CRTC0_HSYNC_REG            0x1420
+#define LSDC_CRTC0_VDISPLAY_REG         0x1480
+#define LSDC_CRTC0_VSYNC_REG            0x14A0
Quoted 8 lines

drivers/gpu/drm/loongson/lsdc_regs.h line 128

Quoted 6 lines
drivers/gpu/drm/loongson/lsdc_regs.h new file +6 -0
+#define LSDC_CRTC0_GAMMA_INDEX_REG      0x14E0
+#define LSDC_CRTC0_GAMMA_DATA_REG       0x1500
+#define LSDC_CRTC0_FB1_ADDR_LO_REG      0x1580
+#define LSDC_CRTC0_FB1_ADDR_HI_REG      0x15C0
+
+/*********** CTRC1 & DISPLAY PIPE1 ***********/

"CRTC1"

Indeed, thanks for your sharpen eyes.

I will try to solve all other problems you mentioned at next version.

I don't notice this.

Great thanks.

#29 lore raw
In reply to WANG Xuerui

Hi,

Quoted 6 lines · WANG Xuerui
Quoted 6 lines
drivers/gpu/drm/loongson/lsdc_drv.c new file +6 -0
+
+static int __init loongson_module_init(void)
+{
+    struct pci_dev *pdev = NULL;
+
+    if (video_firmware_drivers_only())
Quoted 8 lines
Quoted 6 lines

+        return -ENODEV;
+
+    /* Multiple video card workaround */
+    while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev))) { +        if (pdev->vendor != PCI_VENDOR_ID_LOONGSON) {
+            pr_info("Discrete graphic card detected, abort\n");

Why is it that the iGPU cannot be used together with a dGPU? I can't see why this is technically the case so some more explanations could be beneficial to other readers and LoongArch devs.

We will remote this workaround at next version. we find some way to keep multiple GPU driver co-exixt in the system. The reason we choose to workaround is because it  is both easy and effective to solve bugs.

After the dGPU is mounted on the motherboard,

1) the integrate register don't receive write or read access anymore.  sometime cause its can't receive vblank interrupt, causing vblank timeout etc.

Have something to do with the PCI driver layer and/or PCI/vgaarb layer.

2) For ls7a1000, both the display controller and gpu is special,

    when dGPU is mounted, we are multiple gpu system.

    we should made the vgaarb works correct , this is relay on firmware and efi  support to be complete.

   In the past, our system don't support firmware framebuffer even.

3) It need us we implement PRIME, for cross driver buffer sharing.

     loongson display don't has scatter-gather able DMA. Can't access non physical contiguous GTT buffer.

    We can only expect

   1) the CPU do the copy.

   2) DC driver export dumb buffer, and GPU driver import this buffer, and resolve the tiled buffer to the linear.

   3) shared buffer has to pinned at GTT

4) Using space X server also has bug for parser the PCI device on complex patch.

5) Even on X86, there are motherboard vendor choose to black the iGPU when the dGPU is mounted.

It perhaps better black the iGPU at firmware layer.

But our firmware engineer don't know about this for a very long time.

But as its already as is, we will try to improve this at the next version.

Signature · 1 line
Jingfeng
#30 lore raw
Quoted 1 line · Sui Jingfeng

We will remote this workaround at next version.

remote -> remove

#31 lore raw

PATCH v14 2/2 MAINTAINERS: add maintainers for DRM LOONGSON driver

In reply to Sui Jingfeng

From: Sui Jingfeng <[email protected]>

This patch add Sui Jingfeng as maintainer to drm/loongson driver, also invite Thomas Zimmermann as co-maintainer.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 70d4385fd5ef..1ec3179c01ed 100644
@@ -6938,6 +6938,14 @@ T:	git git://anongit.freedesktop.org/drm/drm-misc
 F:	drivers/gpu/drm/lima/
 F:	include/uapi/drm/lima_drm.h
 
+DRM DRIVERS FOR LOONGSON
+M:	Sui Jingfeng <[email protected]>
+M:	Thomas Zimmermann <[email protected]>
+L:	[email protected]
+S:	Supported
+T:	git git://anongit.freedesktop.org/drm/drm-misc
+F:	drivers/gpu/drm/loongson/
+
 DRM DRIVERS FOR MEDIATEK
 M:	Chun-Kuang Hu <[email protected]>
 M:	Philipp Zabel <[email protected]>
Signature · 1 line
2.25.1
#32 lore raw

Re: [PATCH v14 2/2] MAINTAINERS: add maintainers for DRM LOONGSON driver

Quoted 4 lines · Sui Jingfeng

From: Sui Jingfeng <[email protected]>

This patch add Sui Jingfeng as maintainer to drm/loongson driver, also invite Thomas Zimmermann as co-maintainer.

Hmm, it could be more polite to perhaps wait a bit longer? If I didn't see it wrong you posted v14 after no more than 2 days since v13.

Quoted 11 lines
---
  MAINTAINERS | 8 ++++++++
  1 file changed, 8 insertions(+)
MAINTAINERS +0 -0
index 70d4385fd5ef..1ec3179c01ed 100644

MAINTAINERS T: git git://anongit.freedesktop.org/drm/drm-misc · line 6944

Quoted 7 lines
MAINTAINERS +4 -0
@@ -6938,6 +6938,14 @@ T:	git git://anongit.freedesktop.org/drm/drm-misc
  F:	drivers/gpu/drm/lima/
  F:	include/uapi/drm/lima_drm.h
 
+DRM DRIVERS FOR LOONGSON
+M:	Sui Jingfeng <[email protected]>
+M:	Thomas Zimmermann <[email protected]>
+L:	[email protected]

Maybe add [email protected] for notifying the LoongArch folks too? AFAIK this list is most effective at grabbing the attention of devs interested in Loongson and/or LoongArch.

Quoted 7 lines
MAINTAINERS +4 -0
+S:	Supported
+T:	git git://anongit.freedesktop.org/drm/drm-misc
+F:	drivers/gpu/drm/loongson/
+
  DRM DRIVERS FOR MEDIATEK
  M:	Chun-Kuang Hu <[email protected]>
  M:	Philipp Zabel <[email protected]>
Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#33 lore raw
In reply to Sui Jingfeng

Hi,

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Please Help!

Quoted 211 lines · Sui Jingfeng

From: Sui Jingfeng <[email protected]>

Loongson display controller IP has been integrated in both Loongson north bridge chipset(ls7a1000/ls7a2000) and Loongson SoCs(ls2k1000/ls2k2000), it has been even included in Loongson self-made BMC products.

This display controller is a PCI device. It has two display pipes and each display pipe support a primary plane and a cursor plane. For the DC in the ls7a1000 and ls2k1000, each display pipe has a DVO output interface which provide RGB888 signals, vertical & horizontal synchronisations and pixel clock. Each CRTC is able to support 1920x1080@60Hz, the maximum resolution of each display pipe is 2048x2048 according to the hardware spec.

For the DC in LS7A2000, each display pipe is equipped with a built-in HDMI encoder which is compliant with the HDMI 1.4 specification, thus it support 3840x2160@30Hz. The first display pipe is also equipped with a transparent vga encoder which is parallel with the HDMI encoder. The DC in LS7A2000 is more complete compare with the one in old chips, besides above feature, it has two hardware cursors, two hardware vblank counter and two scanout position recorders unit. It also support tiled framebuffer format which can be scanout the tiled framebuffer rendered by the LoongGPU directly.

v1 -> v2:
1) Use hpd status reg when polling for ls7a2000
2) Fix all warnings emerged when compile with W=1

v2 -> v3:
1) Add COMPILE_TEST in Kconfig and make the driver off by default
2) Alphabetical sorting headers (Thomas)
3) Untangle register access functions as much as possible (Thomas)
4) Switch to TTM based memory manager and prefer cached mapping for Loongson SoC (Thomas)
5) Add chip id detection method, now all models are distinguishable.
6) Revise builtin HDMI phy driver, nearly all main stream mode below 4K@30Hz is tested, this driver supported these mode very well including clone display mode and extend display mode.

v3 -> v4:
1) Quickly fix a small mistake.

v4 -> v5:
1) Drop potential support for Loongson 2K series SoC temporary, this part should be resend with the DT binding patch in the future.
2) Add per display pipe debugfs support to the builtin HDMI encoder.
3) Rewrite atomic_update() for hardware cursors plane(Thomas)
4) Rewrite encoder and connector initialization part, untangle it according to the chip(Thomas).

v5 -> v6:
1) Remove stray code which didn't get used, say lsdc_of_get_reserved_ram
2) Fix all typos I could found, make sentences and code more readable
3) Untangle lsdc_hdmi*_connector_detect() function according to the pipe
4) After a serious consideration, we rename this driver as loongson. Because we also have drivers toward the LoongGPU IP in LS7A2000 and LS2K2000. Besides, there are also drivers about the external encoder, HDMI audio driver and vbios support etc. This patch only provide DC driver part, my teammate Li Yi believe that loongson will be more suitable for loongson graphics than lsdc in the long run.

loongson.ko = LSDC + LoongGPU + encoders driver + vbios/DT ...

v6 -> v7:
1) Add prime support, self-sharing is works. sharing buffer with etnaviv is also tested, and its works with limitation.
2) Implement buffer objects tracking with list_head.
3) S3(sleep to RAM) is tested on ls3a5000+ls7a2000 evb and it works.
4) Rewrite lsdc_bo_move, since ttm core stop allocating resources during BO creation. Patch V1 ~ V6 of this series no longer works on latest kernel. Thus, we send V7 to revival them.

v7 -> v8:
1) Zero a compile warnnings on 32-bit platform, compile with W=1
2) Revise lsdc_bo_gpu_offset() and minor cleanup
3) Pageflip tested on the virtual terminal with following commands

     modetest -M loongson -s 32:1920x1080 -v
     modetest -M loongson -s 34:1920x1080 -v -F tiles

    It works like a charm, when running pageflip test with dual screnn
    configuration, another two additional bo created by the modetest
    emerged, VRAM usage up to 40+MB, well we have at least 64MB, still
    enough.

    # cat bos

        bo[0000]: size:     8112kB VRAM
        bo[0001]: size:       16kB VRAM
        bo[0002]: size:       16kB VRAM
        bo[0003]: size:    16208kB VRAM
        bo[0004]: size:     8112kB VRAM
        bo[0005]: size:     8112kB VRAM

v8 -> v9:
1) Select I2C and I2C_ALGOBIT in Kconfig and should depend on MMU.
2) Using pci_get_domain_bus_and_slot to get the GPU device.
3) Other minor improvements.

Those patches are tested on ls3a5000 + ls7a1000 CRB, ls3a5000 + ls7a2000 evb, and lemote a1901 board(ls3a4000 + ls7a1000). On loongson mips CPU, the write combine support should be enabled, to get a decent performance for writing framebuffer data to the VRAM.

v9 -> v10:
1) Revise lsdc_drm_freeze() to implement S3 completely and correctly. I suddenly realized that pinned buffer can not move and VRAM lost power when sleep to RAM. Thus, the data in the buffer who is pinned in VRAM will get lost when resume. Yet it's not big problem because we are software rendering solution which relay on the CPU update the front framebuffer. We can see the garbage data when resume from S3, but the screen will show correct image as I move the cursor. This is due to the cpu repaint. v10 of this patch make S3 perfect by unpin all of BOs in VRAM, evict them all to system RAM.

v10 -> v11:
1) On double screen case, the single giant framebuffer is referenced by two GEM object, hence, it will be pinned by prepare_fb() at lease two times. This cause its pin count > 1. V10 of this patch only unpin VRAM BOs once when suspend, which is not correct on double screen case. V11 of this patch unpin BOs until its pin count reach to zero when suspend. Then, we make the S3 support complete finally. With v11, I can't see any garbage data after resume. Tested on both ls7a1000 and ls7a2000 platform, with single screen and double screen configuration.
2) Fix vblank wait timeout when disable CRTC.
3) Test against IGT, at least fbdev test and kms_flip test passed.
4) Rewrite pixel PLL update function, magic numbers eliminated (Emil)
5) Drop a few common hardware features description in lsdc_desc (Emil)
6) Drop lsdc_mode_config_mode_valid(), instead add restrictions in dumb create function. (Emil)
7) Untangle the ls7a1000 case and ls7a2000 case completely (Thomas)

v11 -> v12:
none

v12 -> v13:
1) Add benchmark to figure out the bandwidth of the hardware platform. Usage:
# cd /sys/kernel/debug/dri/0/
# cat benchmark

2) VRAM is filled with garbage data if uninitialized, add a buffer clearing procedure, clear it on the BO creation time.
3) Update copyrights and adjust coding style (Huacai)

v13 -> v14:
1) Trying to add async update support for cursor plane.

Sui Jingfeng (2):
drm: add kms driver for loongson display controller
MAINTAINERS: add maintainers for DRM LOONGSON driver

  MAINTAINERS                                   |    8 +
  drivers/gpu/drm/Kconfig                       |    2 +
  drivers/gpu/drm/Makefile                      |    1 +
  drivers/gpu/drm/loongson/Kconfig              |   17 +
  drivers/gpu/drm/loongson/Makefile             |   20 +
  drivers/gpu/drm/loongson/lsdc_benchmark.c     |  133 ++
  drivers/gpu/drm/loongson/lsdc_benchmark.h     |   13 +
  drivers/gpu/drm/loongson/lsdc_crtc.c          | 1066 +++++++++++++++++
  drivers/gpu/drm/loongson/lsdc_debugfs.c       |   91 ++
  drivers/gpu/drm/loongson/lsdc_device.c        |  104 ++
  drivers/gpu/drm/loongson/lsdc_drv.c           |  495 ++++++++
  drivers/gpu/drm/loongson/lsdc_drv.h           |  451 +++++++
  drivers/gpu/drm/loongson/lsdc_gem.c           |  324 +++++
  drivers/gpu/drm/loongson/lsdc_gem.h           |   37 +
  drivers/gpu/drm/loongson/lsdc_gfxpll.c        |  199 +++
  drivers/gpu/drm/loongson/lsdc_gfxpll.h        |   52 +
  drivers/gpu/drm/loongson/lsdc_i2c.c           |  179 +++
  drivers/gpu/drm/loongson/lsdc_i2c.h           |   29 +
  drivers/gpu/drm/loongson/lsdc_irq.c           |   71 ++
  drivers/gpu/drm/loongson/lsdc_irq.h           |   16 +
  drivers/gpu/drm/loongson/lsdc_output.h        |   21 +
  drivers/gpu/drm/loongson/lsdc_output_7a1000.c |  161 +++
  drivers/gpu/drm/loongson/lsdc_output_7a2000.c |  531 ++++++++
  drivers/gpu/drm/loongson/lsdc_pixpll.c        |  481 ++++++++
  drivers/gpu/drm/loongson/lsdc_pixpll.h        |   86 ++
  drivers/gpu/drm/loongson/lsdc_plane.c         |  781 ++++++++++++
  drivers/gpu/drm/loongson/lsdc_probe.c         |   56 +
  drivers/gpu/drm/loongson/lsdc_probe.h         |   12 +
  drivers/gpu/drm/loongson/lsdc_regs.h          |  402 +++++++
  drivers/gpu/drm/loongson/lsdc_ttm.c           |  610 ++++++++++
  drivers/gpu/drm/loongson/lsdc_ttm.h           |   99 ++
  31 files changed, 6548 insertions(+)

create mode 100644 drivers/gpu/drm/loongson/Kconfig create mode 100644 drivers/gpu/drm/loongson/Makefile create mode 100644 drivers/gpu/drm/loongson/lsdc_benchmark.c create mode 100644 drivers/gpu/drm/loongson/lsdc_benchmark.h create mode 100644 drivers/gpu/drm/loongson/lsdc_crtc.c create mode 100644 drivers/gpu/drm/loongson/lsdc_debugfs.c create mode 100644 drivers/gpu/drm/loongson/lsdc_device.c create mode 100644 drivers/gpu/drm/loongson/lsdc_drv.c create mode 100644 drivers/gpu/drm/loongson/lsdc_drv.h create mode 100644 drivers/gpu/drm/loongson/lsdc_gem.c create mode 100644 drivers/gpu/drm/loongson/lsdc_gem.h create mode 100644 drivers/gpu/drm/loongson/lsdc_gfxpll.c create mode 100644 drivers/gpu/drm/loongson/lsdc_gfxpll.h create mode 100644 drivers/gpu/drm/loongson/lsdc_i2c.c create mode 100644 drivers/gpu/drm/loongson/lsdc_i2c.h create mode 100644 drivers/gpu/drm/loongson/lsdc_irq.c create mode 100644 drivers/gpu/drm/loongson/lsdc_irq.h create mode 100644 drivers/gpu/drm/loongson/lsdc_output.h create mode 100644 drivers/gpu/drm/loongson/lsdc_output_7a1000.c create mode 100644 drivers/gpu/drm/loongson/lsdc_output_7a2000.c create mode 100644 drivers/gpu/drm/loongson/lsdc_pixpll.c create mode 100644 drivers/gpu/drm/loongson/lsdc_pixpll.h create mode 100644 drivers/gpu/drm/loongson/lsdc_plane.c create mode 100644 drivers/gpu/drm/loongson/lsdc_probe.c create mode 100644 drivers/gpu/drm/loongson/lsdc_probe.h create mode 100644 drivers/gpu/drm/loongson/lsdc_regs.h create mode 100644 drivers/gpu/drm/loongson/lsdc_ttm.c create mode 100644 drivers/gpu/drm/loongson/lsdc_ttm.h

Signature · 1 line
Jingfeng
#35 lore raw

Hi,

Quoted 6 lines · Maxime Ripard

Hi,

Quoted 3 lines · Sui Jingfeng

Hi,

Quoted 7 lines
Quoted 3 lines

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Thomas already told you to merge it in the previous version:
https://lore.kernel.org/dri-devel/[email protected]/

So.. do that?

Yes, that sound fine.

But I can't do it myself, would you like to help?

Quoted 1 line

Maxime

maintainer
#36 lore raw
Quoted 12 lines · Sui Jingfeng

Hi,

Quoted 9 lines · Maxime Ripard

Hi,

Quoted 6 lines · Sui Jingfeng

Hi,

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Quoted 8 lines
Quoted 4 lines

Thomas already told you to merge it in the previous version:
https://lore.kernel.org/dri-devel/[email protected]/

So.. do that?

Yes, that sound fine.

But I can't do it myself, would you like to help?

Why can't you do it yourself?

Maxime

#37 lore raw
Quoted 13 lines · Maxime Ripard
Quoted 12 lines · Sui Jingfeng

Hi,

Quoted 9 lines · Maxime Ripard

Hi,

Quoted 6 lines · Sui Jingfeng

Hi,

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Thomas already told you to merge it in the previous version:
https://lore.kernel.org/dri-devel/[email protected]/

So.. do that?

Yes, that sound fine.

But I can't do it myself, would you like to help?

Why can't you do it yourself?

I don't have a commit access to the drm-misc,

I think, I can get the commit access in a letter time when I good enough,

But get the code merged, just merge the latest version is OK.

Quoted 1 line

Maxime

Signature · 1 line
Jingfeng
maintainer
#38 lore raw
Quoted 21 lines · Sui Jingfeng
Quoted 19 lines · Maxime Ripard
Quoted 18 lines · Sui Jingfeng

Hi,

Quoted 6 lines · Maxime Ripard

Hi,

Quoted 3 lines · Sui Jingfeng

Hi,

Quoted 7 lines
Quoted 3 lines

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Thomas already told you to merge it in the previous version:
https://lore.kernel.org/dri-devel/[email protected]/

So.. do that?

Yes, that sound fine.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

But I can't do it myself, would you like to help?

Why can't you do it yourself?

I don't have a commit access to the drm-misc,

I think, I can get the commit access in a letter time when I good enough,

But get the code merged, just merge the latest version is OK.

Look at the link in Thomas mail, it's the documentation on how to get commit access.

Maxime

#39 lore raw

Hi,

Quoted 22 lines · Maxime Ripard
Quoted 21 lines · Sui Jingfeng
Quoted 20 lines · Maxime Ripard
Quoted 19 lines · Sui Jingfeng

Hi,

Quoted 6 lines · Maxime Ripard

Hi,

Quoted 3 lines · Sui Jingfeng

Hi,

Quoted 7 lines
Quoted 3 lines

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Thomas already told you to merge it in the previous version:
https://lore.kernel.org/dri-devel/[email protected]/

So.. do that?

Yes, that sound fine.

But I can't do it myself, would you like to help?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Why can't you do it yourself?

I don't have a commit access to the drm-misc,

I think, I can get the commit access in a letter time when I good enough,

But get the code merged, just merge the latest version is OK.

Look at the link in Thomas mail, it's the documentation on how to get commit access.

I have already submit the commit access  request [1], would you like to agree?

Thanks for you and thomas.

[1] https://gitlab.freedesktop.org/freedesktop/freedesktop/-/issues/673#note_1932024

Quoted 1 line

Maxime

Signature · 1 line
Jingfeng
#40 lore raw
In reply to Maxime Ripard
Quoted 22 lines · Maxime Ripard
Quoted 21 lines · Sui Jingfeng
Quoted 20 lines · Maxime Ripard
Quoted 19 lines · Sui Jingfeng

Hi,

Quoted 6 lines · Maxime Ripard

Hi,

Quoted 3 lines · Sui Jingfeng

Hi,

Quoted 7 lines
Quoted 3 lines

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Thomas already told you to merge it in the previous version:
https://lore.kernel.org/dri-devel/[email protected]/

So.. do that?

Yes, that sound fine.

But I can't do it myself, would you like to help?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Why can't you do it yourself?

I don't have a commit access to the drm-misc,

I think, I can get the commit access in a letter time when I good enough,

But get the code merged, just merge the latest version is OK.

Look at the link in Thomas mail, it's the documentation on how to get commit access.

Can I get the commit access at a latter time?

I do not need the commit access currently.

As long as somebody can help to merge this driver is OK.

Quoted 1 line

Maxime

Signature · 1 line
Jingfeng
#41 lore raw
In reply to Maxime Ripard
Quoted 6 lines · Maxime Ripard

Hi,

Quoted 3 lines · Sui Jingfeng

Hi,

Quoted 7 lines
Quoted 3 lines

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Thomas already told you to merge it in the previous version:
https://lore.kernel.org/dri-devel/[email protected]/

So.. do that?

OK, I also want to merge this.

If there are any other problems, We and other contributor will take the responsibility to fixed it with a separate patch.

It this OK?

Quoted 1 line

Maxime

maintainer
#42 lore raw
Quoted 14 lines · Sui Jingfeng
Quoted 12 lines · Maxime Ripard

Hi,

Quoted 6 lines · Sui Jingfeng

Hi,

Any ideas for this trivial DC driver? Sorry about my broken English.

What to do next? Send a new version?

Thomas already told you to merge it in the previous version:
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 8 lines
Quoted 1 line

So.. do that?

OK, I also want to merge this.

If there are any other problems, We and other contributor will take the responsibility to fixed it with a separate patch.

It this OK?

Sure, that's pretty much how it works :)

Maxime