Commit Graph

1399033 Commits

Author SHA1 Message Date
eng33
057bb6fb2c input: Add support for no irq to ili210x driver
Signed-off-by: eng33 <eng33@waveshare.com>
2025-11-24 14:23:33 +00:00
Tim Gover
732b79eac1 serial: tty: Add a driver for the RPi firmware UART
On Raspberry Pi 4 and earlier models the firmware provides
a low speed (up to 115200 baud) bit-bashed UART on arbitrary
GPIOs using the second VPU core.

The firmware driver is designed to support 19200 baud. Higher
rates up to 115200 seem to work but there may be more jitter.

This can be useful for debug or managing additional low
speed peripherals if the hardware PL011 and 8250 hardware
UARTs are already used for console / bluetooth.

The firmware driver requires a fixed core clock frequency
and also requires the VPU PWM audio driver to be disabled
(dtparam=audio=off)

Runtime configuration is handled via the vc-mailbox APIs
with the FIFO buffers being allocated in uncached VPU
addressable memory. The FIFO pointers are stored in spare
VideoCore multi-core sync registers in order to reduce the number
of uncached SDRAM accesses thereby reducing jitter.

Signed-off-by: Tim Gover <tim.gover@raspberrypi.com>

serial: rpi-fw-uart: Demote debug log messages

A dev_info call in rpi_fw_uart_configure causes kernel log output every
time one opens the UART. Demote it to dev_dbg.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
2025-11-24 14:23:33 +00:00
Tim Gover
220d9ee979 serial: core: Add the Raspberry Pi firmware UART id
Assign a new serial core number for the RPi firmware UART.

Signed-off-by: Tim Gover <tim.gover@raspberrypi.com>
2025-11-24 14:23:33 +00:00
Dave Stevenson
965955a547 drm/vc4: Cache LBM allocations to avoid double-buffering
LBM is only relevant for each active dlist, so there is
no need to double-buffer the allocations.

Cache the allocations per plane so that we can ensure the
allocations are possible.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:33 +00:00
Maíra Canal
21ca238c7b drm/vc4: backport 27e0a194a2 and b3bf19552e
Get the KUnit tests passing.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
2025-11-24 14:23:33 +00:00
Phil Elwell
58947314fa drm/vc4: tests: Fix up vc4_test_lbm_size
Following the example of [1], move the state allocation out of the init
function to make it thread safe.

