Skip to contentSkip to conversation

drm/ast: Handle framebuffer from dma-buf

PATCH Superseded Jocelyn Falempe 2 participants 5 messages Oct 28, 2025 – Oct 29, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jocelyn Falempe

author reviewer
#0 lore raw

PATCH 1/1 drm/ast: Handle framebuffer from dma-buf

In the atomic update callback, ast should call drm_gem_fb_begin_cpu_access() to make sure it can read the framebuffer from the CPU, otherwise the data might not be there due to cache, and synchronization.

Tested on a Lenovo SE100, while rendering on the ArrowLake GPU with i915 driver, and using ast for display.

---
 drivers/gpu/drm/ast/ast_mode.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/ast/ast_mode.c +6 -0
index 9ce874dba69c..68da4544d92d 100644
@@ -556,11 +556,17 @@ static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
 		ast_set_vbios_color_reg(ast, fb->format, ast_crtc_state->vmode);
 	}
 
+	/* if the buffer comes from another device */
+	if (!drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
+		return;
+
 	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
 	drm_atomic_for_each_plane_damage(&iter, &damage) {
 		ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage);
 	}
 
+	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+
 	/*
 	 * Some BMCs stop scanning out the video signal after the driver
 	 * reprogrammed the offset. This stalls display output for several

base-commit: 4f9ffd2c80a2fa09dcc8dfa0482cb7e0fb6fcf6c

Signature · 1 line
2.51.0
author reviewer
#1 lore raw
Quoted 7 lines · Jocelyn Falempe

In the atomic update callback, ast should call drm_gem_fb_begin_cpu_access() to make sure it can read the framebuffer from the CPU, otherwise the data might not be there due to cache, and synchronization.

Tested on a Lenovo SE100, while rendering on the ArrowLake GPU with i915 driver, and using ast for display.

I sent this patch a bit too fast, my mistake below:>

Quoted 11 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/gpu/drm/ast/ast_mode.c +0 -0
index 9ce874dba69c..68da4544d92d 100644

drivers/gpu/drm/ast/ast_mode.c static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane, · line 562

Quoted 7 lines
drivers/gpu/drm/ast/ast_mode.c +4 -0
@@ -556,11 +556,17 @@ static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
  		ast_set_vbios_color_reg(ast, fb->format, ast_crtc_state->vmode);
  	}
 
+	/* if the buffer comes from another device */
+	if (!drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
+		return;
+

Sorry, there is a typo here, it should be:

if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))

	return;
Quoted 12 lines
drivers/gpu/drm/ast/ast_mode.c +2 -0
  	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
  	drm_atomic_for_each_plane_damage(&iter, &damage) {
  		ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage);
  	}
 
+	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+
  	/*
  	 * Some BMCs stop scanning out the video signal after the driver
  	 * reprogrammed the offset. This stalls display output for several

base-commit: 4f9ffd2c80a2fa09dcc8dfa0482cb7e0fb6fcf6c

#2 lore raw

Hi Jocelyn

Am 28.10.25 um 15:49 schrieb Jocelyn Falempe:

Quoted 31 lines · Jocelyn Falempe
Quoted 7 lines

In the atomic update callback, ast should call drm_gem_fb_begin_cpu_access() to make sure it can read the framebuffer from the CPU, otherwise the data might not be there due to cache, and synchronization.

Tested on a Lenovo SE100, while rendering on the ArrowLake GPU with i915 driver, and using ast for display.

I sent this patch a bit too fast, my mistake below:>

Quoted 14 lines

---
  drivers/gpu/drm/ast/ast_mode.c | 6 ++++++

  1 file changed, 6 insertions(+)
drivers/gpu/drm/ast/ast_mode.c +0 -0
index 9ce874dba69c..68da4544d92d 100644
@@ -556,11 +556,17 @@ static void 
 ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
           ast_set_vbios_color_reg(ast, fb->format, ast_crtc_state->vmode);
       }
Quoted 4 lines

  +    /* if the buffer comes from another device */ +    if (!drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE)) +        return;
+

Sorry, there is a typo here, it should be:

Quoted 9 lines

if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE)) return;

Quoted 6 lines

drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state); drm_atomic_for_each_plane_damage(&iter, &damage) { ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage); }
  +    drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+

Thanks for posting this. I know that you follow the common code from other drivers, but I think we should change the pattern a bit. The code in _begin_cpu_access() might fail for whatever reason, but that does not affect the rest of the plane update.

How about

if (_begin_cpu_access() == 0)
    for_each_damage {
        handle_damage()
    }
    _end_cpu_access()
}

and then continue with the rest of the helper? Even if the damage update doesn't happen, the driver would still program changes of the framebuffer pitch.

There's no easy way of keeping the damage information across display updates AFAIK. But the problem might be transient, while a failed update of the framebuffer pitch can be permanent.

Best regards
Thomas

