drm: Add DRM driver for GlandaGPU (VHDL soft-IP GPU)
Subsystems (3)
v2 cover drm: Add DRM driver for GlandaGPU (VHDL soft-IP GPU)
This is v2 of the GlandaGPU DRM driver series [1], addressing review feedback from Thomas Zimmermann, Conor Dooley, Uwe Kleine-König, and the automated review bot on v1.
GlandaGPU is a small VHDL soft-IP 2D display controller, currently targeting a Terasic DE10-Standard (Cyclone V SoC). This series has been tested both 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 v1:
dt-bindings:
- add a link to the GlandaGPU project in the binding description
- add clocks to the required properties
- fix the example to use interrupt-parent and the GIC_SPI/ IRQ_TYPE_LEVEL_HIGH macros instead of raw numbers
- fix missing trailing newline
driver core:
- drop the struct device *dev field, use drm_device.dev instead
- open-code drm_encoder_init() instead of drm_simple_encoder_init(), which is being phased out
- switch the plane update path from manual dma_resv_lock()/ drm_gem_shmem_vmap_locked() to DRM_GEM_SHADOW_PLANE_HELPER_FUNCS/ DRM_GEM_SHADOW_PLANE_FUNCS. This also fixes sleeping calls being made from atomic-commit context and a raw map.vaddr dereference, both flagged by automated review
- use drm_gem_fb_create_with_dirty() instead of a custom fb_create implementation
- remove the redundant new_state == NULL check in the CRTC flush helper
- remove the ioctl-based UAPI (CLEAR/RECT/LINE) entirely. As Thomas pointed out in v1, fixed-function 2D ioctls aren't a good fit for mainline DRM, and userspace rendering into the shadow-plane framebuffer covers the same functionality
- fix a double drm_mode_config_cleanup() call in the probe and remove error paths (devres already handles this)
- call drm_atomic_helper_shutdown() on remove
- fix a teardown race where in-flight work could touch already unmapped MMIO, using drm_dev_unplug()/drm_dev_enter()/ drm_dev_exit()
- move IRQ registration to after CRTC initialization, avoiding a potential NULL pointer dereference from an early-firing shared IRQ
- fix platform_get_irq() error handling. Negative error codes such as -EPROBE_DEFER were previously misread as "no IRQ available"
new in v2:
- add PCI probe support alongside the existing platform_driver/ devicetree path, backed by a matching QEMU device model, so the driver can be tested against a virtual device without needing devicetree or real hardware. Real hardware continues to use the platform_driver path unchanged. This replaces the old x86 test device patch 3/3, reducing the series from 3 to 2 patches.
Known open item: the QEMU test device currently uses a placeholder ID from the range QEMU reserves for experimental, unregistered use (1af4:10f0, see [2]). I've requested a permanent
ID from Gerd Hoffmann and will post a follow-up once it's assigned.
[1] https://lore.kernel.org/dri-devel/[email protected]/T/#t
[2] https://www.qemu.org/docs/master/specs/pci-ids.html
Leander Kieweg (2):
dt-bindings: display: Add GlandaGPU binding drm/glanda: Add initial DRM driver for GlandaGPU
.../bindings/display/glanda,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 | 579 ++++++++++++++++++ 6 files changed, 654 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/glanda,gpu.yaml create mode 100644 drivers/gpu/drm/tiny/glandagpu.c
Signature · 1 line
2.43.0
PATCH v2 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/glanda,gpu.yaml | 55 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/glanda,gpu.yaml
Documentation/devicetree/bindings/display/glanda,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/glanda,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: glanda,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 = "glanda,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 + "^glanda,.*": + description: GlandaGPU "^glinet,.*": description: GL Intelligence, Inc. "^globalscale,.*":
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] dt-bindings: display: Add GlandaGPU binding
Quoted 32 lines · Leander Kieweg
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/GlandaGPUSigned-off-by Leander Kieweg <[email protected]>--- .../bindings/display/glanda,gpu.yaml | 55 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/glanda,gpu.yamlDocumentation/devicetree/bindings/display/glanda,gpu.yaml new file +13
-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/glanda,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
Documentation/devicetree/bindings/display/glanda,gpu.yaml line 23
Quoted 10 lines
Documentation/devicetree/bindings/display/glanda,gpu.yaml new file +10
-0+ 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: glanda,gpu-1.0
What does this 1.0 correspond to? There is no such tag on linked Github.
Quoted 37 lines
Documentation/devicetree/bindings/display/glanda,gpu.yaml new file +32
-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 = "glanda,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 +0
-0
Documentation/devicetree/bindings/vendor-prefixes.yaml patternProperties: · line 670
Quoted 5 lines
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 + "^glanda,.*": + description: GlandaGPU
Vendor prefixes are per actual vendor, not product.
I have doubts this is needed in the first place. As a pure FPGA design, this cannot work alone and you cannot get it alone (at least yet, happily to see resources proving me wrong). Thus it will be always customized per final board design, thus that final compatible is what matters.
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-bindings: display: Add GlandaGPU binding
Thanks for the review.
Quoted 5 lines
Documentation/devicetree/bindings/display/glanda,gpu.yaml line 23
Quoted 3 lines
Documentation/devicetree/bindings/display/glanda,gpu.yaml new file +3
-0+properties: + compatible: + const: glanda,gpu-1.0What does this 1.0 correspond to? There is no such tag on linked Github.
I've pushed a v1.0 tag to the GlandaGPU repo now, matching the register interface described in this binding:
https://github.com/stiangglanda/GlandaGPU/releases/tag/v1.0
Quoted 10 lines
Documentation/devicetree/bindings/vendor-prefixes.yaml patternProperties: · line 670
Quoted 2 lines
Documentation/devicetree/bindings/vendor-prefixes.yaml +2
-0+ "^glanda,.*": + description: GlandaGPUVendor prefixes are per actual vendor, not product.
I have doubts this is needed in the first place. As a pure FPGA design, this cannot work alone and you cannot get it alone (at least yet, happily to see resources proving me wrong). Thus it will be always customized per final board design, thus that final compatible is what matters.
"opencores" and "openrisc" are both accepted vendor prefixes for open-source hardware projects rather than commercial vendors, so a project name seems reasonable to me here too.
That said, I take your point about board customization. I'm happy to add a board-specific compatible as the primary match, with "glanda,gpu-1.0" as the fallback, e.g.:
compatible = "terasic,de10-standard-glandagpu", "glanda,gpu-1.0";
The driver would keep matching on "glanda,gpu-1.0". Let me know if you'd like this for v3, or if the generic compatible is enough for now, since there's currently only one board using this core.
Best regards,
Leander
Re: [PATCH v2 1/2] dt-bindings: display: Add GlandaGPU binding
Quoted 31 lines · Leander Kieweg
Thanks for the review.
Quoted 5 lines
Documentation/devicetree/bindings/display/glanda,gpu.yaml line 23
Quoted 3 lines
Documentation/devicetree/bindings/display/glanda,gpu.yaml new file +3
-0+properties: + compatible: + const: glanda,gpu-1.0What does this 1.0 correspond to? There is no such tag on linked Github.
I've pushed a v1.0 tag to the GlandaGPU repo now, matching the register interface described in this binding:
https://github.com/stiangglanda/GlandaGPU/releases/tag/v1.0Quoted 10 lines
Documentation/devicetree/bindings/vendor-prefixes.yaml patternProperties: · line 670
Quoted 2 lines
Documentation/devicetree/bindings/vendor-prefixes.yaml +2
-0+ "^glanda,.*": + description: GlandaGPUVendor prefixes are per actual vendor, not product.
I have doubts this is needed in the first place. As a pure FPGA design, this cannot work alone and you cannot get it alone (at least yet, happily to see resources proving me wrong). Thus it will be always customized per final board design, thus that final compatible is what matters.
"opencores" and "openrisc" are both accepted vendor prefixes for open-source hardware projects rather than commercial vendors, so a project name seems reasonable to me here too.
That said, I take your point about board customization. I'm happy to add a board-specific compatible as the primary match, with "glanda,gpu-1.0" as the fallback, e.g.:
Quoted 5 lines
compatible = "terasic,de10-standard-glandagpu", "glanda,gpu-1.0";
The driver would keep matching on "glanda,gpu-1.0". Let me know if you'd like this for v3, or if the generic compatible is enough for now, since there's currently only one board using this core.
openrisc is arch.
opencores is entire org. Are you saying that "Glanda" is this one:
https://www.glanda.com.au/
and opencores releases entire SoCs, thus they integrate their own IPs there into final product. I agree though, that opencores should not define standalone generic compatibles.
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-bindings: display: Add GlandaGPU binding
Quoted 6 lines
openrisc is arch.
opencores is entire org. Are you saying that "Glanda" is this one:
https://www.glanda.com.au/
and opencores releases entire SoCs, thus they integrate their own IPs there into final product. I agree though, that opencores should not define standalone generic compatibles.
Fair, those precedents don't really hold up then.
No relation to glanda.com.au, I wasn't even aware of that company. This is just a personal hobby project, not a company or organization.
Given that, what would you suggest instead? I'm open to using a board-specific compatible as the primary match as discussed, or whatever naming scheme you'd consider appropriate for an individual's hobby project.
Best regards,
Leander
Re: [PATCH v2 1/2] dt-bindings: display: Add GlandaGPU binding
Quoted 9 lines · Leander Kieweg
Quoted 6 lines
openrisc is arch.
opencores is entire org. Are you saying that "Glanda" is this one:
https://www.glanda.com.au/
and opencores releases entire SoCs, thus they integrate their own IPs there into final product. I agree though, that opencores should not define standalone generic compatibles.Fair, those precedents don't really hold up then.
Quoted 7 lines
No relation to glanda.com.au, I wasn't even aware of that company. This is just a personal hobby project, not a company or organization.
Given that, what would you suggest instead? I'm open to using a board-specific compatible as the primary match as discussed, or whatever naming scheme you'd consider appropriate for an individual's hobby project.
I am fine with small projects, till we do not have surge of them because anyone clones some project and vibe-codes new soft-core.
Projects run on your personal github, without any organization, do not get their own vendor prefix. Why? Because then you come with another project and want one more prefix... Personal vendor prefix would be fine, but different thing: this repo for your design was created a few months ago, with one contributor and ~70 commits. This means it is very new, without users.
What is the benefit of having it in Linux kernel for the community? Who needs this, outside of you?
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-bindings: display: Add GlandaGPU binding
Quoted 9 lines
I am fine with small projects, till we do not have surge of them because anyone clones some project and vibe-codes new soft-core.
Projects run on your personal github, without any organization, do not get their own vendor prefix. Why? Because then you come with another project and want one more prefix... Personal vendor prefix would be fine, but different thing: this repo for your design was created a few months ago, with one contributor and ~70 commits. This means it is very new, without users.
Makes sense. I'll go with a personal vendor prefix instead, e.g. "kieweg,gpu-1.0". I'd reuse that for any future project instead of asking for a new prefix.
Quoted 2 lines
What is the benefit of having it in Linux kernel for the community? Who needs this, outside of you?
Honestly, no one, probably. I built this because I wanted to learn, not because anyone was asking for it. I actually asked about this exact concern during the RFC review, whether being a hobby/non commercial project could be a dealbreaker for mainline. Thomas Zimmermann's reply at the time was:
We already have a driver for a RasPi-based USB display that someone made in their spare time. So being a hobbyist project is not a problem per se.
I don't want to pretend there's a bigger community need than there actually is. If that's not enough for mainline, I understand.
Best regards,
Leander
Re: [PATCH v2 1/2] dt-bindings: display: Add GlandaGPU binding
In reply to Krzysztof KozlowskiQuoted 9 lines
I am fine with small projects, till we do not have surge of them because anyone clones some project and vibe-codes new soft-core.
Projects run on your personal github, without any organization, do not get their own vendor prefix. Why? Because then you come with another project and want one more prefix... Personal vendor prefix would be fine, but different thing: this repo for your design was created a few months ago, with one contributor and ~70 commits. This means it is very new, without users.
Makes sense. I'll go with a personal vendor prefix instead, e.g. "kieweg,gpu-1.0". I'd reuse that for any future project instead of asking for a new prefix.
Quoted 2 lines
What is the benefit of having it in Linux kernel for the community? Who needs this, outside of you?
Honestly, no one, probably. I built this because I wanted to learn, not because anyone was asking for it. I actually asked about this exact concern during the RFC review, whether being a hobby/non commercial project could be a dealbreaker for mainline. Thomas Zimmermann's reply at the time was:
We already have a driver for a RasPi-based USB display that someone made in their spare time. So being a hobbyist project is not a problem per se.
I don't want to pretend there's a bigger community need than there actually is. If that's not enough for mainline, I understand.
Best regards,
Leander
PATCH v2 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 | 579 +++++++++++++++++++++++++++++++ 4 files changed, 597 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/glanda,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 + 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 +579 -0
579 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 2/2] drm/glanda: Add initial DRM driver for GlandaGPU
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider: - [High] Ignored return value of drm_mode_config_init(). - [High] Hardware interrupts are left enabled if…
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
- [High] Ignored return value of drm_mode_config_init().
- [High] Hardware interrupts are left enabled if drm_dev_register() fails, leading to an unhandled interrupt storm.
- [High] Missing resource size validation before I/O memory mapping allows out-of-bounds mapping and writes.
- [High] Userspace atomic commits hang when the driver falls back to polling mode because vblank events are armed but never signaled.
- [Medium] Unused INT_DONE interrupt is unconditionally enabled, risking an interrupt storm.
- [Medium] Native u32 read of little-endian pixel data breaks color conversions on big-endian CPUs.
- [Low] Missing dependencies in Kconfig for DRM_GLANDA.
- [Low] Using platform_get_irq() for an optional IRQ causes log spam.
--
--- Patch [2]: [PATCH v2 2/2] drm/glanda: Add initial DRM driver for GlandaGPU --- commit 47c9d06e7235a576cf0a48e9d5a1011c1d5c7ced
Author: Leander Kieweg <[email protected]>
Subject: drm/glanda: Add initial DRM driver for GlandaGPU
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.
Quoted 4 lines
drivers/gpu/drm/tiny/Kconfig +0
-0
[ ... ]
drivers/gpu/drm/tiny/Kconfig config DRM_CIRRUS_QEMU · line 63
Quoted 9 lines
drivers/gpu/drm/tiny/Kconfig +5
-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 + select DRM_KMS_HELPER + select DRM_GEM_SHMEM_HELPER
[Severity: Low]
Does this config need to depend on MMU and PCI || COMPILE_TEST? The driver selects DRM_GEM_SHMEM_HELPER which depends on MMU, and it calls PCI devres functions that lack non-PCI stubs when CONFIG_PCI is disabled.
Quoted 5 lines
drivers/gpu/drm/tiny/glandagpu.c new file +0
-0
[ ... ]
Quoted 3 lines
drivers/gpu/drm/tiny/glandagpu.c new file +3
-0+static void glanda_plane_atomic_update (struct drm_plane *plane, +struct drm_atomic_commit *state) +{
[ ... ]
Quoted 4 lines
drivers/gpu/drm/tiny/glandagpu.c new file +4
-0+for (y =0 ; y < height; y++) { +size_t offset = y *GLANDA_WIDTH *sizeof (u32); +u32 __iomem *dst = (u32 __iomem *)(gdev->vram_base + offset); +
drivers/gpu/drm/tiny/glandagpu.c line 131
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+for (x =0 ; x < width; x++) { +u32 pixel =iosys_map_rd (&shadow_state->data[0 ], + y * src_pitch + x *sizeof (u32), u32); +u32 packed = ((pixel >>12 ) &0x0F00 ) | + ((pixel >>8 ) &0x00F0 ) | + ((pixel >>4 ) &0x000F ); + +writel_relaxed (packed, &dst[x]); + } + }
[Severity: Medium]
Will this bitwise extraction read the correct color channels on big-endian architectures? By using iosys_map_rd to read a native u32, the little-endian DRM_FORMAT_XRGB8888 byte stream will have its bytes inverted on big-endian CPUs.
[ ... ]
Quoted 7 lines
drivers/gpu/drm/tiny/glandagpu.c new file +7
-0+static void glanda_crtc_atomic_flush (struct drm_crtc *crtc, +struct drm_atomic_commit *state) +{ +struct drm_crtc_state *new_state =drm_atomic_get_new_crtc_state (state, crtc); +struct drm_pending_vblank_event *event; + +if (new_state->event) {
drivers/gpu/drm/tiny/glandagpu.c line 251
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+ event = new_state->event; + + new_state->event =NULL ; + +spin_lock_irq (&crtc->dev->event_lock); + +if (drm_crtc_vblank_get (crtc) ==0 ) +drm_crtc_arm_vblank_event (crtc, event); +else +drm_crtc_send_vblank_event (crtc, event);
[Severity: High]
What happens to armed vblank events when the driver falls back to polling mode? If there is no hardware interrupt to call drm_crtc_handle_vblank(), these events might never be signaled, which can cause userspace page flips to hang. Should the driver set crtc->state->no_vblank = true or bypass drm_crtc_arm_vblank_event in polling mode?
[ ... ]
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 343
Quoted 5 lines
drivers/gpu/drm/tiny/glandagpu.c new file +5
-0+writel (0 , gdev->mmio_base +REG_IER ); +writel (0xFFFFFFFF , gdev->mmio_base +REG_ISR );/* clear flags */ + +/* DRM mode config */ +drm_mode_config_init (&gdev->drm);
[Severity: High]
Is it safe to ignore the integer return value of drm_mode_config_init? If this fails due to memory allocation issues, the DRM mode configuration state will be partially initialized, potentially leading to NULL pointer dereferences later when the DRM core accesses it.
[ ... ]
drivers/gpu/drm/tiny/glandagpu.c line 413
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_DONE , gdev->mmio_base +REG_IER );
[Severity: Medium]
Could enabling INT_DONE cause an interrupt storm? If the hardware asserts INT_DONE when the 2D engine is idle, and the driver never submits commands to it, the IRQ handler might get caught in a loop continuously clearing it.
drivers/gpu/drm/tiny/glandagpu.c line 421
Quoted 8 lines
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+drm_info (&gdev->drm,"IRQ %d requested and enabled\n" , gdev->irq); + }else { +drm_warn (&gdev->drm,"No IRQ found, falling back to polling\n" ); + } + + ret =drm_dev_register (&gdev->drm,0 ); +if (ret) +return ret;
[Severity: High]
Does this error path leave hardware interrupts enabled? If drm_dev_register fails, the function returns without clearing REG_IER. Since devres frees the IRQ handler, this might leave the hardware asserting an interrupt with no kernel handler available to acknowledge it.
[ ... ]
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 460
Quoted 8 lines
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -ENODEV ; + + 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 );
[Severity: High]
Should there be a check on the underlying resource length before mapping? Blindly mapping GLANDA_VRAM_SIZE without verifying resource_size(res) could cause out-of-bounds mappings if the hardware resource is undersized. Later, the shadow plane write loop in glanda_plane_atomic_update() could overrun the boundaries and corrupt physical memory.
drivers/gpu/drm/tiny/glandagpu.c line 468
Quoted 8 lines
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+if (!gdev->vram_base || !gdev->mmio_base) { +drm_err (&gdev->drm,"failed to ioremap\n" ); +return -ENOMEM ; + } + + irq =platform_get_irq (pdev,0 ); +if (irq == -ENXIO ) + irq =-1 ;/* no IRQ resource, fall back to polling */
[Severity: Low]
Since the driver gracefully supports polling mode, could this use platform_get_irq_optional instead? Using platform_get_irq logs a false-positive error when the IRQ is not found.
[ ... ]
Quoted 2 lines
drivers/gpu/drm/tiny/glandagpu.c new file +2
-0+static int glandagpu_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{
[ ... ]
drivers/gpu/drm/tiny/glandagpu.c line 522
Quoted 3 lines
drivers/gpu/drm/tiny/glandagpu.c new file +3
-0+ gdev->mmio_base =pcim_iomap_table (pdev)[0 ]; + gdev->vram_base =pcim_iomap_table (pdev)[1 ]; + gdev->vram_phys =pci_resource_start (pdev,1 );
[Severity: High]
Does this PCI probe path also need to validate the size of the mapped BARs against the expected GLANDA_VRAM_SIZE and GLANDA_MMIO_SIZE to prevent similar out-of-bounds writes?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/2] drm/glanda: Add initial DRM driver for GlandaGPU
In reply to Leander Kiewegdrivers/gpu/drm/tiny/glandagpu.c line 414
Quoted 8 lines · Leander Kieweg
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+if (ret) { +drm_err (&gdev->drm,"Failed to request IRQ %d\n" , + gdev->irq); +return ret; + } + +writel (INT_DONE , gdev->mmio_base +REG_IER ); +drm_info (&gdev->drm,"IRQ %d requested and enabled\n" , gdev->irq);
Please drop
drivers/gpu/drm/tiny/glandagpu.c line 423
Quoted 9 lines
drivers/gpu/drm/tiny/glandagpu.c new file +9
-0+ }else { +drm_warn (&gdev->drm,"No IRQ found, falling back to polling\n" ); + } + + ret =drm_dev_register (&gdev->drm,0 ); +if (ret) +return ret; + +drm_info (&gdev->drm,"GlandaGPU DRM Initialized (/dev/dri/cardX created)\n" );
Please drop all such messages.
drivers/gpu/drm/tiny/glandagpu.c line 436
Quoted 13 lines
drivers/gpu/drm/tiny/glandagpu.c new file +13
-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); + +/* Disable interrupts */ +writel (0 , gdev->mmio_base +REG_IER ); + +drm_info (&gdev->drm,"GlandaGPU DRM Driver removed\n" );
Ditto
drivers/gpu/drm/tiny/glandagpu.c line 445
Quoted 9 lines
drivers/gpu/drm/tiny/glandagpu.c new file +9
-0+} + +static int glandagpu_probe (struct platform_device *pdev) +{ +struct resource *res; +struct glanda_device *gdev; +int irq; + +dev_info (&pdev->dev,"GlandaGPU Probe started\n" );
Ditto, Driver should be silent on success.
Quoted 28 lines
drivers/gpu/drm/tiny/glandagpu.c new file +28
-0+ + 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 ; + + 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 (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); +}
drivers/gpu/drm/tiny/glandagpu.c line 483
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+ +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 ="glanda,gpu-1.0" }, + {/* end of table */ }
Drop comment, obvious.
drivers/gpu/drm/tiny/glandagpu.c line 491
Quoted 8 lines
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+}; + +MODULE_DEVICE_TABLE (of, glanda_of_match); + +static struct platform_driver glandagpu_driver = { + .driver = { + .name ="glandagpu" , + .of_match_table = glanda_of_match,
Messed indent.
drivers/gpu/drm/tiny/glandagpu.c line 503
Quoted 12 lines
drivers/gpu/drm/tiny/glandagpu.c new file +12
-0+ }, + .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; + +dev_info (&pdev->dev,"GlandaGPU PCI Probe started\n" );
Drop. Driver should be silent on success.
Quoted 50 lines
drivers/gpu/drm/tiny/glandagpu.c new file +50
-0+ + ret =pcim_enable_device (pdev); +if (ret) +return ret; +pci_set_master (pdev); + + 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 ) }, + {/* end of table */ } +}; + +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;
drivers/gpu/drm/tiny/glandagpu.c line 563
Quoted 10 lines
drivers/gpu/drm/tiny/glandagpu.c new file +10
-0+ } + + 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; + } + +pr_info ("GlandaGPU: Module loaded successfully\n" );
Drop. Kernel does not print such messages. It pollutes dmesg even without actual hardware.
drivers/gpu/drm/tiny/glandagpu.c line 571
Quoted 8 lines
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+return 0 ; +} + +static void __exit glandagpu_exit(void) +{ +pci_unregister_driver (&glandagpu_pci_driver); +platform_driver_unregister (&glandagpu_driver); +pr_info ("GlandaGPU: Module unloaded\n" );
Same here.
Quoted 11 lines
drivers/gpu/drm/tiny/glandagpu.c new file +8
-0+} + +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 · 1 line
2.43.0
Re: [PATCH v2 2/2] drm/glanda: Add initial DRM driver for GlandaGPU
Quoted 2 lines
Drop. Kernel does not print such messages. It pollutes dmesg even without actual hardware.
Thanks, all of this makes sense. I'll drop the info/debug messages on the success paths (probe, remove, init, exit), remove the redundant "end of table" comments, and fix the indentation on the of_match_table line for v3.
Best regards,
Leander