[1] commit 7e0351ae91 ("drm/vc4: tests: Stop allocating the state in
test init")

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
2025-11-24 14:23:32 +00:00
Dave Stevenson
453c88b561 drm/vc4: tests: Update pv muxing tests now DSI1 is more flexible
The tests on vc4 (BCM2835-7) were checking for DSI1 muxing being
to restricted channel 2, and therefore muxing with TXP was impossible.

As we no longer have that restriction, update the capabilities
defined for DSI1, move the tests that used to be impossible to the
valid list, and extend for additional combinations that are now
possible.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:32 +00:00
Maxime Ripard
3431520b60 drm/vc4: tests: Introduce a test for LBM buffer size
The BCM2712 comes with a different LBM size computation than the
previous generations, so let's add the few examples provided as kunit
tests to make sure we always satisfy those requirements.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
49d6b83af7 drm/vc4: tests: Support a few more plane formats
We'll start testing our planes code in situations where we will use more
than XRGB8888, so let's add a few common pixel formats.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
8631dee6a2 drm/vc4: tests: Add helper to add a new plane to a state
We'll start to add some tests for the plane state logic, so let's create
a helper to add a plane to an existing atomic state.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
b0f7178b0a drm/vc4: tests: Add function to lookup a plane for a CRTC
Some tests will need to find a plane to run a test on for a given CRTC.
Let's create a small helper to do that.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
3f9dcda96a drm/vc4: tests: Use custom plane state for mock
The current mock planes were just using the regular drm_plane_state,
while the driver expect struct vc4_plane_state that subclasses
drm_plane_state.

Hook the proper implementations of reset, duplicate_state, destroy and
atomic_check to create vc4_plane_state.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
cc2635f124 drm/vc4: tests: Add tests for BCM2712 PixelValve Muxing
The BCM2712 has a simpler pipeline than the BCM2711, and thus the muxing
requirements are different. Create some tests to make sure we get proper
muxing decisions.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
5594e02e9c drm/vc4: tests: Add BCM2712 mock driver
The BCM2712 has a simpler pipeline that can only output to a writeback
connector and two HDMI controllers.

Let's allow our kunit tests to create a mock of that pipeline.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
383f97bbbb drm/vc4: tests: Return the allocated output
Some tests will need to retrieve the output that was just allocated by
vc4_mock_atomic_add_output().

Instead of making them look them up in the DRM device, we can simply
make vc4_mock_atomic_add_output() return an error pointer that holds the
allocated output instead of the error code.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
aab56c58a8 drm/vc4: tests: Drop drm parameter for vc4_find_crtc_for_encoder
The DRM device pointer and the DRM encoder pointer are redundant, since
the latter is attached to the former and we can just follow the
drm_encoder->dev pointer.

Let's remove the drm_device pointer argument.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Maxime Ripard
b1a5933e68 drm/vc4: tests: Switch generation mockup to a switch
Testing whether the VideoCore generation we want to mock is vc5 or vc4
worked so far, but will be difficult to extend to support BCM2712 (VC6).

Convert to a switch.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:32 +00:00
Dave Stevenson
6e0b0d0ec9 drm/vc4: fkms: Add firmware-kms mode
This is a squash of all firmware-kms related patches from previous
branches, up to and including
"drm/vc4: Set the possible crtcs mask correctly for planes with FKMS"
plus a couple of minor fixups for the 5.9 branch.
Please refer to earlier branches for full history.

This patch includes work by Eric Anholt, James Hughes, Phil Elwell,
Dave Stevenson, Dom Cobley, and Jonathon Bell.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

drm/vc4: Fixup firmware-kms after "drm/atomic: Pass the full state to CRTC atomic enable/disable"

Prototype for those calls changed, so amend fkms (which isn't
upstream) to match.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

drm/vc4: Fixup fkms for API change

Atomic flush and check changed API, so fix up the downstream-only
FKMS driver.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

drm/vc4: Make normalize_zpos conditional on using fkms

Eric's view was that there was no point in having zpos
support on vc4 as all the planes had the same functionality.

Can be later squashed into (and fixes):
drm/vc4: Add firmware-kms mode

Signed-off-by: Dom Cobley <popcornmix@gmail.com>

drm/vc4: FKMS: Change of Broadcast RGB mode needs a mode change

The Broadcast RGB (aka HDMI limited/full range) property is only
notified to the firmware on mode change, so this needs to be
signalled when set.

https://github.com/raspberrypi/firmware/issues/1580

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

vc4/drv: Only notify firmware of display done with kms

fkms driver still wants firmware display to be active

Signed-off-by: Dom Cobley <popcornmix@gmail.com>

ydrm/vc4: fkms: Fix margin calculations for the right/bottom edges

The calculations clipped the right/bottom edge of the clipped
range based on the left/top margins.

https://github.com/raspberrypi/linux/issues/4447

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

drm/vc4: fkms: Use new devm_rpi_firmware_get api

drm/kms: Add allow_fb_modifiers

Signed-off-by: Dom Cobley <popcornmix@gmail.com>

drm/vc4: Add async update support for cursor planes

Now that cursors are implemented as regular planes, all cursor
movements result in atomic updates. As the firmware-kms driver
doesn't support asynchronous updates, these are synchronous, which
limits the update rate to the screen refresh rate. Xorg seems unaware
of this (or at least of the effect of this), because if the mouse is
configured with a higher update rate than the screen then continuous
mouse movement results in an increasing backlog of mouse events -
cue extreme lag.

Add minimal support for asynchronous updates - limited to cursor
planes - to eliminate the lag.

See: https://github.com/raspberrypi/linux/pull/4971
     https://github.com/raspberrypi/linux/issues/4988

Signed-off-by: Phil Elwell <phil@raspberrypi.com>

drivers/gpu/drm/vc4: Add missing 32-bit RGB formats

The missing 32-bit per pixel ABGR and various "RGB with an X value"
formats are added. Change sent by Dave Stevenson.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>

drm: vc4: Fixup duplicated macro definition in vc4_firmware_kms

Both vc4_drv.h and vc4_firmware_kms.c had definitions for
to_vc4_crtc.

Rename the fkms one to make it unique, and drop the magic
define vc4_crtc vc4_kms_crtc
define to_vc4_crtc to_vc4_kms_crtc
that renamed half the variable and function names in a slightly
unexpected way.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

drm/vc4: Fix FKMS for when the YUV chroma planes are different buffers

The code was assuming that it was a single buffer with offsets,
when kmstest uses separate buffers and 0 offsets for each plane.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

drm/vc4: fkms: Rename plane related functions

The name collide with the Full KMS functions that are going to be made
public.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>

drm/vc4_fkms: Fix up interrupt handler for both 2835/2711 and 2712

2712 has switched from using the SMI peripheral to another interrupt
source for the vsync interrupt, so handle both sources cleanly.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

drm/vc4: fkms: No SMI abuse needed on BCM2712

Since we don't use the (absent) SMI block to create interrupts on
BCM2712, there's no need to map any registers.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dom Cobley
721c9ec53a drm/vc4: Disable the 2pixel/clock odd timings workaround for interlaced
Whilst BCM2712 does fix using odd horizontal timings, it doesn't
work with interlaced modes.

Drop the workaround for interlaced modes and revert to the same
behaviour as BCM2711.

https://github.com/raspberrypi/linux/issues/6281

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dom Cobley
1a21ad003e drm/vc4: Remove request for min clocks when hdmi output is disabled
Currently, booting with no hdmi connected has:
pi@pi4:~ $ vcgencmd measure_clock hdmi pixel
frequency(9)=120010256
frequency(29)=74988280

After connecting hdmi we get:
pi@pi4:~ $ vcgencmd measure_clock hdmi pixel
frequency(9)=300005856
frequency(29)=149989744

and that persists after disconnecting hdmi

I can measure this on a power supply as 10mA@5.2V (52mW).

We should always remove clk_set_min_rate requests
when we no longer need them.

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
bac32b5b9c drm/vc4: txp: Add a rotation property to the writeback connector
The txp block can implement transpose as it writes out the image
data, so expose that through the new connector rotation property.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

drm: vc4: txp: Do not allow 24bpp formats when transposing

The hardware doesn't support transposing to 24bpp (RGB888/BGR888)
formats. There's no way to advertise this through DRM, so block
it from atomic_check instead.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
60d6acae54 drm/vc4: Drop panic priority for writeback connector
As the writeback connector doesn't have the same realtime
constraints of a live display, drop the panic priority for it.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
5a40082ee4 drm/vc4: Do not include writeback conn load in load tracker
The transposer/writeback connector should be running with a
lower priority, so shouldn't be factored into the load
calculations.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
bd554d6487 drm/vc4: Assign 32 overlay planes to writeback only
Instead of having 48 generic overlay planes, assign 32 to the
writeback connector so that there is no ambiguity in wlroots
when trying to find a plane for composition using the writeback
connector vs display.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
e23463465e drm/vc4: Increase number of overlay planes from 16 to 48
The HVS can accept an arbitrary number of planes, provided
that the overall pixel read load is within limits, and
the display list can fit into the dlist memory.

Now that DRM will support 64 planes per device, increase
the number of overlay planes from 16 to 48 so that the
dlist complexity can be increased (eg 4x4 video wall on
each of 3 displays).

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
4cffdbe106 drm/vc4: hvs: Defer updating the enable_bg_fill until vblank
The register to enable/disable background fill was being set
from atomic flush, however that will be applied immediately and
can be a while before the vblank. If it was required for the
current frame but not for the next one, that can result in
corruption for part of the current frame.

Store the state in vc4_hvs, and update it on vblank.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
365745cca9 drm/vc4: Use the TPZ scaling filter for 1x1 source images
The documentation says that the TPZ filter can not upscale,
and requesting a scaling factor > 1:1 will output the original
image in the top left, and repeat the right/bottom most pixels
thereafter.
That fits perfectly with upscaling a 1x1 image which is done
a fair amount by some compositors to give solid colour, and it
saves a large amount of LBM (TPZ is based on src size, whilst
PPF is based on dest size).

Select TPZ filter for images with source rectangle <=1.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
19b0cf1461 drm/vc4: Add support for per plane scaling filter selection
Seeing as the HVS can be configured with regard the scaling filter,
and DRM now supports selecting scaling filters at a per CRTC or
per plane level, we can implement it.

Default remains as the Mitchell/Netravali filter, but nearest
neighbour is now also implemented.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:31 +00:00
Dom Cobley
c1a5d0bcc3 vc4/drm:plane: Make use of chroma siting parameter
Signed-off-by: Dom Cobley <popcornmix@gmail.com>
2025-11-24 14:23:31 +00:00
Dave Stevenson
159bfef2b0 drm/vc4: dpi: Add override for RGB order
There are no MEDIA_BUS_FMT_* defines for GRB or BRG, and adding
them is a pain.

Add a DT override to allow setting the order.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:30 +00:00
Dom Cobley
95310bcfc7 drm/vc4: Also power down the PLL core when resetting PHY
The current reset code doesn't actually stop the hdmi output.
That makes it difficult for displays to handle a mode set.

Powering down the PLL does actually remove the hdmi signal
and makes mode sets more reliable

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
2025-11-24 14:23:30 +00:00
Dom Cobley
dc7f920345 drm/vc4: Implement vc6_hdmi_phy_disable
The body of this function was missing so we don't reset the phy
when disabling it.

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
2025-11-24 14:23:30 +00:00
Dom Cobley
3a7963a061 drm/vc4: Add a delay after disabling hdmi phy output
There appears to be a requirement for some devices
(I'm testing with a 8K VRROOM 40Gbps HDMI switch)
for a measable delay between removing the hdmi phy output from
the old mode, to enabling the hdmi phy output for the new mode.

Without the delay, a mode switch has a small change of getting a permanent
'no signal', which requires a subsequent mode switch or a unplug/replug
to redetect.

Switching between 4kp24/25/30 modes fails about 5% of time in my testing.

Add a delay to make it impossible to switch faster than this.

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
2025-11-24 14:23:30 +00:00
Dom Cobley
8d02894aac vc4/hdmi: Ignore hotplug interrupt with force_hotplug
The intention of the vc4.force_hotplug setting is to
ignore hotplug completely.

It can be used when a display toggles hotplug when
switching AV inputs, going into standby or changing a
KVM switch, and some side effect of that is unwanted.

It turns out while vc4.force_hotplug currently makes
hotplug always read as asserted, that isn't enough to
stop drm doing lots of stuff, including re-reading
the edid.

An example of what drm does with a hotplug deasert/assert
and vc4.force_hotplug=1 currently is:

https://paste.debian.net/hidden/dc07434b/

That is unwanted. Lets ignore the hotplug interrupt
completely so drm is blissfully unaware of the hotplug change.

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
2025-11-24 14:23:30 +00:00
Dom Cobley
fd59077f0d drm/vc4_hdmi: Allow hotplug detect to be forced
See: https://forum.libreelec.tv/thread/24783-tv-avr-turns-back-on-right-after-turning-them-off

While the kernel provides a :D flag for assuming device is connected,
it doesn't stop this function from being called and generating a cec_phys_addr_invalidate
message when hotplug is deasserted.

That message provokes a flurry of CEC messages which for many users results in the TV
switching back on again and it's very hard to get it to stay switched off.

It seems to only occur with an AVR and TV connected but has been observed across a
number of manufacturers.

The issue started with https://github.com/raspberrypi/linux/pull/4371
and this provides an optional way of getting back the old behaviour

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
2025-11-24 14:23:30 +00:00
Dave Stevenson
8a129d25cf drm/vc4: hdmi: Add a clear_infoframe hook
If you disable HDR metadata, then the hardware should stop
sending the infoframe, and that is implemented by the
clear_infoframe hook which wasn't implemented. Add it.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:30 +00:00
Dave Stevenson
687f1239ec drm/vc4: Initialise the tv_mode property default from cmdline_mode.
With the command line parser now providing the information about
the tv mode, use that as the preferred choice for initialising the
default of the tv_mode property.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:30 +00:00
Mateusz Kwiatkowski
af7a068818 drm/vc4: Allow setting the TV norm via module parameter
Similar to the ch7006 and nouveau drivers, introduce a "tv_mode" module
parameter that allow setting the TV norm by specifying vc4.tv_norm= on
the kernel command line.

If that is not specified, try inferring one of the most popular norms
(PAL or NTSC) from the video mode specified on the command line. On
Raspberry Pis, this causes the most common cases of the sdtv_mode
setting in config.txt to be respected.

Signed-off-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>

drm/vc4: Do not reset tv mode as this is already handled by framework

In vc4_vec_connector_reset, the tv mode is already reset to the
property default by drm_atomic_helper_connector_tv_reset, so there
is no need for a local fixup to potentially some other default.

Fixes: 96922af144 ("drm/vc4: Allow setting the TV norm via module parameter")
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:30 +00:00
Dave Stevenson
189505fcb1 drm: vc4: dsi: enable video and then retry failed transfers
The DSI block appears to be able to come up stuck in a condition where
it leaves the lanes in HS mode or just jabbering. This stops LP
transfers from completing as there is no LP time available. This is
signalled via the LP1 contention error.

Enabling video briefly clears that condition, so if we detect the
error condition, enable video mode and then retry.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:30 +00:00
Dave Stevenson
a94c0d971a drm/vc4: dsi: Don't reset the host until post_disable
Some DSI peripheral drivers wish to send commands in the
post_disable or panel unprepare callback. These are called
after the DSI host's disable call, but before the host's
post_disable if pre_enable_prev_first is set.

Don't reset the block until post_disable to allow these
commands to be sent.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:30 +00:00
Dave Stevenson
26a4ba7789 drm/vc4: Fixup mode for 7inch panel on DSI0
The TC358762 bridge and panel decodes the mode differently on
DSI0 to DSI1 for no obvious reason, and results in a shift off
the screen.
Whilst it would be possible to change the compatible used for
the panel, that then messes up Pi5.

As it appears to be restricted to vc4 DSI0, fix up the mode
in vc4_dsi.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:30 +00:00
Dave Stevenson
857d290a31 drm/vc4: Add vblank callback to DSI0 to reset FIFO
The pixel to byte FIFO appears to not always reset correctly,
which can lead to colour errors and/or horizontal shifts.
Reset on every vblank to work around the issue.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:29 +00:00
Dave Stevenson
b063ae8c8d drm/vc4: Ensure DSI is enabled for FIFO resets
The block must be enabled for the FIFO resets to be actioned,
so ensure this is the case.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:29 +00:00
Dave Stevenson
7d166cfd30 drm: vc4: Reset DSI AFE on disable
vc4_dsi_bridge_disable wasn't resetting things during shutdown,
so add that in.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:29 +00:00
Dave Stevenson
8c33016aec drm: vc4: dsi: Clocks should be running before reset
The initialisation sequence differs slightly from the documentation
in that the clocks are meant to be running before resets and
similar.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:29 +00:00
Dave Stevenson
d96ff61392 drm/vc4: Add option to call from crtc to encoder on vblank
DSI0 is misbehaving and needs to action things on vblank to
work around it.
Add a new hook to call across during vblank.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:29 +00:00
Dave Stevenson
810b31ee8a drm: vc4: Block swiotlb bounce buffers being imported as dmabuf
The dmabuf import already checks that the backing buffer is contiguous
and rejects it if it isn't. vc4 also requires that the buffer is
in the bottom 1GB of RAM, and this is all correctly defined via
dma-ranges.

However the kernel silently uses swiotlb to bounce dma buffers
around if they are in the wrong region. This relies on dma sync
functions to be called in order to copy the data to/from the
bounce buffer.

DRM is based on all memory allocations being coherent with the
GPU so that any updates to a framebuffer will be acted on without
the need for any additional update. This is fairly fundamentally
incompatible with needing to call dma_sync_ to handle the bounce
buffer copies, and therefore we have to detect and reject mappings
that use bounce buffers.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:29 +00:00
Dave Stevenson
d3fd7de91e drm/vc4: Disable overrun interrupts
We have a read-modify-write race when updating SCALER_DISPCTRL for
underrun and end-of-frame interrupts.
Ideally it would be fixed via a spinlock or similar, but that will
require a reasonable amount of study to ensure we don't get deadlocks.

The underrun reporting is only for debug, so disable it for now.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:29 +00:00
Dave Stevenson
8d8c6c02dd drm/vc4: Add hvs_dlist_allocs debugfs function.
Users are reporting running out of DLIST memory. Add a
debugfs file to dump out all the allocations.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
2025-11-24 14:23:29 +00:00
Maxime Ripard
1102c671f7 drm/vc4: hvs: Defer dlist slots deallocation
During normal operations, the cursor position update is done through an
asynchronous plane update, which on the vc4 driver basically just
modifies the right dlist word to move the plane to the new coordinates.

However, when we have the overscan margins setup, we fall back to a
regular commit when we are next to the edges. And since that commit
happens to be on a cursor plane, it's considered a legacy cursor update
by KMS.

The main difference it makes is that it won't wait for its completion
(ie, next vblank) before returning. This means if we have multiple
commits happening in rapid succession, we can have several of them
happening before the next vblank.

In parallel, our dlist allocation is tied to a CRTC state, and each time
we do a commit we end up with a new CRTC state, with the previous one
being freed. This means that we free our previous dlist entry (but don't
clear it though) every time a new one is being committed.

Now, if we were to have two commits happening before the next vblank, we
could end up freeing reusing the same dlist entries before the next
vblank.

Indeed, we would start from an initial state taking, for example, the
dlist entries 10 to 20, then start a commit taking the entries 20 to 30
and setting the dlist pointer to 20, and freeing the dlist entries 10 to
20. However, since we haven't reach vblank yet, the HVS is still using
the entries 10 to 20.

If we were to make a new commit now, chances are the allocator are going
to give the 10 to 20 entries back, and we would change their content to
match the new state. If vblank hasn't happened yet, we just corrupted
the active dlist entries.

A first attempt to solve this was made by creating an intermediate dlist
buffer to store the current (ie, as of the last commit) dlist content,
that we would update each time the HVS is done with a frame. However, if
the interrupt handler missed the vblank window, we would end up copying
our intermediate dlist to the hardware one during the composition,
essentially creating the same issue.

Since making sure that our interrupt handler runs within a fixed,
constrained, time window would require to make Linux a real-time kernel,
this seems a bit out of scope.

Instead, we can work around our original issue by keeping the dlist
slots allocation longer. That way, we won't reuse a dlist slot while
it's still in flight. In order to achieve this, instead of freeing the
dlist slot when its associated CRTC state is destroyed, we'll queue it
in a list.

A naive implementation would free the buffers in that queue when we get
our end of frame interrupt. However, there's still a race since, just
like in the shadow dlist case, we don't control when the handler for
that interrupt is going to run. Thus, we can end up with a commit adding
an old dlist allocation to our queue during the window between our
actual interrupt and when our handler will run. And since that buffer is
still being used for the composition of the current frame, we can't free
it right away, exposing us to the original bug.

Fortunately for us, the hardware provides a frame counter that is
increased each time the first line of a frame is being generated.
Associating the frame counter the image is supposed to go away to the
allocation, and then only deallocate buffers that have a counter below
or equal to the one we see when the deallocation code should prevent the
above race from occurring.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
2025-11-24 14:23:29 +00:00