Quoted 6 lines
Quoted 5 lines

      /*
       * Some BMCs stop scanning out the video signal after the driver
       * reprogrammed the offset. This stalls display output for several

base-commit: 4f9ffd2c80a2fa09dcc8dfa0482cb7e0fb6fcf6c

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author reviewer
#3 lore raw
Quoted 56 lines · Thomas Zimmermann

Hi Jocelyn

Am 28.10.25 um 15:49 schrieb Jocelyn Falempe:

Quoted 30 lines · Jocelyn Falempe
Quoted 7 lines

In the atomic update callback, ast should call drm_gem_fb_begin_cpu_access() to make sure it can read the framebuffer from the CPU, otherwise the data might not be there due to cache, and synchronization.

Tested on a Lenovo SE100, while rendering on the ArrowLake GPU with i915 driver, and using ast for display.

I sent this patch a bit too fast, my mistake below:>

Quoted 13 lines

---
  drivers/gpu/drm/ast/ast_mode.c | 6 ++++++

  1 file changed, 6 insertions(+)
drivers/gpu/drm/ast/ast_mode.c +0 -0
index 9ce874dba69c..68da4544d92d 100644
@@ -556,11 +556,17 @@ static void 
 ast_primary_plane_helper_atomic_update(struct drm_plane *plane,

          ast_set_vbios_color_reg(ast, fb->format, ast_crtc_state-

Quoted 6 lines
Quoted 1 line

vmode);

      }
  +    /* if the buffer comes from another device */ +    if (!drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE)) +        return;
+

Quoted 11 lines

Sorry, there is a typo here, it should be:

if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE)) return;

Quoted 6 lines

drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state); drm_atomic_for_each_plane_damage(&iter, &damage) { ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage); }
  +    drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+

Thanks for posting this. I know that you follow the common code from other drivers, but I think we should change the pattern a bit. The code in _begin_cpu_access() might fail for whatever reason, but that does not affect the rest of the plane update.

How about

if (_begin_cpu_access() == 0)
    for_each_damage {
        handle_damage()
    }
    _end_cpu_access()
}

Quoted 4 lines

and then continue with the rest of the helper? Even if the damage update doesn't happen, the driver would still program changes of the framebuffer pitch.

There's no easy way of keeping the damage information across display updates AFAIK. But the problem might be transient, while a failed update of the framebuffer pitch can be permanent.

I'm unsure what is better, change the pitch while keeping the old buffer content, or keeping the last frame, and risking the next update to mess up. Anyway this shouldn't happen in practice, so I will sent your version in a v2.

Best regards,

Signature · 1 line
Jocelyn
Quoted 10 lines

Best regards
Thomas

Quoted 6 lines
Quoted 5 lines

      /*
       * Some BMCs stop scanning out the video signal after the driver
       * reprogrammed the offset. This stalls display output for several

base-commit: 4f9ffd2c80a2fa09dcc8dfa0482cb7e0fb6fcf6c

#4 lore raw

Hi

Am 28.10.25 um 18:24 schrieb Jocelyn Falempe:

Quoted 57 lines · Thomas Zimmermann
Quoted 56 lines

Hi Jocelyn

Am 28.10.25 um 15:49 schrieb Jocelyn Falempe:

Quoted 30 lines · Jocelyn Falempe
Quoted 7 lines

In the atomic update callback, ast should call drm_gem_fb_begin_cpu_access() to make sure it can read the framebuffer from the CPU, otherwise the data might not be there due to cache, and synchronization.

Tested on a Lenovo SE100, while rendering on the ArrowLake GPU with i915 driver, and using ast for display.

I sent this patch a bit too fast, my mistake below:>

Quoted 13 lines

---
  drivers/gpu/drm/ast/ast_mode.c | 6 ++++++

  1 file changed, 6 insertions(+)
drivers/gpu/drm/ast/ast_mode.c +0 -0
index 9ce874dba69c..68da4544d92d 100644
@@ -556,11 +556,17 @@ static void 
 ast_primary_plane_helper_atomic_update(struct drm_plane *plane,

          ast_set_vbios_color_reg(ast, fb->format, ast_crtc_state-

Quoted 6 lines
Quoted 1 line

vmode);

      }
  +    /* if the buffer comes from another device */ +    if (!drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE)) +        return;
+

Quoted 11 lines

Sorry, there is a typo here, it should be:

if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE)) return;

Quoted 6 lines

drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state); drm_atomic_for_each_plane_damage(&iter, &damage) { ast_handle_damage(ast_plane, shadow_plane_state->data, fb, &damage); }
  +    drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+

Thanks for posting this. I know that you follow the common code from other drivers, but I think we should change the pattern a bit. The code in _begin_cpu_access() might fail for whatever reason, but that does not affect the rest of the plane update.

How about

if (_begin_cpu_access() == 0)
     for_each_damage {
         handle_damage()
     }
     _end_cpu_access()
}

Quoted 6 lines
Quoted 4 lines

and then continue with the rest of the helper? Even if the damage update doesn't happen, the driver would still program changes of the framebuffer pitch.

There's no easy way of keeping the damage information across display updates AFAIK. But the problem might be transient, while a failed update of the framebuffer pitch can be permanent.

I'm unsure what is better, change the pitch while keeping the old buffer content, or keeping the last frame, and risking the next update to mess up. Anyway this shouldn't happen in practice, so I will sent your version in a v2.

If the error is permanent, we're probably out of luck in any case. If the error is transient, it might be fixed with the next frame if we program the framebuffer pitch to the correct value.

Best regards
Thomas

Quoted 3 lines

Best regards,

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)