drm: add kms driver for loongson display controller
Subsystems (4)
v8 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 and ls7a2000) and Loongson SoCs(ls2k1000 and ls2k2000 etc), it even has been included in Loongson BMC products.
This display controller is a PCI device, it has two display pipe. For the DC in LS7A1000 and LS2K1000 each way has a DVO output interface which provide RGB888 signals, vertical & horizontal synchronisations, and the pixel clock. Each CRTC is able to support 1920x1080@60Hz, the maximum resolution 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 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, besides above feature, it has two hardware cursors, two hardware vblank counter and two scanout position recorders.
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) Untange 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 Linux 6.3.0-rc2. Thus, we send V7 to revival them.
5) Remove depends on LOONGARCH || MIPS || COMPILE_TEST to help review and compile on x86 machine.
6) Add a cover letter to help patchwork tracking my patch.
V1 ~ V4 can be found at link [1], V5 at link [2], V6 at link [3]
[1] https://patchwork.freedesktop.org/series/113566/
[2] https://patchwork.freedesktop.org/series/114386/
[3] https://patchwork.freedesktop.org/patch/524532/ 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 VRAMSui Jingfeng (2):
MAINTAINERS: add maintainers for DRM LOONGSON driver
drm: add kms driver for loongson display controller
MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/loongson/Kconfig | 15 + drivers/gpu/drm/loongson/Makefile | 16 + drivers/gpu/drm/loongson/lsdc_crtc.c | 385 ++++++++++++++++ drivers/gpu/drm/loongson/lsdc_debugfs.c | 261 +++++++++++ drivers/gpu/drm/loongson/lsdc_drv.c | 501 +++++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_drv.h | 318 +++++++++++++ drivers/gpu/drm/loongson/lsdc_gem.c | 291 ++++++++++++ drivers/gpu/drm/loongson/lsdc_gem.h | 26 ++ drivers/gpu/drm/loongson/lsdc_i2c.c | 171 +++++++ drivers/gpu/drm/loongson/lsdc_irq.c | 88 ++++ drivers/gpu/drm/loongson/lsdc_irq.h | 11 + drivers/gpu/drm/loongson/lsdc_output.c | 563 ++++++++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_output.h | 14 + drivers/gpu/drm/loongson/lsdc_plane.c | 416 +++++++++++++++++ drivers/gpu/drm/loongson/lsdc_pll.c | 338 ++++++++++++++ drivers/gpu/drm/loongson/lsdc_pll.h | 76 ++++ drivers/gpu/drm/loongson/lsdc_probe.c | 85 ++++ drivers/gpu/drm/loongson/lsdc_probe.h | 11 + drivers/gpu/drm/loongson/lsdc_regs.h | 370 ++++++++++++++++ drivers/gpu/drm/loongson/lsdc_ttm.c | 430 ++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_ttm.h | 68 +++ 24 files changed, 4464 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_crtc.c create mode 100644 drivers/gpu/drm/loongson/lsdc_debugfs.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_i2c.c 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.c create mode 100644 drivers/gpu/drm/loongson/lsdc_output.h create mode 100644 drivers/gpu/drm/loongson/lsdc_plane.c create mode 100644 drivers/gpu/drm/loongson/lsdc_pll.c create mode 100644 drivers/gpu/drm/loongson/lsdc_pll.h 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
PATCH v8 1/2 MAINTAINERS: add maintainers for DRM LOONGSON driver
From: Sui Jingfeng <[email protected]>
This patch add myself as maintainer to fix following warning when run ./scripts/checkpatch.pl
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -6909,6 +6909,13 @@ 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: suijingfeng <[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
PATCH v8 2/2 drm: add kms driver for loongson display controller
In reply to Sui JingfengFrom: Sui Jingfeng <[email protected]>
Loongson display controller IP has been integrated in both Loongson North Bridge chipset(ls7a1000 and ls7a2000) and Loongson SoCs(ls2k1000 and ls2k2000 etc), it even has been included in Loongson BMC products.
This display controller is a PCI device, it has two display pipe. For the DC in LS7A1000 and LS2K1000 each way has a DVO output interface which provide RGB888 signals, vertical & horizontal synchronisations, and the pixel clock. Each CRTC is able to support 1920x1080@60Hz, the maximum resolution 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 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, besides above feature, it has two hardware cursors, two hardware vblank counter and two scanout position recorders.
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--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/loongson/Kconfig | 15 + drivers/gpu/drm/loongson/Makefile | 16 + drivers/gpu/drm/loongson/lsdc_crtc.c | 385 ++++++++++++++++ drivers/gpu/drm/loongson/lsdc_debugfs.c | 261 +++++++++++ drivers/gpu/drm/loongson/lsdc_drv.c | 501 +++++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_drv.h | 318 +++++++++++++ drivers/gpu/drm/loongson/lsdc_gem.c | 291 ++++++++++++ drivers/gpu/drm/loongson/lsdc_gem.h | 26 ++ drivers/gpu/drm/loongson/lsdc_i2c.c | 171 +++++++ drivers/gpu/drm/loongson/lsdc_irq.c | 88 ++++ drivers/gpu/drm/loongson/lsdc_irq.h | 11 + drivers/gpu/drm/loongson/lsdc_output.c | 563 ++++++++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_output.h | 14 + drivers/gpu/drm/loongson/lsdc_plane.c | 416 +++++++++++++++++ drivers/gpu/drm/loongson/lsdc_pll.c | 338 ++++++++++++++ drivers/gpu/drm/loongson/lsdc_pll.h | 76 ++++ drivers/gpu/drm/loongson/lsdc_probe.c | 85 ++++ drivers/gpu/drm/loongson/lsdc_probe.h | 11 + drivers/gpu/drm/loongson/lsdc_regs.h | 370 ++++++++++++++++ drivers/gpu/drm/loongson/lsdc_ttm.c | 430 ++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_ttm.h | 68 +++ 23 files changed, 4457 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_crtc.c create mode 100644 drivers/gpu/drm/loongson/lsdc_debugfs.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_i2c.c 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.c create mode 100644 drivers/gpu/drm/loongson/lsdc_output.h create mode 100644 drivers/gpu/drm/loongson/lsdc_plane.c create mode 100644 drivers/gpu/drm/loongson/lsdc_pll.c create mode 100644 drivers/gpu/drm/loongson/lsdc_pll.h 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
@@ -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
@@ -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 +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 + +config DRM_LOONGSON + tristate "DRM support for Loongson Graphics" + depends on DRM && PCI + select DRM_KMS_HELPER + select DRM_TTM + 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 +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 + +loongson-y := \ + lsdc_crtc.o \ + lsdc_debugfs.o \ + lsdc_drv.o \ + lsdc_gem.o \ + lsdc_i2c.o \ + lsdc_irq.o \ + lsdc_output.o \ + lsdc_plane.o \ + lsdc_pll.o \ + lsdc_probe.o \ + lsdc_ttm.o + +obj-$(CONFIG_DRM_LOONGSON) += loongson.o
drivers/gpu/drm/loongson/lsdc_crtc.c new file +385 -0
385 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_debugfs.c new file +261 -0
261 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_drv.c new file +501 -0
501 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_drv.h new file +318 -0
318 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_gem.c new file +291 -0
291 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_gem.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#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); + +#endif
drivers/gpu/drm/loongson/lsdc_i2c.c new file +171 -0
171 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_irq.c new file +88 -0
88 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_irq.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LSDC_IRQ_H__ +#define __LSDC_IRQ_H__ + +#include <linux/irqreturn.h> + +irqreturn_t lsdc_irq_thread_handler (int irq,void *arg); +irq_handler_t lsdc_get_irq_handler (struct lsdc_device *ldev); + +#endif
drivers/gpu/drm/loongson/lsdc_output.c new file +563 -0
563 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_output.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LSDC_OUTPUT_H__ +#define __LSDC_OUTPUT_H__ + +#include "lsdc_drv.h" + +int lsdc_create_output (struct lsdc_device *ldev,struct lsdc_display_pipe *p); + +struct lsdc_i2c *lsdc_create_i2c_chan (struct drm_device *ddev, +void *base, +unsigned int index); + +#endif
drivers/gpu/drm/loongson/lsdc_plane.c new file +416 -0
328 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_pll.c new file +338 -0
338 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_pll.h new file +76 -0
76 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_probe.c new file +85 -0
85 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_probe.h new file +11 -0
Lines of this file are not shown. View the raw message.
drivers/gpu/drm/loongson/lsdc_regs.h new file +370 -0
370 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_ttm.c new file +430 -0
430 lines not on this page · raw message
drivers/gpu/drm/loongson/lsdc_ttm.h new file +68 -0
68 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.
Hi,
Welcome review, comments and discussion,
If there are issues in this driver, I will take the responsibility to resolve and revise my driver.
We are maintain three version of this drvier at downstream world,
target to linux-4.19.190, linux 5.4 kernel and linux 5.10 kernel respectively.
Our company product side using linux-4.19.190 debian 10 release, while
kylinos using 5.4, open openEuler using 5.10 kernel version.
We found surprisingly that we will pay more and more time to maintain this drivers for different kernel version as time goes,
A few personal developers also want a driver for loongson hardware, they may want to play a while occasionally.
Is there anyone willing to help upstream this trivial driver? please help!
Quoted 4,741 lines · Sui Jingfeng
From: Sui Jingfeng <[email protected]>
Loongson display controller IP has been integrated in both Loongson North Bridge chipset(ls7a1000 and ls7a2000) and Loongson SoCs(ls2k1000 and ls2k2000 etc), it even has been included in Loongson BMC products.
This display controller is a PCI device, it has two display pipe. For the DC in LS7A1000 and LS2K1000 each way has a DVO output interface which provide RGB888 signals, vertical & horizontal synchronisations, and the pixel clock. Each CRTC is able to support 1920x1080@60Hz, the maximum resolution 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 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, besides above feature, it has two hardware cursors, two hardware vblank counter and two scanout position recorders.
v1 -> v2:
1) Use hpd status reg when polling for ls7a2000
2) Fix all warnings emerged when compile with W=1v2 -> v3:
1) AddCOMPILE_TESTinKconfigand 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) Rewriteatomic_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, saylsdc_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 withlist_head.
3) S3(sleep to RAM) is tested on ls3a5000+ls7a2000 evb and it works.
4) Rewritelsdc_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 VRAMSigned-off-by Li Yi <[email protected]>Signed-off-by Sui Jingfeng <[email protected]>--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/loongson/Kconfig | 15 + drivers/gpu/drm/loongson/Makefile | 16 + drivers/gpu/drm/loongson/lsdc_crtc.c | 385 ++++++++++++++++ drivers/gpu/drm/loongson/lsdc_debugfs.c | 261 +++++++++++ drivers/gpu/drm/loongson/lsdc_drv.c | 501 +++++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_drv.h | 318 +++++++++++++ drivers/gpu/drm/loongson/lsdc_gem.c | 291 ++++++++++++ drivers/gpu/drm/loongson/lsdc_gem.h | 26 ++ drivers/gpu/drm/loongson/lsdc_i2c.c | 171 +++++++ drivers/gpu/drm/loongson/lsdc_irq.c | 88 ++++ drivers/gpu/drm/loongson/lsdc_irq.h | 11 + drivers/gpu/drm/loongson/lsdc_output.c | 563 ++++++++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_output.h | 14 + drivers/gpu/drm/loongson/lsdc_plane.c | 416 +++++++++++++++++ drivers/gpu/drm/loongson/lsdc_pll.c | 338 ++++++++++++++ drivers/gpu/drm/loongson/lsdc_pll.h | 76 ++++ drivers/gpu/drm/loongson/lsdc_probe.c | 85 ++++ drivers/gpu/drm/loongson/lsdc_probe.h | 11 + drivers/gpu/drm/loongson/lsdc_regs.h | 370 ++++++++++++++++ drivers/gpu/drm/loongson/lsdc_ttm.c | 430 ++++++++++++++++++ drivers/gpu/drm/loongson/lsdc_ttm.h | 68 +++ 23 files changed, 4457 insertions(+)create mode 100644
drivers/gpu/drm/loongson/Kconfigcreate mode 100644drivers/gpu/drm/loongson/Makefilecreate mode 100644drivers/gpu/drm/loongson/lsdc_crtc.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_debugfs.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_drv.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_drv.hcreate mode 100644drivers/gpu/drm/loongson/lsdc_gem.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_gem.hcreate mode 100644drivers/gpu/drm/loongson/lsdc_i2c.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_irq.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_irq.hcreate mode 100644drivers/gpu/drm/loongson/lsdc_output.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_output.hcreate mode 100644drivers/gpu/drm/loongson/lsdc_plane.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_pll.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_pll.hcreate mode 100644drivers/gpu/drm/loongson/lsdc_probe.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_probe.hcreate mode 100644drivers/gpu/drm/loongson/lsdc_regs.hcreate mode 100644drivers/gpu/drm/loongson/lsdc_ttm.ccreate mode 100644drivers/gpu/drm/loongson/lsdc_ttm.hdrivers/gpu/drm/Kconfig +2
-0@@ -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@@ -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 +15
-0@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 + +config DRM_LOONGSON + tristate "DRM support for Loongson Graphics" + depends on DRM && PCI + select DRM_KMS_HELPER + select DRM_TTM + 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 +16
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 + +loongson-y := \ + lsdc_crtc.o \ + lsdc_debugfs.o \ + lsdc_drv.o \ + lsdc_gem.o \ + lsdc_i2c.o \ + lsdc_irq.o \ + lsdc_output.o \ + lsdc_plane.o \ + lsdc_pll.o \ + lsdc_probe.o \ + lsdc_ttm.o + +obj-$(CONFIG_DRM_LOONGSON) += loongson.odrivers/gpu/drm/loongson/lsdc_crtc.c new file +385
-0@@ -0,0 +1,385 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <drm/drm_atomic.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_vblank.h> + +#include "lsdc_drv.h" + +static u32 lsdc_get_vblank_counter_pipe0 (struct drm_crtc *crtc) +{ +struct lsdc_device *ldev =to_lsdc (crtc->dev); + +return lsdc_rreg32 (ldev,LSDC_CRTC0_VSYNC_COUNTER_REG ); +} + +static u32 lsdc_get_vblank_counter_pipe1 (struct drm_crtc *crtc) +{ +struct lsdc_device *ldev =to_lsdc (crtc->dev); + +return lsdc_rreg32 (ldev,LSDC_CRTC1_VSYNC_COUNTER_REG ); +} + +static int lsdc_enable_vblank_pipe0 (struct drm_crtc *crtc) +{ +struct lsdc_device *ldev =to_lsdc (crtc->dev); + +lsdc_ureg32_set (ldev,LSDC_INT_REG ,INT_CRTC0_VSYNC_EN ); + +return 0 ; +} + +static void lsdc_disable_vblank_pipe0 (struct drm_crtc *crtc) +{ +struct lsdc_device *ldev =to_lsdc (crtc->dev); + +lsdc_ureg32_clr (ldev,LSDC_INT_REG ,INT_CRTC0_VSYNC_EN ); +} + +static int lsdc_enable_vblank_pipe1 (struct drm_crtc *crtc) +{ +struct lsdc_device *ldev =to_lsdc (crtc->dev); + +lsdc_ureg32_set (ldev,LSDC_INT_REG ,INT_CRTC1_VSYNC_EN ); + +return 0 ; +} + +static void lsdc_disable_vblank_pipe1 (struct drm_crtc *crtc) +{ +struct lsdc_device *ldev =to_lsdc (crtc->dev); + +lsdc_ureg32_clr (ldev,LSDC_INT_REG ,INT_CRTC1_VSYNC_EN ); +} + +static void lsdc_crtc_reset (struct drm_crtc *crtc) +{ +struct lsdc_display_pipe *dispipe =crtc_to_display_pipe (crtc); +struct drm_device *ddev = crtc->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +struct lsdc_crtc_state *priv_crtc_state; +unsigned int index = dispipe->index; +u32 val; + + val =LSDC_PF_XRGB8888 |CFG_RESET_N ; +if (ldev->descp->chip ==CHIP_LS7A2000 ) + val |=LSDC_DMA_STEP_64_BYTES ; + +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_CFG_REG , index, val); + +if (ldev->descp->chip ==CHIP_LS7A2000 ) { + val =PHY_CLOCK_EN |PHY_DATA_EN ; +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_PANEL_CONF_REG , index, val); + } + +if (crtc->state) { + priv_crtc_state =to_lsdc_crtc_state (crtc->state); +__drm_atomic_helper_crtc_destroy_state (&priv_crtc_state->base); +kfree (priv_crtc_state); + } + + priv_crtc_state =kzalloc (sizeof (*priv_crtc_state),GFP_KERNEL ); +if (!priv_crtc_state) +return ; + +__drm_atomic_helper_crtc_reset (crtc, &priv_crtc_state->base); +} + +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; +} + +#define LSDC_CRTC_FUNCS_GEN (pipe, pfn_get_vblank_counter) \ + .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, \ + .get_vblank_counter = pfn_get_vblank_counter, \ + .enable_vblank = lsdc_enable_vblank_##pipe, \ + .disable_vblank = lsdc_disable_vblank_##pipe, \ + .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp + +static const struct drm_crtc_funcs lsdc_crtc_funcs_array[2 ][LSDC_NUM_CRTC ] = { + { + { +LSDC_CRTC_FUNCS_GEN (pipe0,NULL ), + }, + { +LSDC_CRTC_FUNCS_GEN (pipe1,NULL ), + } + }, + { + { +LSDC_CRTC_FUNCS_GEN (pipe0, lsdc_get_vblank_counter_pipe0), + }, + { +LSDC_CRTC_FUNCS_GEN (pipe1, lsdc_get_vblank_counter_pipe1), + } + } +}; + +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; + +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) { +drm_dbg (ddev,"mode %dx%d, pixel clock=%d is too high\n" , + mode->hdisplay, mode->vdisplay, mode->clock); +return MODE_CLOCK_HIGH ; + } + +/* TODO: check RGB565 support, 4 for DRM_FORMAT_XRGB8888 */ +if ((mode->hdisplay *4 ) % descp->pitch_align) { +drm_dbg (ddev,"stride align to %u bytes is required\n" , + descp->pitch_align); +return MODE_BAD_WIDTH ; + } + +return MODE_OK ; +} + +static int lsdc_pixpll_atomic_check (struct drm_crtc *crtc, +struct drm_crtc_state *state) +{ +struct lsdc_display_pipe *dispipe =crtc_to_display_pipe (crtc); +struct lsdc_pll *pixpll = &dispipe->pixpll; +const struct lsdc_pixpll_funcs *pfuncs = pixpll->funcs; +struct lsdc_crtc_state *priv_state =to_lsdc_crtc_state (state); +struct lsdc_pll_parms *pout = &priv_state->pparms; +unsigned int clock = state->mode.clock; +int ret; + + ret = pfuncs->compute (pixpll, clock, pout); +if (ret) { +drm_warn (crtc->dev,"Find PLL parms for %ukHz failed\n" , clock); +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_atomic_enable (struct drm_crtc *crtc, +struct drm_atomic_state *state) +{ +struct drm_device *ddev = crtc->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +const struct lsdc_desc *descp = ldev->descp; +struct lsdc_display_pipe *dispipe =crtc_to_display_pipe (crtc); +struct lsdc_pll *pixpll = &dispipe->pixpll; +const struct lsdc_pixpll_funcs *clk_func = pixpll->funcs; +struct drm_crtc_state *crtc_state =drm_atomic_get_new_crtc_state (state, crtc); +struct lsdc_crtc_state *priv_state =to_lsdc_crtc_state (crtc_state); +struct drm_display_mode *mode = &crtc_state->mode; +unsigned int index = dispipe->index; +unsigned int width_in_bytes = mode->crtc_hdisplay *4 ; +u32 val; + +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_HDISPLAY_REG , index, + (mode->crtc_htotal <<16 ) | mode->crtc_hdisplay); + +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_VDISPLAY_REG , index, + (mode->crtc_vtotal <<16 ) | mode->crtc_vdisplay); + +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_HSYNC_REG , index, + (mode->crtc_hsync_end <<16 ) | + mode->crtc_hsync_start | +HSYNC_EN ); + +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_VSYNC_REG , index, + (mode->crtc_vsync_end <<16 ) | + mode->crtc_vsync_start | +VSYNC_EN ); + + val =lsdc_crtc_rreg32 (ldev,LSDC_CRTC0_CFG_REG , index); +/* clear old dma step settings */ + val &= ~CFG_DMA_STEP_MASK ; + +if (descp->chip ==CHIP_LS7A2000 ) { +/* +* Using large dma step as much as possible, +* for improve hardware DMA efficiency. +*/ +if (width_in_bytes %256 ==0 ) + val |=LSDC_DMA_STEP_256_BYTES ; +else if (width_in_bytes %128 ==0 ) + val |=LSDC_DMA_STEP_128_BYTES ; +else if (width_in_bytes %64 ==0 ) + val |=LSDC_DMA_STEP_64_BYTES ; +else /* width_in_bytes % 32 == 0 */ + val |=LSDC_DMA_STEP_32_BYTES ; + } + + clk_func->update (pixpll, &priv_state->pparms); + +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_CFG_REG , index, val |CFG_OUTPUT_EN ); + +drm_crtc_vblank_on (crtc); + +drm_crtc_wait_one_vblank (crtc); +} + +static void lsdc_crtc_atomic_disable (struct drm_crtc *crtc, +struct drm_atomic_state *state) +{ +struct lsdc_display_pipe *dispipe =crtc_to_display_pipe (crtc); +struct drm_device *ddev = crtc->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +unsigned int index = dispipe->index; + +lsdc_crtc_ureg32_clr (ldev,LSDC_CRTC0_CFG_REG , index,CFG_OUTPUT_EN ); + +drm_crtc_wait_one_vblank (crtc); + +drm_crtc_vblank_off (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_display_pipe *dispipe =crtc_to_display_pipe (crtc); +struct drm_device *ddev = crtc->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +unsigned int index = dispipe->index; +int line, vsw, vbp, vactive_start, vactive_end, vfp_end; +u32 val =0 ; + + 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 (); + + val =lsdc_crtc_rreg32 (ldev,LSDC_CRTC0_SCAN_POS_REG , index); + + line = (val &0xffff ); + +if (line < vactive_start) + line -= vactive_start; +else if (line > vactive_end) + line = line - vfp_end - vactive_start; +else + line -= vactive_start; + + *vpos = line; + *hpos = val >>16 ; + +if (etime) + *etime =ktime_get (); + +return true; +} + +static const struct drm_crtc_helper_funcs lsdc_crtc_helper_funcs = { + .mode_valid = lsdc_crtc_mode_valid, + .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 lsdc_crtc_init (struct drm_device *ddev, +struct drm_crtc *crtc, +struct drm_plane *primary, +struct drm_plane *cursor, +unsigned int index) +{ +struct lsdc_device *ldev =to_lsdc (ddev); +const struct lsdc_desc *descp = ldev->descp; +unsigned int has = descp->has_vblank_counter; +int ret; + + ret =drm_crtc_init_with_planes (ddev, crtc, primary, cursor, + &lsdc_crtc_funcs_array[has][index], +"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); + +drm_dbg (ddev,"%s initialized %s vblank counter support\n" , + crtc->name, has ?"with" :"without" ); + + 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 +261
-0@@ -0,0 +1,261 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <drm/drm_debugfs.h> +#include <drm/drm_gem_vram_helper.h> +#include <drm/drm_managed.h> + +#include "lsdc_drv.h" +#include "lsdc_gem.h" +#include "lsdc_probe.h" + +#ifdef CONFIG_DEBUG_FS + +static int lsdc_identify (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); +u8 imp, rev; + +loongson_cpu_get_prid (&imp, &rev); + +seq_printf (m,"I'm in %s, running on cpu 0x%x, cpu revision: 0x%x\n" , +chip_to_str (ldev->descp->chip), imp, rev); + +return 0 ; +} + +static int lsdc_show_clock (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_crtc *crtc; + +drm_for_each_crtc (crtc, ddev) { +struct lsdc_display_pipe *pipe =crtc_to_display_pipe (crtc); +struct lsdc_pll *pixpll = &pipe->pixpll; +const struct lsdc_pixpll_funcs *funcs = pixpll->funcs; +struct drm_display_mode *mode = &crtc->state->mode; +struct lsdc_pll_parms parms; +unsigned int out_khz; + + out_khz = funcs->get_clock_rate (pixpll, &parms); + +seq_printf (m,"Display pipe %u: %dx%d\n" , + pipe->index, mode->hdisplay, mode->vdisplay); + +seq_printf (m,"Frequency actually output: %u kHz\n" , out_khz); +seq_printf (m,"Pixel clock required: %d kHz\n" , mode->clock); +seq_printf (m,"diff: %d kHz\n" , out_khz - mode->clock); + +seq_printf (m,"div_ref=%u, loopc=%u, div_out=%u\n" , + parms.div_ref, parms.loopc, parms.div_out); + +seq_printf (m,"hsync_start=%d, hsync_end=%d, htotal=%d\n" , + mode->hsync_start, mode->hsync_end, mode->htotal); +seq_printf (m,"vsync_start=%d, vsync_end=%d, vtotal=%d\n\n" , + mode->vsync_start, mode->vsync_end, mode->vtotal); + } + +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 ; +} + +#define REG_DEF (reg) { __stringify_1(LSDC_##reg##_REG), LSDC_##reg##_REG } +static const struct { +const char *name; +u32 reg_offset; +} lsdc_regs_array[] = { +REG_DEF (CURSOR0_CFG ), +REG_DEF (CURSOR0_POSITION ), +REG_DEF (CURSOR0_BG_COLOR ), +REG_DEF (CURSOR0_FG_COLOR ), +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 (INT ), +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 ), +}; + +static int lsdc_show_regs (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); +int i; + +for (i =0 ; i <ARRAY_SIZE (lsdc_regs_array); i++) { +u32 offset = lsdc_regs_array[i].reg_offset; +const char *name = lsdc_regs_array[i].name; + +seq_printf (m,"%s (0x%04x): 0x%08x\n" , + name, offset,lsdc_rreg32 (ldev, offset)); + } + +return 0 ; +} + +static int lsdc_show_vblank_counter (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); + +seq_printf (m,"CRTC-0 vblank counter: %08u\n" , +lsdc_rreg32 (ldev,LSDC_CRTC0_VSYNC_COUNTER_REG )); + +seq_printf (m,"CRTC-1 vblank counter: %08u\n" , +lsdc_rreg32 (ldev,LSDC_CRTC1_VSYNC_COUNTER_REG )); + +return 0 ; +} + +static int lsdc_show_scan_position (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); +u32 p0 =lsdc_rreg32 (ldev,LSDC_CRTC0_SCAN_POS_REG ); +u32 p1 =lsdc_rreg32 (ldev,LSDC_CRTC1_SCAN_POS_REG ); + +seq_printf (m,"CRTC-0: x: %08u, y: %08u\n" , p0 >>16 , p0 &0xFFFF ); +seq_printf (m,"CRTC-1: x: %08u, y: %08u\n" , p1 >>16 , p1 &0xFFFF ); + +return 0 ; +} + +static int lsdc_show_primary_addr (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); +u32 lo, hi; +u32 val; + + val =lsdc_rreg32 (ldev,LSDC_CRTC0_CFG_REG ); +if (val &CFG_FB_IN_USING ) { + lo =lsdc_rreg32 (ldev,LSDC_CRTC0_FB1_LO_ADDR_REG ); + hi =lsdc_rreg32 (ldev,LSDC_CRTC0_FB1_HI_ADDR_REG ); +seq_printf (m,"CRTC-0 using fb1: 0x%x:%x\n" , hi, lo); + }else { + lo =lsdc_rreg32 (ldev,LSDC_CRTC0_FB0_LO_ADDR_REG ); + hi =lsdc_rreg32 (ldev,LSDC_CRTC0_FB0_HI_ADDR_REG ); +seq_printf (m,"CRTC-0 using fb0: 0x%x:%x\n" , hi, lo); + } + + val =lsdc_rreg32 (ldev,LSDC_CRTC1_CFG_REG ); +if (val &CFG_FB_IN_USING ) { + lo =lsdc_rreg32 (ldev,LSDC_CRTC1_FB1_LO_ADDR_REG ); + hi =lsdc_rreg32 (ldev,LSDC_CRTC1_FB1_HI_ADDR_REG ); +seq_printf (m,"CRTC-1 using fb1: 0x%x:%x\n" , hi, lo); + }else { + lo =lsdc_rreg32 (ldev,LSDC_CRTC1_FB0_LO_ADDR_REG ); + hi =lsdc_rreg32 (ldev,LSDC_CRTC1_FB0_HI_ADDR_REG ); +seq_printf (m,"CRTC-1 using fb0: 0x%x:%x\n" , hi, lo); + } + +return 0 ; +} + +/* To verify if TTM_PL_FLAG_TOPDOWN works */ +static int lsdc_show_cursor_addr (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); +u32 lo, hi; + + lo =lsdc_rreg32 (ldev,LSDC_CURSOR0_ADDR_LO_REG ); + hi =lsdc_rreg32 (ldev,LSDC_CURSOR0_ADDR_HI_REG ); +seq_printf (m,"CURSOR0: 0x%x:%x\n" , hi, lo); + + lo =lsdc_rreg32 (ldev,LSDC_CURSOR1_ADDR_LO_REG ); + hi =lsdc_rreg32 (ldev,LSDC_CURSOR1_ADDR_HI_REG ); +seq_printf (m,"CURSOR1: 0x%x:%x\n" , hi, lo); + +return 0 ; +} + +static int lsdc_show_stride (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); +u32 stride0 =lsdc_rreg32 (ldev,LSDC_CRTC0_STRIDE_REG ); +u32 stride1 =lsdc_rreg32 (ldev,LSDC_CRTC1_STRIDE_REG ); + +seq_printf (m,"PIPE-0 stride: %u\n" , stride0); +seq_printf (m,"PIPE-1 stride: %u\n" , stride1); + +return 0 ; +} + +static int lsdc_trigger_flip_fb (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); +u32 val; + + val =lsdc_rreg32 (ldev,LSDC_CRTC0_CFG_REG ); +lsdc_wreg32 (ldev,LSDC_CRTC0_CFG_REG , val |CFG_PAGE_FLIP ); +seq_puts (m,"CRTC-0 flip triggered\n" ); + + val =lsdc_rreg32 (ldev,LSDC_CRTC1_CFG_REG ); +lsdc_wreg32 (ldev,LSDC_CRTC1_CFG_REG , val |CFG_PAGE_FLIP ); +seq_puts (m,"CRTC-1 flip triggered\n" ); + +return 0 ; +} + +static struct drm_info_list lsdc_debugfs_list[] = { + {"chip" , lsdc_identify,0 ,NULL }, + {"clocks" , lsdc_show_clock,0 }, + {"mm" , lsdc_show_mm,0 ,NULL }, + {"regs" , lsdc_show_regs,0 }, + {"vblanks" , lsdc_show_vblank_counter,0 ,NULL }, + {"scan_pos" , lsdc_show_scan_position,0 ,NULL }, + {"fb_addr" , lsdc_show_primary_addr,0 ,NULL }, + {"cursor_addr" , lsdc_show_cursor_addr,0 ,NULL }, + {"flip" , lsdc_trigger_flip_fb,0 ,NULL }, + {"stride" , lsdc_show_stride,0 ,NULL }, + {"bos" , lsdc_show_buffer_object,0 ,NULL }, +}; + +#endif + +void lsdc_debugfs_init (struct drm_minor *minor) +{ +#ifdef CONFIG_DEBUG_FS +drm_debugfs_create_files (lsdc_debugfs_list, +ARRAY_SIZE (lsdc_debugfs_list), + minor->debugfs_root, + minor); +#endif +}drivers/gpu/drm/loongson/lsdc_drv.c new file +501
-0@@ -0,0 +1,501 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <linux/pci.h> + +#include <drm/drm_aperture.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_drv.h> +#include <drm/drm_fbdev_generic.h> +#include <drm/drm_fourcc.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> + +#include "lsdc_drv.h" +#include "lsdc_gem.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" +#define DRIVER_DESC "drm driver for loongson graphics" +#define DRIVER_DATE "20220701" +#define DRIVER_MAJOR 1 +#define DRIVER_MINOR 0 +#define DRIVER_PATCHLEVEL 0 + +static const struct lsdc_desc dc_in_ls7a1000 = { + .chip =CHIP_LS7A1000 , + .num_of_crtc =LSDC_NUM_CRTC , + .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, + .has_scan_pos = true, + .has_builtin_i2c = true, + .has_vram = true, + .has_hpd_reg = false, + .is_soc = false, +}; + +static const struct lsdc_desc dc_in_ls7a2000 = { + .chip =CHIP_LS7A2000 , + .num_of_crtc =LSDC_NUM_CRTC , + .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 use 40 for backward compatibility */ + .has_vblank_counter = true, + .has_scan_pos = true, + .has_builtin_i2c = true, + .has_vram = true, + .has_hpd_reg = true, + .is_soc = false, +}; + +const char *chip_to_str (enum loongson_chip_family chip) +{ +if (chip ==CHIP_LS7A2000 ) +return "LS7A2000" ; + +if (chip ==CHIP_LS7A1000 ) +return "LS7A1000" ; + +return "unknown" ; +} + +DEFINE_DRM_GEM_FOPS (lsdc_gem_fops); + +static const struct drm_driver lsdc_drm_driver = { + .driver_features =DRIVER_MODESET |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 enum drm_mode_status +lsdc_mode_config_mode_valid (struct drm_device *ddev, +const struct drm_display_mode *mode) +{ +struct lsdc_device *ldev =to_lsdc (ddev); +const struct drm_format_info *info =drm_format_info (DRM_FORMAT_XRGB8888 ); +u64 min_pitch =drm_format_info_min_pitch (info,0 , mode->hdisplay); +u64 fb_size = min_pitch * mode->vdisplay; + +if (fb_size *3 > ldev->vram_size) { +drm_err (ddev,"VRAM size not enough\n" ); +return MODE_MEM ; + } + +return MODE_OK ; +} + +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, + .mode_valid = lsdc_mode_config_mode_valid, +}; + +static int lsdc_modeset_init (struct lsdc_device *ldev, +const struct lsdc_desc *descp) +{ +struct drm_device *ddev = &ldev->base; +unsigned int num_crtc = descp->num_of_crtc; +unsigned int i; +int ret; + +for (i =0 ; i < num_crtc; i++) { +struct lsdc_display_pipe *dispipe = &ldev->dispipe[i]; +/* We need a index before crtc is initialized */ + dispipe->index = i; + + ret =lsdc_create_output (ldev, dispipe); +if (ret) +return ret; + + ldev->num_output++; + } + +for (i =0 ; i < num_crtc; i++) { +struct lsdc_display_pipe *dispipe = &ldev->dispipe[i]; + + ret =lsdc_pixpll_init (&dispipe->pixpll, ddev, i); +if (ret) +return ret; + + ret =lsdc_primary_plane_init (ldev, &dispipe->primary, i); +if (ret) +return ret; + + ret =lsdc_cursor_plane_init (ldev, &dispipe->cursor, i); +if (ret) +return ret; + + ret =lsdc_crtc_init (ddev, &dispipe->crtc, &dispipe->primary, &dispipe->cursor, i); +if (ret) +return ret; + } + +drm_mode_config_reset (ddev); + +drm_info (ddev,"modeset init finished, total %u outputs\n" , ldev->num_output); + +return 0 ; +} + +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 = descp->has_vram; + + ddev->mode_config.cursor_width = descp->hw_cursor_h; + ddev->mode_config.cursor_height = descp->hw_cursor_h; + +if (descp->has_vblank_counter) + ddev->max_vblank_count =0xffffffff ; + +return ret; +} + +static const struct lsdc_desc * +lsdc_detect_chip (struct pci_dev *pdev,const struct pci_device_id *ent) +{ +enum loongson_chip_family chip = ent->driver_data; + +if (chip ==CHIP_LS7A1000 ) +return &dc_in_ls7a1000; + +if (chip ==CHIP_LS7A2000 ) +return &dc_in_ls7a2000; + +return ERR_PTR (-ENODEV ); +} + +static int lsdc_get_dedicated_vram (struct lsdc_device *ldev, +const struct lsdc_desc *descp) +{ +struct drm_device *ddev = &ldev->base; +struct pci_dev *gpu; +resource_size_t base, size; + +/* +* The GPU and display controller in LS7A1000/LS7A2000 are separated +* PCIE devices, they are two devices not one. The DC does not has a +* dedicate VRAM bar, because the BIOS engineer choose to assign the +* VRAM to the GPU device. Sadly, after years application, this form +* as a convention for loongson integrated graphics. Bar 2 of the GPU +* 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). +*/ +if (descp->chip ==CHIP_LS7A1000 ) + gpu =pci_get_device (PCI_VENDOR_ID_LOONGSON ,0x7A15 ,NULL ); +else if (descp->chip ==CHIP_LS7A2000 ) + gpu =pci_get_device (PCI_VENDOR_ID_LOONGSON ,0x7A25 ,NULL ); + +if (!gpu) { +drm_warn (ddev,"No GPU device found\n" ); +return -ENODEV ; + } + + base =pci_resource_start (gpu,2 ); + size =pci_resource_len (gpu,2 ); + + ldev->vram_base = base; + ldev->vram_size = size; + +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 pci_device_id *ent, +const struct drm_driver *drv) +{ +struct lsdc_device *ldev; +struct drm_device *ddev; +const struct lsdc_desc *descp; +int ret; + + ldev = devm_drm_dev_alloc(&pdev->dev, drv, struct lsdc_device, base); +if (IS_ERR (ldev)) +return ldev; + + ddev = &ldev->base; + +pci_set_drvdata (pdev, ddev); + + descp =lsdc_detect_chip (pdev, ent); +if (IS_ERR_OR_NULL (descp)) { +drm_err (ddev,"Not known device, the driver need update!\n" ); +return NULL ; + } + +drm_info (ddev,"%s found, revision: %u" ,chip_to_str (descp->chip), pdev->revision); + + ldev->descp = descp; + +spin_lock_init (&ldev->reglock); + +/* BAR 0 of the DC device contain registers base address */ + ldev->reg_base =pcim_iomap (pdev,0 ,0 ); +if (!ldev->reg_base) +return ERR_PTR (-ENODEV ); + + ret =lsdc_get_dedicated_vram (ldev, descp); +if (ret) { +drm_err (ddev,"Init VRAM failed: %d\n" , ret); +return ERR_PTR (ret); + } + + ret =drm_aperture_remove_conflicting_framebuffers (ldev->vram_base, + ldev->vram_size, + false, + drv); +if (ret) { +drm_err (ddev,"remove firmware framebuffers failed: %d\n" , ret); +return ERR_PTR (ret); + } + + 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); + + ret =lsdc_mode_config_init (ddev, descp); +if (ret) +return ERR_PTR (ret); + + ret =lsdc_modeset_init (ldev, descp); +if (ret) +return ERR_PTR (ret); + + ret =drm_vblank_init (ddev, descp->num_of_crtc); +if (ret) +return ERR_PTR (ret); + + ret =request_threaded_irq (pdev->irq, +lsdc_get_irq_handler (ldev), + lsdc_irq_thread_handler, +IRQF_ONESHOT , +dev_name (ddev->dev), + ddev); +if (ret) { +drm_err (ddev,"Failed to register interrupt: %d\n" , 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) +{ +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; + + ldev =lsdc_create_device (pdev, ent, &lsdc_drm_driver); +if (IS_ERR (ldev)) +return PTR_ERR (ldev); + + ddev = &ldev->base; + + 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) +{ +int error; + + error =drm_mode_config_helper_suspend (ddev); +if (error) +return error; + +pci_save_state (to_pci_dev (ddev->dev)); + +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); + +if (pcim_enable_device (pdev)) +return -EIO ; + +pci_set_power_state (pdev,PCI_D0 ); + +pci_restore_state (pdev); + +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 ) +{ +struct pci_dev *pdev =NULL ; + +if (drm_firmware_drivers_only ()) +return -ENODEV ; + +/* +* We intend to write a all-in-one driver which can rules them all. +* But before this driver could provide support for loongson SoC +* formally, we would like to drop it temporarily. +*/ +if (lsdc_is_ls2k1000 () ||lsdc_is_ls2k2000 ()) +return -ENODEV ; + +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" ); +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 +318
-0@@ -0,0 +1,318 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 Loongson Corporation +* +* Authors: +* Li Yi <[email protected]> +* Sui Jingfeng <[email protected]> +*/ + +#ifndef __LSDC_DRV_H__ +#define __LSDC_DRV_H__ + +#include <linux/i2c.h> +#include <linux/i2c-algo-bit.h> + +#include <drm/drm_connector.h> +#include <drm/drm_crtc.h> +#include <drm/drm_device.h> +#include <drm/drm_encoder.h> +#include <drm/drm_plane.h> +#include <drm/ttm/ttm_device.h> + +#include "lsdc_pll.h" +#include "lsdc_regs.h" + +/* Currently, all loongson display controller has two display pipes */ +#define LSDC_NUM_CRTC 2 + +/* +* LS7A1000 and LS7A2000 function as north bridge of the LS3A4000/LS3A5000, +* They are equipped on-board Video RAM. While LS2K2000/LS2K1000 are SoC, +* they don't have dediacated Video RAM. LS7A2000 bridge chip integrated +* 32-bit DDR4@2400 video memtory controller, while it is just 16-bit DDR3 +* for LS7A1000. +* +* The display controller in LS7A2000 has two display pipe, yet it has three +* integrated encoders, display pipe 0 is attached with a transparent VGA +* encoder and a HDMI phy, 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 | +* | +------+ | |______________| +* |______________________| +* +* +* 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 | +* | -------| |_________| +* |___________________| +* +* 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. +* +* LS7A1000 and LS7A2000 can only be used with LS3A3000, LS3A4000, LS3A5000 +* desktop class CPUs, thus CPU PRID can be used to differentiate those SoC +* and the desktop level CPU on the runtime. +*/ + +enum loongson_chip_family { +CHIP_LS7A1000 =0 , +CHIP_LS7A2000 =1 , +CHIP_LAST , +}; + +struct lsdc_desc { +enum loongson_chip_family chip; +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 */ +bool has_scan_pos;/* CRTC scan position recorder */ +bool has_builtin_i2c; +bool has_vram; +bool has_hpd_reg; +bool is_soc; +}; + +struct lsdc_i2c { +struct i2c_adapter adapter; +struct i2c_algo_bit_data bit; +struct drm_device *ddev; +void __iomem *dir_reg; +void __iomem *dat_reg; +/* pin bit mask */ +u8 sda; +u8 scl; +}; + +struct lsdc_display_pipe { +struct drm_crtc crtc; +struct drm_plane primary; +struct drm_plane cursor; +struct drm_encoder encoder; +struct drm_connector connector; +struct lsdc_pll pixpll; +struct lsdc_i2c *li2c; +unsigned int index; +}; + +static inline struct lsdc_display_pipe * +crtc_to_display_pipe (struct drm_crtc *crtc) +{ + return container_of(crtc, struct lsdc_display_pipe, crtc); +} + +static inline struct lsdc_display_pipe * +primary_to_display_pipe (struct drm_plane *plane) +{ + return container_of(plane, struct lsdc_display_pipe, primary); +} + +static inline struct lsdc_display_pipe * +cursor_to_display_pipe (struct drm_plane *plane) +{ + return container_of(plane, struct lsdc_display_pipe, cursor); +} + +static inline struct lsdc_display_pipe * +connector_to_display_pipe (struct drm_connector *connector) +{ + return container_of(connector, struct lsdc_display_pipe, connector); +} + +static inline struct lsdc_display_pipe * +encoder_to_display_pipe (struct drm_encoder *encoder) +{ + return container_of(encoder, struct lsdc_display_pipe, encoder); +} + +struct lsdc_crtc_state { +struct drm_crtc_state base; +struct lsdc_pll_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; + +/* @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_size; + +struct lsdc_display_pipe dispipe[LSDC_NUM_CRTC ]; + +struct lsdc_gem gem; + +/* @num_output: count the number of active display pipe */ +unsigned int num_output; + +u32 irq_status; +}; + +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); +} + +const char *chip_to_str (enum loongson_chip_family chip); + +void lsdc_debugfs_init (struct drm_minor *minor); + +int lsdc_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 lsdc_device *ldev, +struct drm_plane *plane, +unsigned int index); + +int lsdc_cursor_plane_init (struct lsdc_device *ldev, +struct drm_plane *plane, +unsigned int index); + +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 bit) +{ +void __iomem *addr = ldev->reg_base + offset; +u32 val =readl (addr); + +writel (val | bit, addr); +} + +static inline void lsdc_ureg32_clr (struct lsdc_device *ldev, +u32 offset, +u32 bit) +{ +void __iomem *addr = ldev->reg_base + offset; +u32 val =readl (addr); + +writel (val & ~bit, 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 ); +} + +#define lsdc_hdmi_rreg32 lsdc_pipe_rreg32 +#define lsdc_crtc_rreg32 lsdc_pipe_rreg32 + +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 ); +} + +#define lsdc_hdmi_wreg32 lsdc_pipe_wreg32 +#define lsdc_crtc_wreg32 lsdc_pipe_wreg32 + +static inline void lsdc_crtc_ureg32_set (struct lsdc_device *ldev, +u32 offset, +u32 pipe, +u32 bit) +{ +void __iomem *addr; +u32 val; + + addr = ldev->reg_base + offset + pipe *CRTC_PIPE_OFFSET ; + val =readl (addr); +writel (val | bit, addr); +} + +static inline void lsdc_crtc_ureg32_clr (struct lsdc_device *ldev, +u32 offset, +u32 pipe, +u32 bit) +{ +void __iomem *addr; +u32 val; + + addr = ldev->reg_base + offset + pipe *CRTC_PIPE_OFFSET ; + val =readl (addr); +writel (val & ~bit, addr); +} + +#endif drivers/gpu/drm/loongson/lsdc_gem.c new file +291
-0@@ -0,0 +1,291 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#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 ttm_buffer_object *tbo =to_ttm_bo (obj); +struct lsdc_bo *lbo =to_lsdc_bo (tbo); +int ret; + + ret =lsdc_bo_pin (lbo,LSDC_GEM_DOMAIN_GTT ,NULL ); +if (unlikely (ret)) +return ret; + + lbo->sharing_count++; + +return 0 ; +} + +static void lsdc_gem_prime_unpin (struct drm_gem_object *obj) +{ +struct lsdc_bo *lbo =gem_to_lsdc_bo (obj); + +lsdc_bo_unpin (lbo); +if (lbo->sharing_count) + lbo->sharing_count--; +} + +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 (tbo->pin_count ==0 ) { +struct ttm_operation_ctx ctx = { false, false }; + + ret =ttm_bo_validate (tbo, &lbo->placement, &ctx); +if (ret <0 ) +return ret; + } + +ttm_bo_pin (tbo); + +if (lbo->vmap_count >0 ) { + ++lbo->vmap_count; + goto out; + } + +/* Only vmap if the there's no mapping present */ +if (iosys_map_is_null (&lbo->map)) { + ret =ttm_bo_vmap (tbo, &lbo->map); +if (ret) { +ttm_bo_unpin (tbo); +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 drm_device *ddev = obj->dev; +struct ttm_buffer_object *tbo =to_ttm_bo (obj); +struct lsdc_bo *lbo =to_lsdc_bo (tbo); + +if (unlikely (!lbo->vmap_count)) { +drm_warn (ddev,"%p is not mapped" , lbo); +return ; + } + + --lbo->vmap_count; +if (lbo->vmap_count >0 ) +return ; + +ttm_bo_vunmap (tbo, &lbo->map); + +ttm_bo_unpin (tbo); +} + +static int lsdc_gem_object_mmap (struct drm_gem_object *gem, +struct vm_area_struct *vma) +{ +struct ttm_buffer_object *tbo =to_ttm_bo (gem); +int ret; + + ret =ttm_bo_mmap_obj (vma, tbo); +if (ret <0 ) +return ret; + +drm_gem_object_put (gem); + +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, +}; + +static struct drm_gem_object * +lsdc_gem_object_create (struct drm_device *ddev, +u32 domain, +size_t size, +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, false,NULL ,NULL ); +if (IS_ERR (lbo)) { + ret =PTR_ERR (lbo); +return ERR_PTR (ret); + } + + 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, 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; +struct drm_gem_object *gobj; +size_t pitch, size; +u32 handle; +int ret; + + pitch = args->width *DIV_ROUND_UP (args->bpp,8 ); + pitch =ALIGN (pitch, descp->pitch_align); + size = pitch * args->height; + size =roundup (size,PAGE_SIZE ); + +if (!size) +return -EINVAL ; + + gobj =lsdc_gem_object_create (ddev, +LSDC_GEM_DOMAIN_VRAM , + size, +NULL , +NULL ); +if (IS_ERR (gobj)) +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) +{ +#ifdef CONFIG_DEBUG_FS +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 =0 ; + +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; + +seq_printf (m,"bo[%04u]: size: %8ukB %s\n" , + i, + (unsigned int )(lsdc_bo_size (tbo) >>10 ), +lsdc_mem_type_to_str (resource->mem_type)); + + i++; + } + +mutex_unlock (&ldev->gem.mutex); +#endif +return 0 ; +}drivers/gpu/drm/loongson/lsdc_gem.h new file +26
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#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); + +#endif drivers/gpu/drm/loongson/lsdc_i2c.c new file +171
-0@@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <drm/drm_managed.h> + +#include "lsdc_drv.h" +#include "lsdc_output.h" + +/* +* ls7a_gpio_i2c_set - set the state of a gpio pin indicated by mask +* @mask: gpio pin mask +* @state: "0" for low, "1" for high +*/ +static void ls7a_gpio_i2c_set (struct lsdc_i2c *const li2c,int mask,int state) +{ +struct lsdc_device *ldev =to_lsdc (li2c->ddev); +unsigned long flags; +u8 val; + +spin_lock_irqsave (&ldev->reglock, flags); + +if (state) { +/* +* Setting this pin as input directly, write 1 for Input. +* The external pull-up resistor will pull the level up +*/ + val =readb (li2c->dir_reg); + val |= mask; +writeb (val, li2c->dir_reg); + }else { +/* First set this pin as output, write 0 for Output */ + val =readb (li2c->dir_reg); + val &= ~mask; +writeb (val, li2c->dir_reg); + +/* Then, make this pin output 0 */ + val =readb (li2c->dat_reg); + val &= ~mask; +writeb (val, li2c->dat_reg); + } + +spin_unlock_irqrestore (&ldev->reglock, flags); +} + +/* +* ls7a_gpio_i2c_get - read value back from the gpio pin indicated by mask +* @mask: gpio pin mask +* return "0" for low, "1" for high +*/ +static int ls7a_gpio_i2c_get (struct lsdc_i2c *const li2c,int mask) +{ +struct lsdc_device *ldev =to_lsdc (li2c->ddev); +unsigned long flags; +u8 val; + +spin_lock_irqsave (&ldev->reglock, flags); + +/* First set this pin as input */ + val =readb (li2c->dir_reg); + val |= mask; +writeb (val, li2c->dir_reg); + +/* Then get level state from this pin */ + val =readb (li2c->dat_reg); + +spin_unlock_irqrestore (&ldev->reglock, flags); + +return (val & mask) ?1 :0 ; +} + +static void ls7a_i2c_set_sda (void *i2c,int state) +{ +struct lsdc_i2c *const li2c = (struct lsdc_i2c *)i2c; +/* set state on the li2c->sda pin */ +return ls7a_gpio_i2c_set (li2c, li2c->sda, state); +} + +static void ls7a_i2c_set_scl (void *i2c,int state) +{ +struct lsdc_i2c *const li2c = (struct lsdc_i2c *)i2c; +/* set state on the li2c->scl pin */ +return ls7a_gpio_i2c_set (li2c, li2c->scl, state); +} + +static int ls7a_i2c_get_sda (void *i2c) +{ +struct lsdc_i2c *const li2c = (struct lsdc_i2c *)i2c; +/* read value from the li2c->sda pin */ +return ls7a_gpio_i2c_get (li2c, li2c->sda); +} + +static int ls7a_i2c_get_scl (void *i2c) +{ +struct lsdc_i2c *const li2c = (struct lsdc_i2c *)i2c; +/* read the value from the li2c->scl pin */ +return ls7a_gpio_i2c_get (li2c, li2c->scl); +} + +static void lsdc_destroy_i2c (struct drm_device *ddev,void *data) +{ +struct lsdc_i2c *li2c = (struct lsdc_i2c *)data; + +if (li2c) { +i2c_del_adapter (&li2c->adapter); +kfree (li2c); + } +} + +/* +* The DC in ls7a1000/ls7a2000/ls2k2000 has builtin gpio hardware +* +* @reg_base: gpio reg base +* @index: output channel index, 0 for PIPE0, 1 for PIPE1 +*/ +struct lsdc_i2c *lsdc_create_i2c_chan (struct drm_device *ddev, +void *reg_base, +unsigned int index) +{ +struct i2c_adapter *adapter; +struct lsdc_i2c *li2c; +int ret; + + li2c =kzalloc (sizeof (*li2c),GFP_KERNEL ); +if (!li2c) +return ERR_PTR (-ENOMEM ); + +if (index ==0 ) { + li2c->sda =0x01 ;/* pin 0 */ + li2c->scl =0x02 ;/* pin 1 */ + }else if (index ==1 ) { + li2c->sda =0x04 ;/* pin 2 */ + li2c->scl =0x08 ;/* pin 3 */ + } + + li2c->ddev = ddev; + li2c->dir_reg = reg_base +LS7A_DC_GPIO_DIR_REG ; + li2c->dat_reg = reg_base +LS7A_DC_GPIO_DAT_REG ; + + li2c->bit.setsda = ls7a_i2c_set_sda; + li2c->bit.setscl = ls7a_i2c_set_scl; + li2c->bit.getsda = ls7a_i2c_get_sda; + li2c->bit.getscl = ls7a_i2c_get_scl; + li2c->bit.udelay =5 ; + li2c->bit.timeout =usecs_to_jiffies (2200 ); + li2c->bit.data = li2c; + + adapter = &li2c->adapter; + adapter->algo_data = &li2c->bit; + adapter->owner =THIS_MODULE ; + adapter->class =I2C_CLASS_DDC ; + adapter->dev.parent = ddev->dev; + adapter->nr =-1 ; + +snprintf (adapter->name,sizeof (adapter->name),"lsdc-i2c%u" , index); + +i2c_set_adapdata (adapter, li2c); + + ret =i2c_bit_add_bus (adapter); +if (ret) { +kfree (li2c); +return ERR_PTR (ret); + } + + ret =drmm_add_action_or_reset (ddev, lsdc_destroy_i2c, li2c); +if (ret) +return NULL ; + +drm_info (ddev,"%s(sda pin mask=%u, scl pin mask=%u) created for connector-%u\n" , + adapter->name, li2c->sda, li2c->scl, index); + +return li2c; +}drivers/gpu/drm/loongson/lsdc_irq.c new file +88
-0@@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <drm/drm_vblank.h> + +#include "lsdc_drv.h" +#include "lsdc_irq.h" + +/* +* For the DC in ls7a2000, clearing interrupt status is achieved by +* write "1" to LSDC_INT_REG, For the DC in ls7a1000, ls2k1000, +* Interrupt status clear is achieved by write "0" to LSDC_INT_REG. +* Two different hardware engineer of Loongson modify it as their will. +*/ + +static irqreturn_t ls7a2000_irq_handler (int irq,void *arg) +{ +struct drm_device *ddev = arg; +struct lsdc_device *ldev =to_lsdc (ddev); +u32 val; + +/* Read the interrupt status */ + val =lsdc_rreg32 (ldev,LSDC_INT_REG ); +if ((val &INT_STATUS_MASK ) ==0 ) { +drm_warn (ddev,"no interrupt occurs\n" ); +return IRQ_NONE ; + } + + ldev->irq_status = val; + +/* write "1" to clear the interrupt status */ +lsdc_wreg32 (ldev,LSDC_INT_REG , val); + +return IRQ_WAKE_THREAD ; +} + +/* For the DC in LS7A1000 and LS2K1000 */ +static irqreturn_t ls7a1000_irq_handler (int irq,void *arg) +{ +struct drm_device *ddev = arg; +struct lsdc_device *ldev =to_lsdc (ddev); +u32 val; + +/* Read the interrupt status */ + val =lsdc_rreg32 (ldev,LSDC_INT_REG ); +if ((val &INT_STATUS_MASK ) ==0 ) { +drm_warn (ddev,"no interrupt occurs\n" ); +return IRQ_NONE ; + } + + ldev->irq_status = val; + +/* write "0" to clear the interrupt status */ +lsdc_wreg32 (ldev,LSDC_INT_REG , val & ~INT_STATUS_MASK ); + +return IRQ_WAKE_THREAD ; +} + +irq_handler_t lsdc_get_irq_handler (struct lsdc_device *ldev) +{ +const struct lsdc_desc *descp = ldev->descp; + +if (descp->chip ==CHIP_LS7A2000 ) +return ls7a2000_irq_handler; + +if (descp->chip ==CHIP_LS7A1000 ) +return ls7a1000_irq_handler; + +return ls7a1000_irq_handler; +} + +irqreturn_t lsdc_irq_thread_handler (int irq,void *arg) +{ +struct drm_device *ddev = arg; +struct lsdc_device *ldev =to_lsdc (ddev); +struct drm_crtc *crtc; + +if (ldev->irq_status &INT_CRTC0_VSYNC ) { + crtc =drm_crtc_from_index (ddev,0 ); +drm_crtc_handle_vblank (crtc); + } + +if (ldev->irq_status &INT_CRTC1_VSYNC ) { + crtc =drm_crtc_from_index (ddev,1 ); +drm_crtc_handle_vblank (crtc); + } + +return IRQ_HANDLED ; +}drivers/gpu/drm/loongson/lsdc_irq.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LSDC_IRQ_H__ +#define __LSDC_IRQ_H__ + +#include <linux/irqreturn.h> + +irqreturn_t lsdc_irq_thread_handler (int irq,void *arg); +irq_handler_t lsdc_get_irq_handler (struct lsdc_device *ldev); + +#endif drivers/gpu/drm/loongson/lsdc_output.c new file +563
-0@@ -0,0 +1,563 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/delay.h> + +#include <drm/drm_atomic_helper.h> +#include <drm/drm_debugfs.h> +#include <drm/drm_edid.h> +#include <drm/drm_file.h> +#include <drm/drm_probe_helper.h> + +#include "lsdc_drv.h" +#include "lsdc_output.h" + +static int lsdc_get_modes (struct drm_connector *connector) +{ +unsigned int num =0 ; +struct edid *edid; + +if (connector->ddc) { + edid =drm_get_edid (connector, connector->ddc); +if (edid) { +drm_connector_update_edid_property (connector, edid); + num =drm_add_edid_modes (connector, edid); +kfree (edid); + } + +return num; + } + + num =drm_add_modes_noedid (connector,1920 ,1200 ); + +drm_set_preferred_mode (connector,1024 ,768 ); + +return num; +} + +static enum drm_connector_status +lsdc_dpi_connector_detect (struct drm_connector *connector,bool force) +{ +struct i2c_adapter *ddc = connector->ddc; + +if (ddc) { +if (drm_probe_ddc (ddc)) +return connector_status_connected; + +return connector_status_disconnected; + } + +return connector_status_unknown; +} + +static enum drm_connector_status +ls7a2000_hdmi_vga_connector_detect_pipe0 (struct drm_connector *connector,bool force) +{ +struct drm_device *ddev = connector->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +u32 val; + + val =lsdc_rreg32 (ldev,LSDC_HDMI_HPD_STATUS_REG ); + +if (val &HDMI0_HPD_FLAG ) +return connector_status_connected; + +if (connector->ddc) { +if (drm_probe_ddc (connector->ddc)) +return connector_status_connected; + +return connector_status_disconnected; + } + +return connector_status_unknown; +} + +static enum drm_connector_status +ls7a2000_hdmi_connector_detect_pipe1 (struct drm_connector *connector,bool force) +{ +struct lsdc_device *ldev =to_lsdc (connector->dev); +u32 val; + + val =lsdc_rreg32 (ldev,LSDC_HDMI_HPD_STATUS_REG ); + +if (val &HDMI1_HPD_FLAG ) +return connector_status_connected; + +return connector_status_disconnected; +} + +static struct drm_encoder * +lsdc_connector_get_best_encoder (struct drm_connector *connector, +struct drm_atomic_state *state) +{ +struct lsdc_display_pipe *pipe =connector_to_display_pipe (connector); + +return &pipe->encoder; +} + +static const struct drm_connector_helper_funcs lsdc_connector_helpers = { + .atomic_best_encoder = lsdc_connector_get_best_encoder, + .get_modes = lsdc_get_modes, +}; + +#define LSDC_CONNECTOR_FUNS (pfn_detect) \ + .detect = pfn_detect, \ + .fill_modes = drm_helper_probe_single_connector_modes, \ + .destroy = drm_connector_cleanup, \ + .reset = drm_atomic_helper_connector_reset, \ + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, \ + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state + +static const struct drm_connector_funcs lsdc_dpi_connector_funcs = { +LSDC_CONNECTOR_FUNS (lsdc_dpi_connector_detect), +}; + +static const struct drm_connector_funcs +ls7a2000_hdmi_connector_funcs[LSDC_NUM_CRTC ] = { + { +LSDC_CONNECTOR_FUNS (ls7a2000_hdmi_vga_connector_detect_pipe0), + }, + { +LSDC_CONNECTOR_FUNS (ls7a2000_hdmi_connector_detect_pipe1), + }, +}; + +/* Even though some board has only one hdmi on display pipe 1, +* We still need hook lsdc_encoder_funcs up on display pipe 0, +* This is because we need its reset() callback get called, to +* set the LSDC_HDMIx_CTRL_REG using software gpio emulated i2c. +* Otherwise, the firmware may set LSDC_HDMIx_CTRL_REG blindly. +*/ +static void ls7a2000_hdmi_encoder_reset (struct drm_encoder *encoder) +{ +struct drm_device *ddev = encoder->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +struct lsdc_display_pipe *dispipe =encoder_to_display_pipe (encoder); +unsigned int index = dispipe->index; +u32 val; + + val =lsdc_hdmi_rreg32 (ldev,LSDC_HDMI0_PHY_CTRL_REG , index); + val &= ~HDMI_PHY_RESET_N ; +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_PHY_CTRL_REG , index, val); +udelay (9 ); + val |=HDMI_PHY_RESET_N ; +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_PHY_CTRL_REG , index, val); +udelay (9 ); + + val =lsdc_hdmi_rreg32 (ldev,LSDC_HDMI0_INTF_CTRL_REG , index); + val &= ~HW_I2C_EN ; + val |=HDMI_INTERFACE_EN |HDMI_PACKET_EN ; +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_INTF_CTRL_REG , index, val); + +drm_dbg (ddev,"HDMI-%u Reset\n" , index); +} + +#ifdef CONFIG_DEBUG_FS + +#define LSDC_HDMI_REG (i, reg) { \ + .name = __stringify_1(LSDC_HDMI##i##_##reg##_REG), \ + .offset = LSDC_HDMI##i##_##reg##_REG, \ +} + +static const struct debugfs_reg32 ls7a2000_hdmi_encoder_regs[][9 ] = { + { +LSDC_HDMI_REG (0 ,ZONE ), +LSDC_HDMI_REG (0 ,INTF_CTRL ), +LSDC_HDMI_REG (0 ,PHY_CTRL ), +LSDC_HDMI_REG (0 ,PHY_PLL ), +LSDC_HDMI_REG (0 ,AVI_INFO_CRTL ), +LSDC_HDMI_REG (0 ,PHY_CAL ), +LSDC_HDMI_REG (0 ,AUDIO_PLL_LO ), +LSDC_HDMI_REG (0 ,AUDIO_PLL_HI ), + {NULL ,0 }, + }, + { +LSDC_HDMI_REG (1 ,ZONE ), +LSDC_HDMI_REG (1 ,INTF_CTRL ), +LSDC_HDMI_REG (1 ,PHY_CTRL ), +LSDC_HDMI_REG (1 ,PHY_PLL ), +LSDC_HDMI_REG (1 ,AVI_INFO_CRTL ), +LSDC_HDMI_REG (1 ,PHY_CAL ), +LSDC_HDMI_REG (1 ,AUDIO_PLL_LO ), +LSDC_HDMI_REG (1 ,AUDIO_PLL_HI ), + {NULL ,0 },/* MUST be {NULL, 0} terminated */ + }, +}; + +static int ls7a2000_hdmi_encoder_regs_show (struct seq_file *m,void *data) +{ +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); +const struct debugfs_reg32 *preg; + + preg = (const struct debugfs_reg32 *)node->info_ent->data; + +while (preg->name) { +u32 offset = preg->offset; + +seq_printf (m,"%s (0x%04x): 0x%08x\n" , preg->name, offset, +lsdc_rreg32 (ldev, offset)); + ++preg; + } + +return 0 ; +} + +static const struct drm_info_list ls7a2000_hdmi_debugfs_files[] = { + {"hdmi0_regs" , ls7a2000_hdmi_encoder_regs_show,0 , (void *)ls7a2000_hdmi_encoder_regs[0 ] }, + {"hdmi1_regs" , ls7a2000_hdmi_encoder_regs_show,0 , (void *)ls7a2000_hdmi_encoder_regs[1 ] }, +}; + +static int ls7a2000_hdmi_encoder_late_register (struct drm_encoder *encoder) +{ +struct lsdc_display_pipe *dispipe =encoder_to_display_pipe (encoder); +struct drm_device *ddev = encoder->dev; +struct drm_minor *minor = ddev->primary; + +drm_debugfs_create_files (&ls7a2000_hdmi_debugfs_files[dispipe->index], +1 , minor->debugfs_root, minor); + +return 0 ; +} + +#endif + +static const struct drm_encoder_funcs ls7a1000_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + +static const struct drm_encoder_funcs ls7a2000_encoder_funcs = { + .reset = ls7a2000_hdmi_encoder_reset, + .destroy = drm_encoder_cleanup, +#ifdef CONFIG_DEBUG_FS + .late_register = ls7a2000_hdmi_encoder_late_register, +#endif +}; + +static int ls7a2000_hdmi_set_avi_infoframe (struct drm_encoder *encoder, +struct drm_display_mode *mode) +{ +struct lsdc_display_pipe *dispipe =encoder_to_display_pipe (encoder); +struct drm_device *ddev = encoder->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +unsigned int index = dispipe->index; +struct hdmi_avi_infoframe infoframe; +u8 buffer[HDMI_INFOFRAME_SIZE (AVI )]; +unsigned char *ptr = &buffer[HDMI_INFOFRAME_HEADER_SIZE ]; +unsigned int content0, content1, content2, content3; +int err; + + err =drm_hdmi_avi_infoframe_from_display_mode (&infoframe, &dispipe->connector, mode); +if (err <0 ) { +drm_err (ddev,"failed to setup AVI infoframe: %d\n" , err); +return err; + } + +/* Fixed infoframe configuration not linked to the mode */ + infoframe.colorspace =HDMI_COLORSPACE_RGB ; + infoframe.quantization_range =HDMI_QUANTIZATION_RANGE_DEFAULT ; + infoframe.colorimetry =HDMI_COLORIMETRY_NONE ; + + err =hdmi_avi_infoframe_pack (&infoframe, buffer,sizeof (buffer)); +if (err <0 ) { +drm_err (ddev,"failed to pack AVI infoframe: %d\n" , err); +return err; + } + + content0 = *(unsigned int *)ptr; + content1 = *(ptr +4 ); + content2 = *(unsigned int *)(ptr +5 ); + content3 = *(unsigned int *)(ptr +9 ); + +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_AVI_CONTENT0 , index, content0); +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_AVI_CONTENT1 , index, content1); +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_AVI_CONTENT2 , index, content2); +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_AVI_CONTENT3 , index, content3); + +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_AVI_INFO_CRTL_REG , index, +AVI_PKT_ENABLE |AVI_PKT_UPDATE ); + +drm_dbg (ddev,"Update HDMI-%u avi infoframe\n" , index); + +return 0 ; +} + +static void ls7a2000_hdmi_atomic_disable (struct drm_encoder *encoder, +struct drm_atomic_state *state) +{ +struct lsdc_display_pipe *dispipe =encoder_to_display_pipe (encoder); +struct drm_device *ddev = encoder->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +unsigned int index = dispipe->index; +u32 val; + + val =lsdc_hdmi_rreg32 (ldev,LSDC_HDMI0_PHY_CTRL_REG , index); + val &= ~HDMI_PHY_EN ; +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_PHY_CTRL_REG , index, val); + +drm_dbg (ddev,"HDMI-%u disabled\n" , index); +} + +static void ls7a2000_hdmi_atomic_enable (struct drm_encoder *encoder, +struct drm_atomic_state *state) +{ +struct drm_device *ddev = encoder->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +struct lsdc_display_pipe *dispipe =encoder_to_display_pipe (encoder); +unsigned int index = dispipe->index; +u32 val; + +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_ZONE_REG , index,0x00400040 ); + + val =lsdc_hdmi_rreg32 (ldev,LSDC_HDMI0_PHY_CTRL_REG , index); + + val |=HDMI_PHY_TERM_STATUS | +HDMI_PHY_TERM_DET_EN | +HDMI_PHY_TERM_H_EN | +HDMI_PHY_TERM_L_EN | +HDMI_PHY_EN ; + +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_PHY_CTRL_REG , index, val); + + val =HDMI_CTL_PERIOD_MODE | +HDMI_AUDIO_EN | +HDMI_PACKET_EN | +HDMI_INTERFACE_EN | + (8 <<HDMI_VIDEO_PREAMBLE_SHIFT ); + +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_INTF_CTRL_REG , index, val); + +drm_dbg (ddev,"HDMI-%u enabled\n" , index); +} + +/* +* Fout = M * Fin +* +* M = (4 * LF) / (IDF * ODF) +* +* IDF: Input Division Factor +* ODF: Output Division Factor +* LF: Loop Factor +* M: Required Mult +* +* +--------------------------------------------------------+ +* | Fin (kHZ) | M | IDF | LF | ODF | Fout(Mhz) | +* |-------------------+----+-----+----+-----+--------------| +* | 170000 ~ 340000 | 10 | 16 | 40 | 1 | 1700 ~ 3400 | +* | 85000 ~ 170000 | 10 | 8 | 40 | 2 | 850 ~ 1700 | +* | 42500 ~ 85000 | 10 | 4 | 40 | 4 | 425 ~ 850 | +* | 21250 ~ 42500 | 10 | 2 | 40 | 8 | 212.5 ~ 425 | +* | 20000 ~ 21250 | 10 | 1 | 40 | 16 | 200 ~ 212.5 | +* +--------------------------------------------------------+ +*/ +static void ls7a2000_hdmi_phy_pll_config (struct lsdc_device *ldev, +int fin, +unsigned int index) +{ +struct drm_device *ddev = &ldev->base; +int count =0 ; +u32 val; + +/* Firstly, disable phy pll */ +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_PHY_PLL_REG , index,0x0 ); + +/* +* Most of time, loongson HDMI require M = 10 +* for example, 10 = (4 * 40) / (8 * 2) +* here, write "1" to the ODF will get "2" +*/ + +if (fin >=170000 ) + val = (16 <<HDMI_PLL_IDF_SHIFT ) | + (40 <<HDMI_PLL_LF_SHIFT ) | + (0 <<HDMI_PLL_ODF_SHIFT ); +else if (fin >=85000 ) + val = (8 <<HDMI_PLL_IDF_SHIFT ) | + (40 <<HDMI_PLL_LF_SHIFT ) | + (1 <<HDMI_PLL_ODF_SHIFT ); +else if (fin >=42500 ) + val = (4 <<HDMI_PLL_IDF_SHIFT ) | + (40 <<HDMI_PLL_LF_SHIFT ) | + (2 <<HDMI_PLL_ODF_SHIFT ); +else if (fin >=21250 ) + val = (2 <<HDMI_PLL_IDF_SHIFT ) | + (40 <<HDMI_PLL_LF_SHIFT ) | + (3 <<HDMI_PLL_ODF_SHIFT ); +else + val = (1 <<HDMI_PLL_IDF_SHIFT ) | + (40 <<HDMI_PLL_LF_SHIFT ) | + (4 <<HDMI_PLL_ODF_SHIFT ); + +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_PHY_PLL_REG , index, val |HDMI_PLL_ENABLE ); + +udelay (1 ); + +drm_dbg (ddev,"Fin of HDMI-%u: %d kHz\n" , index, fin); + +/* Wait hdmi phy pll lock */ +do { + val =lsdc_hdmi_rreg32 (ldev,LSDC_HDMI0_PHY_PLL_REG , index); + +if (val &HDMI_PLL_LOCKED ) { +drm_dbg (ddev,"Setting HDMI-%u PLL take %d cycles\n" , + index, count); +break ; + } + ++count; + }while (count <1000 ); + +lsdc_hdmi_wreg32 (ldev,LSDC_HDMI0_PHY_CAL_REG , index,0xf000ff0 ); + +if (count >=1000 ) +drm_err (ddev,"Setting HDMI-%u PLL failed\n" , index); +} + +static void ls7a2000_hdmi_atomic_mode_set (struct drm_encoder *encoder, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state) +{ +struct lsdc_display_pipe *dispipe =encoder_to_display_pipe (encoder); +struct drm_device *ddev = encoder->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +struct drm_display_mode *mode = &crtc_state->mode; + +ls7a2000_hdmi_phy_pll_config (ldev, mode->clock, dispipe->index); + +ls7a2000_hdmi_set_avi_infoframe (encoder, mode); + +drm_dbg (ddev,"HDMI-%u modeset finished\n" , dispipe->index); +} + +const struct drm_encoder_helper_funcs ls7a2000_hdmi_encoder_helper_funcs = { + .atomic_disable = ls7a2000_hdmi_atomic_disable, + .atomic_enable = ls7a2000_hdmi_atomic_enable, + .atomic_mode_set = ls7a2000_hdmi_atomic_mode_set, +}; + +/* +* For LS7A2000: +* +* 1) Some board export double hdmi output interface +* 2) Most of board export one vga + hdmi output interface +* 3) Still have boards export three output(2 hdmi + 1 vga). +* +* So let's hook hdmi helper funcs to all display pipe, don't miss. +* writing hdmi register do no harms. +*/ +static int ls7a2000_output_init (struct lsdc_device *ldev, +struct lsdc_display_pipe *dispipe, +struct i2c_adapter *ddc) +{ +struct drm_device *ddev = &ldev->base; +struct drm_encoder *encoder = &dispipe->encoder; +struct drm_connector *connector = &dispipe->connector; +unsigned int pipe = dispipe->index; +int ret; + + ret =drm_encoder_init (ddev, + encoder, + &ls7a2000_encoder_funcs, +DRM_MODE_ENCODER_TMDS , +"encoder-%u" , + pipe); +if (ret) +return ret; + + encoder->possible_crtcs =BIT (pipe); + +drm_encoder_helper_add (encoder, &ls7a2000_hdmi_encoder_helper_funcs); + + ret =drm_connector_init_with_ddc (ddev, + connector, + &ls7a2000_hdmi_connector_funcs[pipe], +DRM_MODE_CONNECTOR_HDMIA , + ddc); +if (ret) +return ret; + +drm_info (ddev,"display pipe-%u has HDMI%s\n" , pipe, pipe ?"" :" and/or VGA" ); + +drm_connector_helper_add (connector, &lsdc_connector_helpers); + +drm_connector_attach_encoder (connector, encoder); + + connector->polled =DRM_CONNECTOR_POLL_CONNECT | +DRM_CONNECTOR_POLL_DISCONNECT ; + + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + +return 0 ; +} + +static int ls7a1000_output_init (struct lsdc_device *ldev, +struct lsdc_display_pipe *dispipe, +struct i2c_adapter *ddc) +{ +struct drm_device *ddev = &ldev->base; +struct drm_encoder *encoder = &dispipe->encoder; +struct drm_connector *connector = &dispipe->connector; +int ret; + + ret =drm_encoder_init (ddev, + encoder, + &ls7a1000_encoder_funcs, +DRM_MODE_ENCODER_TMDS , +"encoder-%u" , + dispipe->index); +if (ret) +return ret; + + encoder->possible_crtcs =BIT (dispipe->index); + + ret =drm_connector_init_with_ddc (ddev, + connector, + &lsdc_dpi_connector_funcs, +DRM_MODE_CONNECTOR_DPI , + ddc); +if (ret) +return ret; + +drm_info (ddev,"display pipe-%u has a DVO\n" , dispipe->index); + +drm_connector_helper_add (connector, &lsdc_connector_helpers); + +drm_connector_attach_encoder (connector, encoder); + + connector->polled =DRM_CONNECTOR_POLL_CONNECT | +DRM_CONNECTOR_POLL_DISCONNECT ; + + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + +return 0 ; +} + +typedef int (*pfn_output_init_t )(struct lsdc_device *ldev, +struct lsdc_display_pipe *disp, +struct i2c_adapter *ddc); + +/* NOTE: keep this as the order listed in loongson_chip_family enum */ +static const pfn_output_init_t lsdc_output_init[CHIP_LAST ] = { + ls7a1000_output_init, + ls7a2000_output_init, +}; + +int lsdc_create_output (struct lsdc_device *ldev, +struct lsdc_display_pipe *dispipe) +{ +const struct lsdc_desc *descp = ldev->descp; +struct i2c_adapter *ddc =NULL ; +struct lsdc_i2c *li2c; + +if (descp->has_builtin_i2c) { + li2c =lsdc_create_i2c_chan (&ldev->base, ldev->reg_base, dispipe->index); +if (IS_ERR (li2c)) +return PTR_ERR (li2c); + + dispipe->li2c = li2c; + ddc = &li2c->adapter; + } + +/* Output interfaces suffer from changes */ +return lsdc_output_init[descp->chip](ldev, dispipe, ddc); +}drivers/gpu/drm/loongson/lsdc_output.h new file +14
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LSDC_OUTPUT_H__ +#define __LSDC_OUTPUT_H__ + +#include "lsdc_drv.h" + +int lsdc_create_output (struct lsdc_device *ldev,struct lsdc_display_pipe *p); + +struct lsdc_i2c *lsdc_create_i2c_chan (struct drm_device *ddev, +void *base, +unsigned int index); + +#endif drivers/gpu/drm/loongson/lsdc_plane.c new file +416
-0@@ -0,0 +1,416 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <drm/drm_atomic.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_framebuffer.h> +#include <drm/drm_plane_helper.h> + +#include "lsdc_drv.h" +#include "lsdc_regs.h" +#include "lsdc_ttm.h" + +static const u32 lsdc_primary_formats[] = { +DRM_FORMAT_XRGB8888 , +}; + +static const u32 lsdc_cursor_formats[] = { +DRM_FORMAT_ARGB8888 , +}; + +static const u64 lsdc_fb_format_modifiers[] = { +DRM_FORMAT_MOD_LINEAR , +DRM_FORMAT_MOD_INVALID +}; + +static int lsdc_cursor_atomic_check (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_crtc *crtc = new_plane_state->crtc; +struct drm_crtc_state *new_crtc_state; + +if (!crtc) +return 0 ; + + new_crtc_state =drm_atomic_get_new_crtc_state (state, crtc); + +return drm_atomic_helper_check_plane_state (new_plane_state, + new_crtc_state, +DRM_PLANE_NO_SCALING , +DRM_PLANE_NO_SCALING , + true, + true); +} + +static int lsdc_primary_atomic_check (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_crtc *crtc = new_plane_state->crtc; +struct drm_crtc_state *new_crtc_state; + +if (!crtc) +return 0 ; + + new_crtc_state =drm_atomic_get_new_crtc_state (state, crtc); + +return drm_atomic_helper_check_plane_state (new_plane_state, + new_crtc_state, +DRM_PLANE_NO_SCALING , +DRM_PLANE_NO_SCALING , + false, + true); +} + +static unsigned int lsdc_get_fb_offset (struct drm_framebuffer *fb, +struct drm_plane_state *state) +{ +unsigned int offset = fb->offsets[0 ]; + + offset += fb->format->cpp[0 ] * (state->src_x >>16 ); + offset += fb->pitches[0 ] * (state->src_y >>16 ); + +return offset; +} + +static void lsdc_primary_atomic_update (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct lsdc_display_pipe *dispipe =primary_to_display_pipe (plane); +struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); +struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_framebuffer *new_fb = new_plane_state->fb; +struct drm_framebuffer *old_fb = old_plane_state->fb; +struct ttm_buffer_object *tbo =to_ttm_bo (new_fb->obj[0 ]); +struct drm_device *ddev = plane->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +unsigned int index = dispipe->index; +unsigned int fb_offset =lsdc_get_fb_offset (new_fb, new_plane_state); +u64 bo_offset =lsdc_bo_gpu_offset (tbo); +u64 fb_addr = ldev->vram_base + bo_offset + fb_offset; +u32 stride = new_fb->pitches[0 ]; +u32 cfg; +u32 lo, hi; + +/* 40-bit width physical address bus */ + lo = fb_addr &0xFFFFFFFF ; + hi = (fb_addr >>32 ) &0xFF ; + + cfg =lsdc_crtc_rreg32 (ldev,LSDC_CRTC0_CFG_REG , index); +if (cfg &CFG_FB_IN_USING ) { +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_FB1_LO_ADDR_REG , index, lo); +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_FB1_HI_ADDR_REG , index, hi); + }else { +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_FB0_LO_ADDR_REG , index, lo); +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_FB0_HI_ADDR_REG , index, hi); + } + +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_STRIDE_REG , index, stride); + +if (!old_fb || new_fb->format != old_fb->format) { + cfg &= ~CFG_PIX_FMT_MASK ; + cfg |=LSDC_PF_XRGB8888 ; + +lsdc_crtc_wreg32 (ldev,LSDC_CRTC0_CFG_REG , index, cfg); + } +} + +static void lsdc_primary_atomic_disable (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +/* Do nothing, just prevent call into atomic_update(). +* Writing the format as LSDC_PF_NONE can disable the primary, +* But it seems not necessary... +*/ +drm_dbg (plane->dev,"%s disabled\n" , plane->name); +} + +static int lsdc_plane_prepare_fb (struct drm_plane *plane, +struct drm_plane_state *new_state) +{ +struct drm_framebuffer *fb = new_state->fb; +struct drm_gem_object *obj; +struct lsdc_bo *lbo; +int ret; + +if (!fb) +return 0 ; + + obj = fb->obj[0 ]; +if (!obj) +return -EINVAL ; + + lbo =gem_to_lsdc_bo (obj); + + ret =lsdc_bo_pin (lbo,LSDC_GEM_DOMAIN_VRAM ,NULL ); +if (ret) +return ret; + + ret =drm_gem_plane_helper_prepare_fb (plane, new_state); +if (ret) +lsdc_bo_unpin (lbo); + +return 0 ; +} + +static void lsdc_plane_cleanup_fb (struct drm_plane *plane, +struct drm_plane_state *old_state) +{ +struct drm_framebuffer *fb = old_state->fb; +struct drm_gem_object *obj; +struct lsdc_bo *lbo; + +if (!fb) +return ; + + obj = fb->obj[0 ]; +if (!obj) +return ; + + lbo =gem_to_lsdc_bo (obj); + +lsdc_bo_unpin (lbo); +} + +static const struct drm_plane_helper_funcs lsdc_primary_helper_funcs = { + .prepare_fb = lsdc_plane_prepare_fb, + .cleanup_fb = lsdc_plane_cleanup_fb, + .atomic_check = lsdc_primary_atomic_check, + .atomic_update = lsdc_primary_atomic_update, + .atomic_disable = lsdc_primary_atomic_disable, +}; + +/* +* Update location, format, enable and disable state of the cursor, +* For those who have two hardware cursor, cursor 0 is attach it to CRTC-0, +* cursor 1 is attached to CRTC-1. Compositing the primary and cursor plane +* is automatically done by hardware, the cursor is alway on the top of the +* primary. In other word, z-order is fixed in hardware and cannot be changed. +*/ +static void ls7a1000_cursor_atomic_update (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct drm_device *ddev = plane->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +struct lsdc_display_pipe *dispipe =cursor_to_display_pipe (plane); +struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); +struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_framebuffer *new_fb = new_plane_state->fb; +struct drm_framebuffer *old_fb = old_plane_state->fb; +struct ttm_buffer_object *tbo =to_ttm_bo (new_fb->obj[0 ]); +u64 addr = ldev->vram_base +lsdc_bo_gpu_offset (tbo); +u32 cfg =CURSOR_FORMAT_ARGB8888 ; +int x = new_plane_state->crtc_x; +int y = new_plane_state->crtc_y; + +if (x <0 ) + x =0 ; + +if (y <0 ) + y =0 ; + +lsdc_wreg32 (ldev,LSDC_CURSOR0_POSITION_REG , (y <<16 ) | x); + +if (new_fb != old_fb) { +lsdc_wreg32 (ldev,LSDC_CURSOR0_ADDR_HI_REG , (addr >>32 ) &0xFF ); +lsdc_wreg32 (ldev,LSDC_CURSOR0_ADDR_LO_REG , addr); + } + +/* +* If bit 4(CURSOR_LOCATION) of LSDC_CURSOR0_CFG_REG is 1, cursor will +* be locate at CRTC-1, if bit 4 of LSDC_CURSOR0_CFG_REG is 0, cursor +* will be locate at CRTC-0. For the old device we made the single hw +* cursor shared by two CRTC. Switch to software cursor is also ok. +*/ +lsdc_wreg32 (ldev,LSDC_CURSOR0_CFG_REG , dispipe->index ? cfg |CURSOR_LOCATION : cfg); +} + +static void ls7a1000_cursor_atomic_disable (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct drm_device *ddev = plane->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +u32 cfg; + + cfg =lsdc_rreg32 (ldev,LSDC_CURSOR0_CFG_REG ); +/* write 0 to cursor format bits, it will be invisiable */ + cfg &= ~CURSOR_FORMAT_MASK ; +lsdc_wreg32 (ldev,LSDC_CURSOR0_CFG_REG , cfg); +} + +static const struct drm_plane_helper_funcs ls7a1000_cursor_helper_funcs = { + .prepare_fb = lsdc_plane_prepare_fb, + .cleanup_fb = lsdc_plane_cleanup_fb, + .atomic_check = lsdc_cursor_atomic_check, + .atomic_update = ls7a1000_cursor_atomic_update, + .atomic_disable = ls7a1000_cursor_atomic_disable, +}; + +/* update the format, size and location of the cursor */ +static void ls7a2000_cursor0_atomic_update (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct drm_device *ddev = plane->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); +struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_framebuffer *new_fb = new_plane_state->fb; +struct drm_framebuffer *old_fb = old_plane_state->fb; +struct ttm_buffer_object *tbo =to_ttm_bo (new_fb->obj[0 ]); +u64 addr = ldev->vram_base +lsdc_bo_gpu_offset (tbo); +int x = new_plane_state->crtc_x; +int y = new_plane_state->crtc_y; + +if (x <0 ) + x =0 ; + +if (y <0 ) + y =0 ; + +lsdc_wreg32 (ldev,LSDC_CURSOR0_POSITION_REG , (y <<16 ) | x); + +if (new_fb != old_fb) { +lsdc_wreg32 (ldev,LSDC_CURSOR0_ADDR_HI_REG , (addr >>32 ) &0xFF ); +lsdc_wreg32 (ldev,LSDC_CURSOR0_ADDR_LO_REG , addr); + } + +lsdc_wreg32 (ldev,LSDC_CURSOR0_CFG_REG ,CURSOR_FORMAT_ARGB8888 |CURSOR_SIZE_64X64 ); +} + +/* update the format, size and location of the cursor */ +static void ls7a2000_cursor1_atomic_update (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct drm_device *ddev = plane->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); +struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_framebuffer *new_fb = new_plane_state->fb; +struct drm_framebuffer *old_fb = old_plane_state->fb; +struct ttm_buffer_object *tbo =to_ttm_bo (new_fb->obj[0 ]); +u64 addr = ldev->vram_base +lsdc_bo_gpu_offset (tbo); +int x = new_plane_state->crtc_x; +int y = new_plane_state->crtc_y; + +if (x <0 ) + x =0 ; + +if (y <0 ) + y =0 ; + +lsdc_wreg32 (ldev,LSDC_CURSOR1_POSITION_REG , (y <<16 ) | x); + +if (new_fb != old_fb) { +lsdc_wreg32 (ldev,LSDC_CURSOR1_ADDR_HI_REG , (addr >>32 ) &0xFF ); +lsdc_wreg32 (ldev,LSDC_CURSOR1_ADDR_LO_REG , addr); + } + +lsdc_wreg32 (ldev,LSDC_CURSOR1_CFG_REG , +CURSOR_FORMAT_ARGB8888 |CURSOR_SIZE_64X64 |CURSOR_LOCATION ); +} + +static void ls7a2000_cursor0_atomic_disable (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct drm_device *ddev = plane->dev; +struct lsdc_device *ldev =to_lsdc (ddev); +u32 cfg; + + cfg =lsdc_rreg32 (ldev,LSDC_CURSOR0_CFG_REG ); +/* write 0 to cursor format bits, it will be invisiable */ + cfg &= ~CURSOR_FORMAT_MASK ; +lsdc_wreg32 (ldev,LSDC_CURSOR0_CFG_REG , cfg); +} + +static void ls7a2000_cursor1_atomic_disable (struct drm_plane *plane, +struct drm_atomic_state *state) +{Lines of this file are not shown. View the raw message.
drivers/gpu/drm/loongson/lsdc_pll.c new file +338
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/loongson/lsdc_pll.h new file +76
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/loongson/lsdc_probe.c new file +85
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/loongson/lsdc_probe.h new file +11
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/loongson/lsdc_regs.h new file +370
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/loongson/lsdc_ttm.c new file +430
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/loongson/lsdc_ttm.h new file +68
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Sui,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display controller config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230328/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
git checkout 80b4115f44993f4ebf47b1cb9e8f02953575b977
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/accel/ drivers/gpu/drm/loongson/ drivers/iio/light/ drivers/media/pci/intel/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
else if (descp->chip == CHIP_LS7A2000)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs here
if (!gpu) {
^~~
drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its condition is always true
else if (descp->chip == CHIP_LS7A2000)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 'gpu' to silence this warning
struct pci_dev *gpu;
^
= NULL
1 warning generated.
--
>> drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
else if (clock_khz < computed)
^~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/loongson/lsdc_pll.c:191:9: note: uninitialized use occurs here
if (diff < min) {
^~~~
drivers/gpu/drm/loongson/lsdc_pll.c:188:10: note: remove the 'if' if its condition is always true
else if (clock_khz < computed)
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/loongson/lsdc_pll.c:177:22: note: initialize the variable 'diff' to silence this warning
unsigned int diff;
^
= 01 warning generated.
vim +232 drivers/gpu/drm/loongson/lsdc_drv.c
212
213 static int lsdc_get_dedicated_vram(struct lsdc_device *ldev,
214 const struct lsdc_desc *descp)
215 {
216 struct drm_device *ddev = &ldev->base;
217 struct pci_dev *gpu;
218 resource_size_t base, size;
219
220 /*
221 * The GPU and display controller in LS7A1000/LS7A2000 are separated
222 * PCIE devices, they are two devices not one. The DC does not has a
223 * dedicate VRAM bar, because the BIOS engineer choose to assign the
224 * VRAM to the GPU device. Sadly, after years application, this form
225 * as a convention for loongson integrated graphics. Bar 2 of the GPU
226 * device contain the base address and size of the VRAM, both the GPU
227 * and the DC can access the on-board VRAM as long as the DMA address
228 * emitted fall in [base, base + size).
229 */
230 if (descp->chip == CHIP_LS7A1000)
231 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A15, NULL);
> 232 else if (descp->chip == CHIP_LS7A2000)
233 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A25, NULL);
234
235 if (!gpu) {
236 drm_warn(ddev, "No GPU device found\n");
237 return -ENODEV;
238 }
239
240 base = pci_resource_start(gpu, 2);
241 size = pci_resource_len(gpu, 2);
242
243 ldev->vram_base = base;
244 ldev->vram_size = size;
245
246 drm_info(ddev, "dedicated vram start: 0x%llx, size: %uMB\n",
247 (u64)base, (u32)(size >> 20));
248
249 return 0;
250 }
251
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Hi,
Is this all of warnings ? I'm asking because I'm afraid it is not all.
If I fix those, it will generate new again next time.
I'm compile this driver with GCC, it report no warnings
On ls3a4000 mips machine:
make -j$(nproc) ARCH=mips CROSS_COMPILE=mips64el-linux-gnuabi64- W=1
On ls3a5000 LoongArch machine:
| make -j$(nproc) ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu-|
Build tools can be found link [1]
[1] https://github.com/loongson/build-tools
On x86-64 is also compiled.
Yet, It is easy to fix, is there any other questions or issues?
I will fix them all.
Quoted 108 lines · kernel test robot
Hi Sui,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display controller config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230328/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
git checkout80b4115f44993f4ebf47b1cb9e8f02953575b977
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bashdrivers/accel/drivers/gpu/drm/loongson/drivers/iio/light/drivers/media/pci/intel/If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]else if (descp->chip == CHIP_LS7A2000) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs here if (!gpu) { ^~~ drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its condition is always true else if (descp->chip == CHIP_LS7A2000) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 'gpu' to silence this warning struct pci_dev *gpu; ^ = NULL 1 warning generated.--
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]else if (clock_khz < computed) ^~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_pll.c:191:9: note: uninitialized use occurs here if (diff < min) { ^~~~ drivers/gpu/drm/loongson/lsdc_pll.c:188:10: note: remove the 'if' if its condition is always true else if (clock_khz < computed) ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_pll.c:177:22: note: initialize the variable 'diff' to silence this warning unsigned int diff; ^ = 0 1 warning generated.vim +232
drivers/gpu/drm/loongson/lsdc_drv.c212 213 static int lsdc_get_dedicated_vram(struct lsdc_device *ldev, 214 const struct lsdc_desc *descp) 215 { 216 struct drm_device *ddev = &ldev->base; 217 struct pci_dev *gpu; 218 resource_size_t base, size; 219 220 /* 221 * The GPU and display controller in LS7A1000/LS7A2000 are separated 222 * PCIE devices, they are two devices not one. The DC does not has a 223 * dedicate VRAM bar, because the BIOS engineer choose to assign the 224 * VRAM to the GPU device. Sadly, after years application, this form 225 * as a convention for loongson integrated graphics. Bar 2 of the GPU 226 * device contain the base address and size of the VRAM, both the GPU 227 * and the DC can access the on-board VRAM as long as the DMA address 228 * emitted fall in [base, base + size). 229 */ 230 if (descp->chip == CHIP_LS7A1000) 231 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A15, NULL);Quoted 1 line
232 else if (
descp->chip==CHIP_LS7A2000)233 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A25, NULL); 234 235 if (!gpu) { 236 drm_warn(ddev, "No GPU device found\n"); 237 return -ENODEV; 238 } 239 240 base = pci_resource_start(gpu, 2); 241 size = pci_resource_len(gpu, 2); 242 243 ldev->vram_base = base; 244 ldev->vram_size = size; 245 246 drm_info(ddev, "dedicated vram start: 0x%llx, size: %uMB\n", 247 (u64)base, (u32)(size >> 20)); 248 249 return 0; 250 } 251
HI,
Quoted 48 lines · kernel test robot
Hi Sui,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display controller config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230328/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
git checkout80b4115f44993f4ebf47b1cb9e8f02953575b977
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bashdrivers/accel/drivers/gpu/drm/loongson/drivers/iio/light/drivers/media/pci/intel/If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]else if (descp->chip == CHIP_LS7A2000) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs here if (!gpu) { ^~~ drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its condition is always true else if (descp->chip == CHIP_LS7A2000) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 'gpu' to silence this warning struct pci_dev *gpu; ^ = NULL 1 warning generated.
Quoted 1 line
--
In practice, either descp->chip == CHIP_LS7A2000 or descp->chip == CHIP_LS7A1000 will be happened at runtime.
the variable 'gpu' is guaranteed to be initialized when code run at drivers/gpu/drm/loongson/lsdc_drv.c:235
This warnning is almost wrong here.
Quoted 14 lines
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]else if (clock_khz < computed) ^~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_pll.c:191:9: note: uninitialized use occurs here if (diff < min) { ^~~~ drivers/gpu/drm/loongson/lsdc_pll.c:188:10: note: remove the 'if' if its condition is always true else if (clock_khz < computed) ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_pll.c:177:22: note: initialize the variable 'diff' to silence this warning unsigned int diff; ^ = 0 1 warning generated.
Here the robot is also wrong here in practice,
because either if (clock_khz >= computed) or else if (clock_khz < computed) will be happen.
'diff' variable is guaranteed to be initialized.
Quoted 44 lines
vim +232
drivers/gpu/drm/loongson/lsdc_drv.c212 213 static int lsdc_get_dedicated_vram(struct lsdc_device *ldev, 214 const struct lsdc_desc *descp) 215 { 216 struct drm_device *ddev = &ldev->base; 217 struct pci_dev *gpu; 218 resource_size_t base, size; 219 220 /* 221 * The GPU and display controller in LS7A1000/LS7A2000 are separated 222 * PCIE devices, they are two devices not one. The DC does not has a 223 * dedicate VRAM bar, because the BIOS engineer choose to assign the 224 * VRAM to the GPU device. Sadly, after years application, this form 225 * as a convention for loongson integrated graphics. Bar 2 of the GPU 226 * device contain the base address and size of the VRAM, both the GPU 227 * and the DC can access the on-board VRAM as long as the DMA address 228 * emitted fall in [base, base + size). 229 */ 230 if (descp->chip == CHIP_LS7A1000) 231 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A15, NULL);Quoted 1 line
232 else if (
descp->chip==CHIP_LS7A2000)233 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A25, NULL); 234 235 if (!gpu) { 236 drm_warn(ddev, "No GPU device found\n"); 237 return -ENODEV; 238 } 239 240 base = pci_resource_start(gpu, 2); 241 size = pci_resource_len(gpu, 2); 242 243 ldev->vram_base = base; 244 ldev->vram_size = size; 245 246 drm_info(ddev, "dedicated vram start: 0x%llx, size: %uMB\n", 247 (u64)base, (u32)(size >> 20)); 248 249 return 0; 250 } 251
Quoted 53 lines · Sui Jingfeng
HI,
Quoted 48 lines · kernel test robot
Hi Sui,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display controller config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230328/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
git checkout80b4115f44993f4ebf47b1cb9e8f02953575b977
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bashdrivers/accel/drivers/gpu/drm/loongson/drivers/iio/light/drivers/media/pci/intel/If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]else if (descp->chip == CHIP_LS7A2000) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs here if (!gpu) { ^~~ drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its condition is always true else if (descp->chip == CHIP_LS7A2000) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 'gpu' to silence this warning struct pci_dev *gpu; ^ = NULL 1 warning generated.Quoted 1 line
--
Quoted 7 lines
In practice, either
descp->chip==CHIP_LS7A2000ordescp->chip==CHIP_LS7A1000will be happened at runtime.the variable 'gpu' is guaranteed to be initialized when code run at
drivers/gpu/drm/loongson/lsdc_drv.c:235This warnning is almost wrong here.
Clang's semantic analysis happens before optimizations, meaning it does not perform interprocedural analysis, so it does not have enough information at this point to tell that. Either just initialize gpu to NULL and let the existing 'if (!gpu)' handle it or add a separate else branch that warns about an unhandled chip value so that it is obvious what needs to be done if someone forgets to update this statement when a new chip is supported by this driver.
Quoted 15 lines
Quoted 14 lines
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]else if (clock_khz < computed) ^~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_pll.c:191:9: note: uninitialized use occurs here if (diff < min) { ^~~~ drivers/gpu/drm/loongson/lsdc_pll.c:188:10: note: remove the 'if' if its condition is always true else if (clock_khz < computed) ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_pll.c:177:22: note: initialize the variable 'diff' to silence this warning unsigned int diff; ^ = 0 1 warning generated.
Quoted 6 lines
Here the robot is also wrong here in practice,
because either if (
clock_khz>= computed) or else if (clock_khz< computed) will be happen.'diff' variable is guaranteed to be initialized.
Make that clearer by turning 'else if (clock_khz < computed)' into just 'else' as the warning suggests? I do not see why the condition is specified at all if it is just an 'else' in practice.
Cheers,
Nathan
Quoted 45 lines
Quoted 44 lines
vim +232
drivers/gpu/drm/loongson/lsdc_drv.c212 213 static int lsdc_get_dedicated_vram(struct lsdc_device *ldev, 214 const struct lsdc_desc *descp) 215 { 216 struct drm_device *ddev = &ldev->base; 217 struct pci_dev *gpu; 218 resource_size_t base, size; 219 220 /* 221 * The GPU and display controller in LS7A1000/LS7A2000 are separated 222 * PCIE devices, they are two devices not one. The DC does not has a 223 * dedicate VRAM bar, because the BIOS engineer choose to assign the 224 * VRAM to the GPU device. Sadly, after years application, this form 225 * as a convention for loongson integrated graphics. Bar 2 of the GPU 226 * device contain the base address and size of the VRAM, both the GPU 227 * and the DC can access the on-board VRAM as long as the DMA address 228 * emitted fall in [base, base + size). 229 */ 230 if (descp->chip == CHIP_LS7A1000) 231 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A15, NULL);Quoted 1 line
232 else if (
descp->chip==CHIP_LS7A2000)233 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A25, NULL); 234 235 if (!gpu) { 236 drm_warn(ddev, "No GPU device found\n"); 237 return -ENODEV; 238 } 239 240 base = pci_resource_start(gpu, 2); 241 size = pci_resource_len(gpu, 2); 242 243 ldev->vram_base = base; 244 ldev->vram_size = size; 245 246 drm_info(ddev, "dedicated vram start: 0x%llx, size: %uMB\n", 247 (u64)base, (u32)(size >> 20)); 248 249 return 0; 250 } 251
Quoted 59 lines · Nathan Chancellor
Quoted 58 lines · Sui Jingfeng
HI,
Quoted 48 lines · kernel test robot
Hi Sui,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.3-rc4 next-20230328] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230320100131.1277034-3-15330273260%40189.cn patch subject: [PATCH v8 2/2] drm: add kms driver for loongson display controller config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230328/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/80b4115f44993f4ebf47b1cb9e8f02953575b977
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sui-Jingfeng/MAINTAINERS-add-maintainers-for-DRM-LOONGSON-driver/20230320-180408
git checkout80b4115f44993f4ebf47b1cb9e8f02953575b977
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bashdrivers/accel/drivers/gpu/drm/loongson/drivers/iio/light/drivers/media/pci/intel/If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/loongson/lsdc_drv.c:232:11: warning: variable 'gpu' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]else if (descp->chip == CHIP_LS7A2000) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_drv.c:235:7: note: uninitialized use occurs here if (!gpu) { ^~~ drivers/gpu/drm/loongson/lsdc_drv.c:232:7: note: remove the 'if' if its condition is always true else if (descp->chip == CHIP_LS7A2000) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_drv.c:217:21: note: initialize the variable 'gpu' to silence this warning struct pci_dev *gpu; ^ = NULL 1 warning generated.Quoted 1 line
--
In practice, either
descp->chip==CHIP_LS7A2000ordescp->chip==CHIP_LS7A1000will be happened at runtime.the variable 'gpu' is guaranteed to be initialized when code run at
drivers/gpu/drm/loongson/lsdc_drv.c:235
Quoted 8 lines
Quoted 1 line
This warnning is almost wrong here.
Clang's semantic analysis happens before optimizations, meaning it does not perform interprocedural analysis, so it does not have enough information at this point to tell that. Either just initialize gpu to NULL and let the existing 'if (!gpu)' handle it or add a separate else branch that warns about an unhandled chip value so that it is obvious what needs to be done if someone forgets to update this statement when a new chip is supported by this driver.
Right, I overlook the point you mentioned previously.
And I just have a new idea, using pci_get_domain_bus_and_slot function
to handle this. the DC and the GPU have the same pci bus number and domain number.
The slot number of the dc and gpu is also same(6), only the function number is different.
For ls7a1000, what lspci -t -nnn -vvv show is:
-[0000:00]-+-00.0 Loongson Technology LLC Hyper Transport Bridge Controller [0014:7a00]
...
+-06.0 Loongson Technology LLC Vivante GPU (Graphics Processing Unit) [0014:7a15] +-06.1 Loongson Technology LLC DC (Display Controller) [0014:7a06]
...
For ls7a2000, what lspci -t -nnn -vvv show is:
-[0000:00]-+-00.0 Loongson Technology LLC Hyper Transport Bridge Controller [0014:7a00] +-00.1 Loongson Technology LLC Hyper Transport Bridge Controller [0014:7a10]
...
+-06.0 Loongson Technology LLC LoongGPU Device [0014:7a25] +-06.1 Loongson Technology LLC DC (Display Controller) Device [0014:7a36] +-06.2 Loongson Technology LLC Audio Device [0014:7a37]
...
So
pdev_gpu = pci_get_domain_bus_and_slot(pci_domain_nr(pdev_dc->bus), pdev_dc->bus->number, PCI_DEVFN(6, 0));
can help to handle all case, will this be ok?
Quoted 16 lines
Quoted 16 lines
Quoted 14 lines
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/loongson/lsdc_pll.c:188:14: warning: variable 'diff' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]else if (clock_khz < computed) ^~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_pll.c:191:9: note: uninitialized use occurs here if (diff < min) { ^~~~ drivers/gpu/drm/loongson/lsdc_pll.c:188:10: note: remove the 'if' if its condition is always true else if (clock_khz < computed) ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/loongson/lsdc_pll.c:177:22: note: initialize the variable 'diff' to silence this warning unsigned int diff; ^ = 0 1 warning generated.Here the robot is also wrong here in practice,
Quoted 7 lines
Quoted 4 lines
because either if (
clock_khz>= computed) or else if (clock_khz< computed) will be happen.'diff' variable is guaranteed to be initialized.
Make that clearer by turning 'else if (
clock_khz< computed)' into just 'else' as the warning suggests? I do not see why the condition is specified at all if it is just an 'else' in practice.
Yes, you are right.
The test robot do find something, i will fix this at next version.
Quoted 46 lines
Cheers,
NathanQuoted 43 lines
Quoted 43 lines
vim +232
drivers/gpu/drm/loongson/lsdc_drv.c212 213 static int lsdc_get_dedicated_vram(struct lsdc_device *ldev, 214 const struct lsdc_desc *descp) 215 { 216 struct drm_device *ddev = &ldev->base; 217 struct pci_dev *gpu; 218 resource_size_t base, size; 219 220 /* 221 * The GPU and display controller in LS7A1000/LS7A2000 are separated 222 * PCIE devices, they are two devices not one. The DC does not has a 223 * dedicate VRAM bar, because the BIOS engineer choose to assign the 224 * VRAM to the GPU device. Sadly, after years application, this form 225 * as a convention for loongson integrated graphics. Bar 2 of the GPU 226 * device contain the base address and size of the VRAM, both the GPU 227 * and the DC can access the on-board VRAM as long as the DMA address 228 * emitted fall in [base, base + size). 229 */ 230 if (descp->chip == CHIP_LS7A1000) 231 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A15, NULL);Quoted 1 line
232 else if (
descp->chip==CHIP_LS7A2000)233 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A25, NULL); 234 235 if (!gpu) { 236 drm_warn(ddev, "No GPU device found\n"); 237 return -ENODEV; 238 } 239 240 base = pci_resource_start(gpu, 2); 241 size = pci_resource_len(gpu, 2); 242 243 ldev->vram_base = base; 244 ldev->vram_size = size; 245 246 drm_info(ddev, "dedicated vram start: 0x%llx, size: %uMB\n", 247 (u64)base, (u32)(size >> 20)); 248 249 return 0; 250 } 251