drm: Add DRM driver for GlandaGPU (VHDL soft-IP GPU)
Subsystems (3)
v3 cover drm: Add DRM driver for GlandaGPU (VHDL soft-IP GPU)
This is v3 of the GlandaGPU DRM driver series [1][2]. It addresses review feedback from Krzysztof Kozlowski and the automated review bot on v2.
GlandaGPU is a small VHDL soft-IP 2D display controller, currently targeting a Terasic DE10-Standard (Cyclone V SoC). This series has been tested against a QEMU digital twin and on real hardware.
Hardware/VHDL: https://github.com/stiangglanda/GlandaGPU QEMU fork: https://github.com/stiangglanda/qemu-glandagpu Userspace tests: https://github.com/stiangglanda/GlandaGPU-userspace-tests
Changes since v2:
dt-bindings:
- Switch from the "glanda," vendor prefix to a personal prefix, "kieweg," since this is a personal hobby project, not backed by an organization. Update vendor-prefixes.yaml, the binding file name, and $id accordingly (Krzysztof Kozlowski).
driver core:
- Fix ignored return value of drm_mode_config_init().
- Fix hardware interrupts being left enabled if drm_dev_register() fails, which could lead to an unhandled interrupt storm.
- Add resource size validation before I/O memory mapping, closing an out-of-bounds mapping/write.
- Fix userspace atomic commits hanging when the driver falls back to polling mode (no IRQ), because vblank events were armed but never signaled.
- Enable only the INT_VSYNC interrupt. INT_DONE had been enabled unnecessarily which could cause an interrupt storm.
- Fix pixel readback to treat framebuffer data as little-endian explicitly, which broke color conversion on big-endian hosts.
- Add missing Kconfig dependencies for DRM_GLANDA.
- Use platform_get_irq_optional() instead of platform_get_irq() for the optional IRQ, avoiding log spam.
- Drop drm_info()/drm_warn() messages on success paths, drop redundant "end of table" comments, and fix the of_match_table indentation (Krzysztof Kozlowski).
On the question of what this brings to the community beyond myself:
I don't have an existing user base, and I want to be upfront about that. I built this to learn how a DRM/KMS driver is put together end to end, from VHDL soft-IP to kernel driver. What it does provide is a small, complete reference for exactly that path, plus a QEMU digital twin that lets anyone poke at a GlandaGPU-compatible device without owning the physical board. I raised this same concern during the RFC review, and Thomas Zimmermann's answer at the time was that we already carry a driver for a hobbyist-built RasPi USB display, so being a hobby project is not a blocker in itself. I'd rather have this maintained in-tree, with review, than as an out-of-tree module nobody ever looks at.
[1] v1: https://lore.kernel.org/dri-devel/[email protected]/T/#t
[2] v2: https://lore.kernel.org/dri-devel/[email protected]/T/#t
Leander Kieweg (2):
dt-bindings: display: Add GlandaGPU binding drm/glanda: Add initial DRM driver for GlandaGPU
.../bindings/display/kieweg,gpu.yaml | 55 ++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 6 + drivers/gpu/drm/tiny/Kconfig | 11 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/glandagpu.c | 587 ++++++++++++++++++ 6 files changed, 662 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/kieweg,gpu.yaml create mode 100644 drivers/gpu/drm/tiny/glandagpu.c
Signature · 1 line
2.43.0
PATCH v3 1/2 dt-bindings: display: Add GlandaGPU binding
Add Device Tree binding documentation for GlandaGPU, a custom FPGA-based 2D display controller.
For hardware designs and RTL sources, see:
https://github.com/stiangglanda/GlandaGPU
--- .../bindings/display/kieweg,gpu.yaml | 55 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/kieweg,gpu.yaml
Documentation/devicetree/bindings/display/kieweg,gpu.yaml new file +55 -0
@@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/kieweg,gpu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: GlandaGPU 2D Hardware Accelerated Display Controller + +maintainers: + - Leander Kieweg <[email protected]> + +description: | + GlandaGPU is a custom FPGA soft-IP core providing a simple + 2D hardware-accelerated drawing engine with a VGA-compatible + display output. The register window covers a combined VRAM + MMIO + region, with MMIO registers at a fixed offset within it. + + For hardware designs and RTL sources, see: + https://github.com/stiangglanda/GlandaGPU + +properties: + compatible: + const: kieweg,gpu-1.0 + + reg: + maxItems: 1 + description: + Combined VRAM + MMIO register window (VRAM at offset 0, + MMIO registers at offset 0x00200000 within this range). + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + description: Bus and pixel clock provided to the FPGA IP. + +required: + - compatible + - reg + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + gpu@c0000000 { + compatible = "kieweg,gpu-1.0"; + reg = <0xc0000000 0x1000000>; + interrupt-parent = <&intc>; + interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&osc1>; + };
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -666,6 +666,8 @@ patternProperties: description: Giantplus Technology Co., Ltd. "^gira,.*": description: Gira Giersiepen GmbH & Co. KG + "^kieweg,.*": + description: Leander Kieweg "^glinet,.*": description: GL Intelligence, Inc. "^globalscale,.*":
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 1/2] dt-bindings: display: Add GlandaGPU binding
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The new vendor prefix '^kieweg,.*' is inserted out of alphabetical order in vendor-prefixes.yaml. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The new vendor prefix '^kieweg,.*' is inserted out of alphabetical order in vendor-prefixes.yaml. --
--- Patch [1]: [PATCH v3 1/2] dt-bindings: display: Add GlandaGPU binding --- commit 987b0ae0b2509987f3bf6af799a254628d7f7d34
Author: Leander Kieweg <[email protected]>
dt-bindings: display: Add GlandaGPU binding
This commit adds the Device Tree binding documentation for GlandaGPU, a custom FPGA-based 2D display controller. It also adds a new vendor prefix for the author in vendor-prefixes.yaml.
Quoted 4 lines
Documentation/devicetree/bindings/vendor-prefixes.yaml +0
-0
[ ... ]
Documentation/devicetree/bindings/vendor-prefixes.yaml patternProperties: · line 672
Quoted 6 lines
Documentation/devicetree/bindings/vendor-prefixes.yaml +2
-0@@ -668,6 +668,8 @@ patternProperties: description: Giantplus Technology Co., Ltd. "^gira,.*": description: Gira Giersiepen GmbH & Co. KG + "^kieweg,.*": + description: Leander Kieweg
[Severity: Low]
This isn't a bug, but it looks like the new vendor prefix was inserted out of alphabetical order, landing in the middle of the "g" entries. Should this be moved down to the "k" section to keep the list ordered and avoid future merge conflicts?
Quoted 3 lines
Documentation/devicetree/bindings/vendor-prefixes.yaml +0
-0"^glinet,.*": description: GL Intelligence, Inc. "^globalscale,.*":
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v3 2/2 drm/glanda: Add initial DRM driver for GlandaGPU
In reply to Leander KiewegIntroduce the core DRM/KMS driver for GlandaGPU. This driver supports basic modesetting, atomic updates via shadow plane helpers, and optional QEMU PCI probing alongside the platform driver.
--- MAINTAINERS | 6 + drivers/gpu/drm/tiny/Kconfig | 11 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/glandagpu.c | 587 +++++++++++++++++++++++++++++++ 4 files changed, 605 insertions(+) create mode 100644 drivers/gpu/drm/tiny/glandagpu.c
MAINTAINERS +6 -0
@@ -8076,6 +8076,12 @@ T: git https://gitlab.freedesktop.org/drm/misc/kernel.git F: drivers/gpu/drm/gud/ F: include/drm/gud.h +DRM DRIVER FOR GLANDAGPU +M: Leander Kieweg <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/display/kieweg,gpu.yaml +F: drivers/gpu/drm/tiny/glandagpu.c + DRM DRIVER FOR GRAIN MEDIA GM12U320 PROJECTORS M: Hans de Goede <[email protected]> S: Maintained
drivers/gpu/drm/tiny/Kconfig +11 -0
@@ -56,6 +56,17 @@ config DRM_CIRRUS_QEMU - qxl (DRM_QXL, qemu -vga qxl, works best with spice) - virtio (DRM_VIRTIO_GPU), qemu -vga virtio) +config DRM_GLANDA + tristate "GlandaGPU DRM driver" + depends on DRM && MMU && (PCI || COMPILE_TEST) + select DRM_KMS_HELPER + select DRM_GEM_SHMEM_HELPER + help + DRM/KMS driver for the GlandaGPU display controller + (FPGA soft IP). This driver supports basic modesetting, + dumb buffers, and atomic updates via shadow planes. + It also provides PCI probing for QEMU testing. + config DRM_GM12U320 tristate "GM12U320 driver for USB projectors" depends on DRM && USB && MMU
drivers/gpu/drm/tiny/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_DRM_APPLETBDRM) += appletbdrm.o obj-$(CONFIG_DRM_ARCPGU) += arcpgu.o obj-$(CONFIG_DRM_BOCHS) += bochs.o obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus-qemu.o +obj-$(CONFIG_DRM_GLANDA) += glandagpu.o obj-$(CONFIG_DRM_GM12U320) += gm12u320.o obj-$(CONFIG_DRM_PANEL_MIPI_DBI) += panel-mipi-dbi.o obj-$(CONFIG_DRM_PIXPAPER) += pixpaper.o
drivers/gpu/drm/tiny/glandagpu.c new file +587 -0
587 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 2/2] drm/glanda: Add initial DRM driver for GlandaGPU
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] `glanda_crtc_enable_vblank()` enables the hardware VSYNC interrupt without checking if an IRQ…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] glanda_crtc_enable_vblank() enables the hardware VSYNC interrupt without checking if an IRQ handler is registered, leading to an interrupt storm in polling mode.
- [High] VRAM is mapped using standard I/O instead of Write-Combining, causing a severe performance regression.
- [Medium] Unconditionally enabling the VSYNC interrupt during initialization bypasses DRM core's state management, causing unnecessary CPU wakes.
- [Low] Unconditional usage of PCI APIs breaks the build when CONFIG_PCI is disabled under COMPILE_TEST.
--
--- Patch [2]: [PATCH v3 2/2] drm/glanda: Add initial DRM driver for GlandaGPU --- commit a32b58ce69a1f7f207f85c416ed56ab0c146bd56
Author: Leander Kieweg <[email protected]>
drm/glanda: Add initial DRM driver for GlandaGPU
This commit introduces a new DRM/KMS driver for the GlandaGPU display controller. It supports basic modesetting and atomic updates via shadow planes, and allows for both platform and PCI probing.
Quoted 4 lines
drivers/gpu/drm/tiny/glandagpu.c new file +0
-0
[ ... ]
drivers/gpu/drm/tiny/glandagpu.c line 208
Quoted 7 lines
drivers/gpu/drm/tiny/glandagpu.c new file +7
-0+static int glanda_crtc_enable_vblank (struct drm_crtc *crtc) +{ +struct glanda_device *gdev =to_glanda (crtc->dev); +u32 ier; + + ier =readl (gdev->mmio_base +REG_IER ); +writel (ier |INT_VSYNC , gdev->mmio_base +REG_IER );
[Severity: High]
Could this cause an unhandled interrupt storm in polling mode?
If the driver falls back to polling mode, such as when platform_get_irq_optional() returns -ENXIO, gdev->irq is set to -1 and no handler is registered. If a userspace application calls DRM_IOCTL_WAIT_VBLANK, the DRM core will invoke this callback and enable the hardware vsync interrupt.
Since there is no IRQ handler to clear the REG_ISR register, the hardware will keep the interrupt line asserted, which might disable a shared interrupt line and affect other devices.
Quoted 3 lines
drivers/gpu/drm/tiny/glandagpu.c new file +3
-0+ +return 0 ; +}
[ ... ]
Quoted 2 lines
drivers/gpu/drm/tiny/glandagpu.c new file +2
-0+static int glanda_drm_init (struct glanda_device *gdev,int irq) +{
[ ... ]
drivers/gpu/drm/tiny/glandagpu.c line 414
Quoted 11 lines
drivers/gpu/drm/tiny/glandagpu.c new file +11
-0+if (irq >0 ) { + gdev->irq = irq; + ret =devm_request_irq (gdev->drm.dev, gdev->irq, glanda_irq_handler, +IRQF_SHARED ,"glandagpu" , gdev); +if (ret) { +drm_err (&gdev->drm,"Failed to request IRQ %d\n" , + gdev->irq); +return ret; + } + +writel (INT_VSYNC , gdev->mmio_base +REG_IER );
[Severity: Medium]
Is it necessary to unconditionally enable the hardware vsync interrupt here?
The DRM core initializes software vblank state as disabled. Because it is already considered disabled, the core won't call the disable_vblank() callback. This means the hardware will fire vsync interrupts continuously from the moment the driver loads, even when the display is idle.
Quoted 3 lines
drivers/gpu/drm/tiny/glandagpu.c new file +3
-0+ }else { +drm_warn (&gdev->drm,"No IRQ found, falling back to polling\n" ); + }
[ ... ]
Quoted 2 lines
drivers/gpu/drm/tiny/glandagpu.c new file +2
-0+static int glandagpu_probe (struct platform_device *pdev) +{
[ ... ]
drivers/gpu/drm/tiny/glandagpu.c line 462
Quoted 9 lines
drivers/gpu/drm/tiny/glandagpu.c new file +9
-0+if (resource_size (res) <GLANDA_MMIO_OFFSET +GLANDA_MMIO_SIZE ) { +dev_err (&pdev->dev,"MMIO region too small: %llu bytes, need at least %u\n" , + (unsigned long long )resource_size (res), +GLANDA_MMIO_OFFSET +GLANDA_MMIO_SIZE ); +return -EINVAL ; + } + + gdev->vram_phys = res->start; + gdev->vram_base =devm_ioremap (&pdev->dev, res->start,GLANDA_VRAM_SIZE );
[Severity: High]
Will this cause severe CPU stalling during atomic frame updates?
The devm_ioremap() function creates a strongly uncacheable memory mapping. Since glanda_plane_atomic_update() writes hundreds of thousands of pixels individually using writel_relaxed(), each write will traverse the bus separately.
Should this memory be mapped using write-combining (e.g., devm_ioremap_wc()) so the CPU can burst writes efficiently?
Quoted 2 lines
drivers/gpu/drm/tiny/glandagpu.c new file +2
-0+ gdev->mmio_base =devm_ioremap (&pdev->dev, res->start +GLANDA_MMIO_OFFSET , +GLANDA_MMIO_SIZE );
[ ... ]
drivers/gpu/drm/tiny/glandagpu.c line 503
Quoted 12 lines
drivers/gpu/drm/tiny/glandagpu.c new file +12
-0+static struct platform_driver glandagpu_driver = { + .driver = { + .name ="glandagpu" , + .of_match_table = glanda_of_match, + }, + .probe = glandagpu_probe, + .remove = glandagpu_remove, +}; + +/* PCI probe path for the QEMU test device, real hardware uses platform_driver */ +static int glandagpu_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{
[Severity: Low]
Does this code break the build when the kernel is configured with CONFIG_DRM_GLANDA=y, CONFIG_COMPILE_TEST=y, and CONFIG_PCI=n?
The Kconfig explicitly allows building without PCI for test coverage, but functions like pcim_iomap_regions() and pcim_iomap_table() do not have fallback stubs in the headers when PCI is disabled.
Should the PCI-specific driver code be guarded by #ifdef CONFIG_PCI?
Quoted 7 lines
drivers/gpu/drm/tiny/glandagpu.c new file +7
-0+struct glanda_device *gdev; +int ret; + + ret =pcim_enable_device (pdev); +if (ret) +return ret; +pci_set_master (pdev);
drivers/gpu/drm/tiny/glandagpu.c line 520
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+ +if (pci_resource_len (pdev,0 ) <GLANDA_MMIO_SIZE || +pci_resource_len (pdev,1 ) <GLANDA_VRAM_SIZE ) { +dev_err (&pdev->dev,"BAR too small: BAR0=%llu (need %u), BAR1=%llu (need %u)\n" , + (unsigned long long )pci_resource_len (pdev,0 ),GLANDA_MMIO_SIZE , + (unsigned long long )pci_resource_len (pdev,1 ),GLANDA_VRAM_SIZE ); +return -EINVAL ; + } + + ret =pcim_iomap_regions (pdev,BIT (0 ) |BIT (1 ),"glandagpu" );
[Severity: High]
Similar to the platform probe, does this create a strongly uncacheable mapping for VRAM?
pcim_iomap_regions() defaults to standard I/O mappings. This will likely cause the same performance degradation during frame updates.
Quoted 2 lines
drivers/gpu/drm/tiny/glandagpu.c new file +2
-0+if (ret) +return ret;
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Thomas Zimmermann
maintainerRe: [PATCH v3 2/2] drm/glanda: Add initial DRM driver for GlandaGPU
In reply to Leander KiewegHi
Am 24.08.26 um 21:54 schrieb Leander Kieweg:
Quoted 149 lines
Introduce the core DRM/KMS driver for GlandaGPU. This driver supports basic modesetting, atomic updates via shadow plane helpers, and optional QEMU PCI probing alongside the platform driver.
Signed-off-by Leander Kieweg <[email protected]>--- MAINTAINERS | 6 + drivers/gpu/drm/tiny/Kconfig | 11 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/glandagpu.c | 587 +++++++++++++++++++++++++++++++ 4 files changed, 605 insertions(+)create mode 100644
drivers/gpu/drm/tiny/glandagpu.cMAINTAINERS +6
-0@@ -8076,6 +8076,12 @@ T: git https://gitlab.freedesktop.org/drm/misc/kernel.git F: drivers/gpu/drm/gud/ F: include/drm/gud.h +DRM DRIVER FOR GLANDAGPU +M: Leander Kieweg <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/display/kieweg,gpu.yaml +F: drivers/gpu/drm/tiny/glandagpu.c + DRM DRIVER FOR GRAIN MEDIA GM12U320 PROJECTORS M: Hans de Goede <[email protected]> S: Maintaineddrivers/gpu/drm/tiny/Kconfig +11
-0@@ -56,6 +56,17 @@ config DRM_CIRRUS_QEMU - qxl (DRM_QXL, qemu -vga qxl, works best with spice) - virtio (DRM_VIRTIO_GPU), qemu -vga virtio) +config DRM_GLANDA + tristate "GlandaGPU DRM driver" + depends on DRM && MMU && (PCI || COMPILE_TEST) + select DRM_KMS_HELPER + select DRM_GEM_SHMEM_HELPER + help + DRM/KMS driver for the GlandaGPU display controller + (FPGA soft IP). This driver supports basic modesetting, + dumb buffers, and atomic updates via shadow planes. + It also provides PCI probing for QEMU testing. + config DRM_GM12U320 tristate "GM12U320 driver for USB projectors" depends on DRM && USB && MMUdrivers/gpu/drm/tiny/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_DRM_APPLETBDRM) += appletbdrm.o obj-$(CONFIG_DRM_ARCPGU) += arcpgu.o obj-$(CONFIG_DRM_BOCHS) += bochs.o obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus-qemu.o +obj-$(CONFIG_DRM_GLANDA) += glandagpu.o obj-$(CONFIG_DRM_GM12U320) += gm12u320.o obj-$(CONFIG_DRM_PANEL_MIPI_DBI) += panel-mipi-dbi.o obj-$(CONFIG_DRM_PIXPAPER) += pixpaper.odrivers/gpu/drm/tiny/glandagpu.c new file +79
-0@@ -0,0 +1,587 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/platform_device.h> +#include <linux/pci.h> +#include <linux/io.h> +#include <linux/delay.h> /* udelay (polling) */ +#include <linux/of.h> +#include <linux/slab.h> /* GFP_KERNEL */ +#include <linux/interrupt.h> +#include <linux/wait.h> +#include <linux/mm.h> +#include <linux/mutex.h> +#include <linux/iosys-map.h> + +#include <drm/drm_drv.h> +#include <drm/drm_device.h> +#include <drm/drm_file.h> +#include <drm/drm_gem.h> +#include <drm/drm_ioctl.h> +#include <drm/drm_gem_shmem_helper.h> +#include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_framebuffer.h> +#include <drm/drm_vblank.h> + +#include <drm/drm_connector.h> +#include <drm/drm_encoder.h> +#include <drm/drm_modeset_helper.h> +#include <drm/drm_probe_helper.h> +#include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_crtc.h> +#include <drm/drm_crtc_helper.h> +#include <drm/drm_modeset_helper_vtables.h> +#include <drm/drm_plane.h> +#include <drm/drm_fourcc.h> +#include <drm/drm_atomic.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_damage_helper.h> +#include <drm/drm_print.h> + +/* Hardware Constants */ +#define GLANDA_WIDTH 640 +#define GLANDA_HEIGHT 480 +#define GLANDA_VRAM_SIZE (GLANDA_WIDTH * GLANDA_HEIGHT * 4) +#define GLANDA_MMIO_SIZE 32 +#define GLANDA_MMIO_OFFSET 0x00200000 + +/* QEMU test device ID, from the range reserved for experimental use (docs/specs/pci-ids.rst). */ +#define PCI_DEVICE_ID_GLANDA_GPU 0x10f0 + +/* Register Offsets */ +#define REG_STATUS 0x00 +#define REG_CTRL 0x04 +#define REG_COORD0 0x08 +#define REG_COORD1 0x0C +#define REG_COLOR 0x10 +#define REG_ISR 0x14 +#define REG_IER 0x18 + +/* Bit Masks */ +#define INT_DONE BIT(0) +#define INT_VSYNC BIT(1) + +#define STATUS_BUSY BIT(0) +#define CMD_CLEAR (0x1) +#define CMD_RECT (0x2) +#define CMD_LINE (0x3) +#define CTRL_START BIT(4) + +struct glanda_device { +struct drm_device drm; + +/* hw */ +void __iomem *mmio_base; +void __iomem *vram_base; +phys_addr_t vram_phys; +
drivers/gpu/drm/tiny/glandagpu.c line 89
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+int irq; + +/* drm */ +struct drm_plane primary_plane; +struct drm_crtc crtc; +struct drm_encoder encoder; +struct drm_connector connector; +}; + +#define to_glanda (dev) container_of(dev, struct glanda_device, drm)
container_of_const() is nowadays preferred over container_of()
Quoted 7 lines
drivers/gpu/drm/tiny/glandagpu.c new file +7
-0+ +static const u32 glanda_plane_formats[] = { +DRM_FORMAT_XRGB8888 , +}; + +static void glanda_plane_atomic_update (struct drm_plane *plane, +struct drm_atomic_commit *state)
drivers/gpu/drm/tiny/glandagpu.c line 106
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+{ +struct drm_plane_state *new_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_shadow_plane_state *shadow_state =to_drm_shadow_plane_state (new_state); +struct drm_framebuffer *fb = new_state->fb; +struct glanda_device *gdev =to_glanda (plane->dev); +u32 src_pitch, width, height, x, y; +int idx; + +if (!fb) +return ;
If you return here, you can never clear the display. Typically, the CRTC would disable the VGA sync and thereby clear the display. But the CRTC code doesn't do that. The alternative for displays that cannot blank via CRTC is to memset the video memory to 0. You can do this here before returning.
drivers/gpu/drm/tiny/glandagpu.c line 110
Quoted 4 lines
drivers/gpu/drm/tiny/glandagpu.c new file +4
-0+ +if (!drm_dev_enter (plane->dev, &idx)) +return ; +
Below, your driver reads the buffer object's memory to copy it to the video memory. The buffer object's memory could have been imported from another driver, which keeps streaming data into it. Therefore it requires synchronization first.
Direct buffer access needs to be wrapped in drm_gem_fb_begin_cpu_access() and drm_gem_fb_end_cpu_access(). See [1] for a simple example.
Quoted 9 lines
drivers/gpu/drm/tiny/glandagpu.c new file +9
-0+ src_pitch = fb->pitches[0 ]; + width =min_t (u32, fb->width,GLANDA_WIDTH ); + height =min_t (u32, fb->height,GLANDA_HEIGHT ); + +for (y =0 ; y < height; y++) { +size_t offset = y *GLANDA_WIDTH *sizeof (u32); +u32 __iomem *dst = (u32 __iomem *)(gdev->vram_base + offset); + +for (x =0 ; x < width; x++) {
drivers/gpu/drm/tiny/glandagpu.c line 129
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+u32 pixel =iosys_map_rd (&shadow_state->data[0 ], + y * src_pitch + x *sizeof (u32), u32); + pixel =le32_to_cpu ((__force __le32 )pixel); +u32 packed = ((pixel >>12 ) &0x0F00 ) | + ((pixel >>8 ) &0x00F0 ) | + ((pixel >>4 ) &0x000F ); + +writel_relaxed (packed, &dst[x]); + } + }
Your driver cannot directly loop over the framebuffer to copy it over.
1) Instead use damage iterators. Damage handling lets user space clip against areas that have been changed between frames. For example, if the user moves the mouse pointer, it would not update the whole screen, but only the small area around the cursor image. AFAICT damage handling is the main reason why the simple displays have any usable performace at all.
2) The framebuffer might be larger than the video memory and be panned (i.e., moved around). Details are stored in the plane state. Your driver needs to calculate the position in video memory from the plane state. See the loop at [2] for how to do this.
Quoted 9 lines
drivers/gpu/drm/tiny/glandagpu.c new file +9
-0+ +drm_dev_exit (idx); +} + +static int glanda_plane_atomic_check (struct drm_plane *plane, +struct drm_atomic_commit *state) +{ +struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_crtc_state *crtc_state;
drivers/gpu/drm/tiny/glandagpu.c line 148
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+ +if (!new_plane_state->crtc) +return 0 ; + + crtc_state =drm_atomic_get_new_crtc_state (state, new_plane_state->crtc); + +return drm_atomic_helper_check_plane_state (new_plane_state, crtc_state, +DRM_PLANE_NO_SCALING ,DRM_PLANE_NO_SCALING , + false,/* can_position */ + false/* can_update_disabled */ );
Your driver should call drm_atomic_helper_check_plane_state() in any case. So don't return earlier than that. See [3] for the pattern of how to do this.
Quoted 42 lines
drivers/gpu/drm/tiny/glandagpu.c new file +42
-0+} + +static const struct drm_plane_helper_funcs glanda_plane_helper_funcs = { +DRM_GEM_SHADOW_PLANE_HELPER_FUNCS , + .atomic_update = glanda_plane_atomic_update, + .atomic_check = glanda_plane_atomic_check, +}; + +static const struct drm_plane_funcs glanda_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = drm_plane_cleanup, +DRM_GEM_SHADOW_PLANE_FUNCS , +}; + +static int glanda_connector_get_modes (struct drm_connector *connector) +{ +struct drm_display_mode *mode; + + mode =drm_mode_create (connector->dev); +if (!mode) { +dev_err (connector->dev->dev,"GlandaGPU: failed to create display mode\n" ); +return 0 ; + } + +/* Standard VGA timing: 640x480 @ 60 Hz. */ + mode->hdisplay =640 ; + mode->hsync_start =656 ; + mode->hsync_end =752 ; + mode->htotal =800 ; + + mode->vdisplay =480 ; + mode->vsync_start =490 ; + mode->vsync_end =492 ; + mode->vtotal =525 ; + + mode->clock =25175 ;/* 25.175 MHz pixel clock */ + + mode->flags =DRM_MODE_FLAG_NHSYNC |DRM_MODE_FLAG_NVSYNC ; + mode->type =DRM_MODE_TYPE_DRIVER |DRM_MODE_TYPE_PREFERRED ; + +drm_mode_set_name (mode);
drivers/gpu/drm/tiny/glandagpu.c line 200
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+drm_mode_probed_add (connector, mode); + +return 1 ; +} + +static enum drm_connector_status glanda_connector_detect (struct drm_connector + *connector,bool force) +{ +return connector_status_connected; +}
You can leave out this function. The default value is 'connected'.
drivers/gpu/drm/tiny/glandagpu.c line 208
Quoted 8 lines
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+ +static int glanda_crtc_enable_vblank (struct drm_crtc *crtc) +{ +struct glanda_device *gdev =to_glanda (crtc->dev); +u32 ier; + + ier =readl (gdev->mmio_base +REG_IER ); +writel (ier |INT_VSYNC , gdev->mmio_base +REG_IER );
Please see the Sashiko bot's comment on this code.
You also have to wrap all hardware access in drm_dev_begin() and drm_dev_end().
Quoted 7 lines
drivers/gpu/drm/tiny/glandagpu.c new file +7
-0+ +return 0 ; +} + +static void glanda_crtc_disable_vblank (struct drm_crtc *crtc) +{ +struct glanda_device *gdev =to_glanda (crtc->dev);
drivers/gpu/drm/tiny/glandagpu.c line 225
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+u32 ier =readl (gdev->mmio_base +REG_IER ); + +writel (ier & ~INT_VSYNC , gdev->mmio_base +REG_IER ); +} + +static void glanda_crtc_atomic_enable (struct drm_crtc *crtc, +struct drm_atomic_commit *state) +{ +drm_crtc_vblank_on (crtc); +}
Since you're only doing vblank_on, please use drm_crtc_vblank_atomic_enable()
drivers/gpu/drm/tiny/glandagpu.c line 231
Quoted 6 lines
drivers/gpu/drm/tiny/glandagpu.c new file +6
-0+ +static void glanda_crtc_atomic_disable (struct drm_crtc *crtc, +struct drm_atomic_commit *state) +{ +drm_crtc_vblank_off (crtc); +}
drm_crtc_vblank_atomic_disable()
Quoted 60 lines
drivers/gpu/drm/tiny/glandagpu.c new file +60
-0+ +static void glanda_crtc_atomic_flush (struct drm_crtc *crtc, +struct drm_atomic_commit *state) +{ +struct glanda_device *gdev =to_glanda (crtc->dev); +struct drm_crtc_state *new_state =drm_atomic_get_new_crtc_state (state, crtc); +struct drm_pending_vblank_event *event; + +if (new_state->event) { + event = new_state->event; + new_state->event =NULL ; + +spin_lock_irq (&crtc->dev->event_lock); + +if (gdev->irq >0 &&drm_crtc_vblank_get (crtc) ==0 ) +drm_crtc_arm_vblank_event (crtc, event); +else +drm_crtc_send_vblank_event (crtc, event); + +spin_unlock_irq (&crtc->dev->event_lock); + } +} + +static const struct drm_crtc_funcs glanda_crtc_funcs = { + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .reset = drm_atomic_helper_crtc_reset, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, + .enable_vblank = glanda_crtc_enable_vblank, + .disable_vblank = glanda_crtc_disable_vblank, +}; + +static const struct drm_crtc_helper_funcs glanda_crtc_helper_funcs = { + .atomic_enable = glanda_crtc_atomic_enable, + .atomic_disable = glanda_crtc_atomic_disable, + .atomic_flush = glanda_crtc_atomic_flush, +}; + +static const struct drm_connector_helper_funcs glanda_connector_helper_funcs = { + .get_modes = glanda_connector_get_modes, +}; + +static const struct drm_encoder_funcs glanda_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + +static const struct drm_connector_funcs glanda_connector_funcs = { + .fill_modes = drm_helper_probe_single_connector_modes, + .destroy = drm_connector_cleanup, + .detect = glanda_connector_detect, + .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_mode_config_funcs glanda_mode_config_funcs = { + .fb_create = drm_gem_fb_create_with_dirty, + .atomic_check = drm_atomic_helper_check,
drivers/gpu/drm/tiny/glandagpu.c line 301
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+ .atomic_commit = drm_atomic_helper_commit, +}; + +DEFINE_DRM_GEM_FOPS (glanda_drm_fops); + +static const struct drm_driver glanda_drm_driver = { + .driver_features = +DRIVER_GEM |DRIVER_MODESET |DRIVER_ATOMIC , + .name ="glandagpu" , + .desc ="GlandaGPU Hardware Accelerated DRM Driver" ,
"Hardware Accelerated" is kind of overselling it :)
Quoted 30 lines
drivers/gpu/drm/tiny/glandagpu.c new file +30
-0+ .major = 1, + .minor = 0, + .fops = &glanda_drm_fops, + .dumb_create = drm_gem_shmem_dumb_create, +}; + +static irqreturn_t glanda_irq_handler (int irq,void *dev_id) +{ +struct glanda_device *gdev = dev_id; +u32 isr, ier; + +if (!gdev || !gdev->mmio_base) +return IRQ_NONE ; + + isr =readl (gdev->mmio_base +REG_ISR ); + ier =readl (gdev->mmio_base +REG_IER ); + +if (!(isr & ier)) +return IRQ_NONE ; + +if (isr &INT_VSYNC ) +drm_crtc_handle_vblank (&gdev->crtc); + +/* Clear interrupt(W1C) */ +writel (isr, gdev->mmio_base +REG_ISR ); +return IRQ_HANDLED ; +} + +/* Common DRM setup once MMIO/VRAM/IRQ are known(used by both probe paths) */ +static int glanda_drm_init (struct glanda_device *gdev,int irq)
drivers/gpu/drm/tiny/glandagpu.c line 341
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+{ +int ret; + + gdev->irq =-1 ; + +writel (0 , gdev->mmio_base +REG_IER ); +writel (0xFFFFFFFF , gdev->mmio_base +REG_ISR );/* clear flags */ + +/* DRM mode config */ + ret =drm_mode_config_init (&gdev->drm);
Please use drmm_mode_config_init() to that it cleans up the modesetting pipeline automatically.
drivers/gpu/drm/tiny/glandagpu.c line 348
Quoted 7 lines
drivers/gpu/drm/tiny/glandagpu.c new file +7
-0+if (ret) +return ret; + + gdev->drm.mode_config.min_width =640 ; + gdev->drm.mode_config.min_height =480 ; + gdev->drm.mode_config.max_width =640 ; + gdev->drm.mode_config.max_height =480 ;
Rather use DRM_SHADOW_PLANE_MAX_WIDTH and DRM_SHADOW_PLANE_MAX_HEIGHT for the max values. Userspace can be picky about framebuffer sizes and this should handle it. It will also allow userspace to do panning on your driver.
drivers/gpu/drm/tiny/glandagpu.c line 360
Quoted 12 lines
drivers/gpu/drm/tiny/glandagpu.c new file +12
-0+ gdev->drm.mode_config.funcs = &glanda_mode_config_funcs; + + ret =drm_universal_plane_init (&gdev->drm, &gdev->primary_plane,1 <<0 , + &glanda_plane_funcs, + glanda_plane_formats, +ARRAY_SIZE (glanda_plane_formats),NULL , +DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret) { +drm_err (&gdev->drm,"Failed to initialize primary plane\n" ); +return ret; + } +drm_plane_helper_add (&gdev->primary_plane, &glanda_plane_helper_funcs);
Call drm_plane_enable_fb_damage_clips() here to enable damage clipping. You really want this for improving overhead and performance.
drivers/gpu/drm/tiny/glandagpu.c line 363
Quoted 3 lines
drivers/gpu/drm/tiny/glandagpu.c new file +3
-0+ +/* VBlank init */ + ret =drm_vblank_init (&gdev->drm,1 );
I suggest to call this right before drm_mode_config_reset().
Quoted 26 lines
drivers/gpu/drm/tiny/glandagpu.c new file +26
-0+if (ret) { +drm_err (&gdev->drm,"Failed to initialize vblank\n" ); +return ret; + } + +/* CRTC init */ + ret =drm_crtc_init_with_planes (&gdev->drm, &gdev->crtc, + &gdev->primary_plane,NULL , + &glanda_crtc_funcs,NULL ); +if (ret) { +drm_err (&gdev->drm,"Failed to initialize CRTC with planes\n" ); +return ret; + } +drm_crtc_helper_add (&gdev->crtc, &glanda_crtc_helper_funcs); + + ret =drm_encoder_init (&gdev->drm, &gdev->encoder, &glanda_encoder_funcs, +DRM_MODE_ENCODER_DAC ,NULL ); +if (ret) { +drm_err (&gdev->drm,"Failed to initialize encoder\n" ); +return ret; + } + gdev->encoder.possible_crtcs =1 ; + + ret =drm_connector_init (&gdev->drm, &gdev->connector, + &glanda_connector_funcs,DRM_MODE_CONNECTOR_VGA ); +if (ret) {
drivers/gpu/drm/tiny/glandagpu.c line 399
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+drm_err (&gdev->drm,"Failed to initialize connector\n" ); +return ret; + } +drm_connector_helper_add (&gdev->connector, &glanda_connector_helper_funcs); + +drm_connector_attach_encoder (&gdev->connector, &gdev->encoder); + +/* Populate connector state early so userspace can enumerate modes. */ +mutex_lock (&gdev->drm.mode_config.mutex); +drm_helper_probe_single_connector_modes (&gdev->connector,1024 ,768 );
Please don't do this. The DRM framework takes care if it and will populate the mode list when user space needs it.
Quoted 5 lines
drivers/gpu/drm/tiny/glandagpu.c new file +5
-0+mutex_unlock (&gdev->drm.mode_config.mutex); + +drm_mode_config_reset (&gdev->drm); + +if (irq >0 ) {
drivers/gpu/drm/tiny/glandagpu.c line 414
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+ gdev->irq = irq; + ret =devm_request_irq (gdev->drm.dev, gdev->irq, glanda_irq_handler, +IRQF_SHARED ,"glandagpu" , gdev); +if (ret) { +drm_err (&gdev->drm,"Failed to request IRQ %d\n" , + gdev->irq); +return ret; + } + +writel (INT_VSYNC , gdev->mmio_base +REG_IER );
Don't enable IRQs unconditionally.
Quoted 8 lines
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+ }else { +drm_warn (&gdev->drm,"No IRQ found, falling back to polling\n" ); + } + + ret =drm_dev_register (&gdev->drm,0 ); +if (ret) { +writel (0 , gdev->mmio_base +REG_IER ); +return ret;
drivers/gpu/drm/tiny/glandagpu.c line 432
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+ } + +return 0 ; +} + +/* Shared teardown, mirrors glanda_drm_init() */ +static void glanda_drm_fini (struct glanda_device *gdev) +{ +drm_dev_unplug (&gdev->drm); +drm_atomic_helper_shutdown (&gdev->drm);
Rather just unplug. After unplug, no hardware access will be done.
drivers/gpu/drm/tiny/glandagpu.c line 435
Quoted 3 lines
drivers/gpu/drm/tiny/glandagpu.c new file +3
-0+ +/* Disable interrupts */ +writel (0 , gdev->mmio_base +REG_IER );
You don't have to disable IRQs here, as DRM should do this during shutdown.
Best regards
Thomas
Quoted 152 lines
drivers/gpu/drm/tiny/glandagpu.c new file +152
-0+} + +static int glandagpu_probe (struct platform_device *pdev) +{ +struct resource *res; +struct glanda_device *gdev; +int irq; + + gdev = devm_drm_dev_alloc(&pdev->dev, &glanda_drm_driver, struct glanda_device, drm); +if (IS_ERR (gdev)) +return PTR_ERR (gdev); + +platform_set_drvdata (pdev, gdev); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -ENODEV ; + +if (resource_size (res) <GLANDA_MMIO_OFFSET +GLANDA_MMIO_SIZE ) { +dev_err (&pdev->dev,"MMIO region too small: %llu bytes, need at least %u\n" , + (unsigned long long )resource_size (res), +GLANDA_MMIO_OFFSET +GLANDA_MMIO_SIZE ); +return -EINVAL ; + } + + gdev->vram_phys = res->start; + gdev->vram_base =devm_ioremap (&pdev->dev, res->start,GLANDA_VRAM_SIZE ); + gdev->mmio_base =devm_ioremap (&pdev->dev, res->start +GLANDA_MMIO_OFFSET , +GLANDA_MMIO_SIZE ); +if (!gdev->vram_base || !gdev->mmio_base) { +drm_err (&gdev->drm,"failed to ioremap\n" ); +return -ENOMEM ; + } + + irq =platform_get_irq_optional (pdev,0 ); +if (irq == -ENXIO ) + irq =-1 ;/* no IRQ resource, fall back to polling */ +else if (irq <0 ) +return irq; + +return glanda_drm_init (gdev, irq); +} + +static void glandagpu_remove (struct platform_device *pdev) +{ +glanda_drm_fini (platform_get_drvdata (pdev)); +} + +/* Device Tree match table. */ +static const struct of_device_id glanda_of_match[] = { + { .compatible ="kieweg,gpu-1.0" }, + { } +}; + +MODULE_DEVICE_TABLE (of, glanda_of_match); + +static struct platform_driver glandagpu_driver = { + .driver = { + .name ="glandagpu" , + .of_match_table = glanda_of_match, + }, + .probe = glandagpu_probe, + .remove = glandagpu_remove, +}; + +/* PCI probe path for the QEMU test device, real hardware uses platform_driver */ +static int glandagpu_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +struct glanda_device *gdev; +int ret; + + ret =pcim_enable_device (pdev); +if (ret) +return ret; +pci_set_master (pdev); + +if (pci_resource_len (pdev,0 ) <GLANDA_MMIO_SIZE || +pci_resource_len (pdev,1 ) <GLANDA_VRAM_SIZE ) { +dev_err (&pdev->dev,"BAR too small: BAR0=%llu (need %u), BAR1=%llu (need %u)\n" , + (unsigned long long )pci_resource_len (pdev,0 ),GLANDA_MMIO_SIZE , + (unsigned long long )pci_resource_len (pdev,1 ),GLANDA_VRAM_SIZE ); +return -EINVAL ; + } + + ret =pcim_iomap_regions (pdev,BIT (0 ) |BIT (1 ),"glandagpu" ); +if (ret) +return ret; + + gdev = devm_drm_dev_alloc(&pdev->dev, &glanda_drm_driver, struct glanda_device, drm); +if (IS_ERR (gdev)) +return PTR_ERR (gdev); + +pci_set_drvdata (pdev, gdev); + + gdev->mmio_base =pcim_iomap_table (pdev)[0 ]; + gdev->vram_base =pcim_iomap_table (pdev)[1 ]; + gdev->vram_phys =pci_resource_start (pdev,1 ); + +return glanda_drm_init (gdev, pdev->irq); +} + +static void glandagpu_pci_remove (struct pci_dev *pdev) +{ +glanda_drm_fini (pci_get_drvdata (pdev)); +} + +static const struct pci_device_id glanda_pci_ids[] = { + {PCI_DEVICE (PCI_VENDOR_ID_REDHAT_QUMRANET ,PCI_DEVICE_ID_GLANDA_GPU ) }, + { } +}; + +MODULE_DEVICE_TABLE (pci, glanda_pci_ids); + +static struct pci_driver glandagpu_pci_driver = { + .name ="glandagpu-pci" , + .id_table = glanda_pci_ids, + .probe = glandagpu_pci_probe, + .remove = glandagpu_pci_remove, +}; + +static int __init glandagpu_init (void ) +{ +int ret; + + ret =platform_driver_register (&glandagpu_driver); +if (ret) { +pr_err ("GlandaGPU: Failed to register platform driver\n" ); +return ret; + } + + ret =pci_register_driver (&glandagpu_pci_driver); +if (ret) { +pr_err ("GlandaGPU: Failed to register PCI driver\n" ); +platform_driver_unregister (&glandagpu_driver); +return ret; + } + +return 0 ; +} + +static void __exit glandagpu_exit(void) +{ +pci_unregister_driver (&glandagpu_pci_driver); +platform_driver_unregister (&glandagpu_driver); +} + +module_init (glandagpu_init); +module_exit (glandagpu_exit); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Leander Kieweg <[email protected]>" ); +MODULE_DESCRIPTION ("DRM driver for GlandaGPU, an FPGA-based 2D GPU with VGA output" );
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
Re: [PATCH v3 2/2] drm/glanda: Add initial DRM driver for GlandaGPU
Am Mi., 2. Sept. 2026 um 12:03 Uhr schrieb Thomas Zimmermann <[email protected]>:
Hi Thomas,
Thank you for the very detailed review. I'll address every point in v4.
Best regards,
Leander