[PATCH v2 4/8] drm: vkms: Add fb information to `vkms_writeback_job`
Igor Torrente
igormtorrente at gmail.com
Wed Nov 3 19:18:35 UTC 2021
Hi Thomas,
On 11/3/21 12:45 PM, Thomas Zimmermann wrote:
> Hi
>
> Am 26.10.21 um 13:34 schrieb Igor Torrente:
>> This commit is the groundwork to introduce new formats to the planes and
>> writeback buffer. As part of it, a new buffer metadata field is added to
>> `vkms_writeback_job`, this metadata is represented by the `vkms_composer`
>> struct.
>>
>> This will allow us, in the future, to have different compositing and wb
>> format types.
>>
>> Signed-off-by: Igor Torrente <igormtorrente at gmail.com>
>> ---
>> V2: Change the code to get the drm_framebuffer reference and not copy its
>> contents(Thomas Zimmermann).
>> ---
>> drivers/gpu/drm/vkms/vkms_composer.c | 4 ++--
>> drivers/gpu/drm/vkms/vkms_drv.h | 12 ++++++------
>> drivers/gpu/drm/vkms/vkms_plane.c | 10 +++++-----
>> drivers/gpu/drm/vkms/vkms_writeback.c | 21 ++++++++++++++++++---
>> 4 files changed, 31 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
>> index 82f79e508f81..383ca657ddf7 100644
>> --- a/drivers/gpu/drm/vkms/vkms_composer.c
>> +++ b/drivers/gpu/drm/vkms/vkms_composer.c
>> @@ -153,7 +153,7 @@ static void compose_plane(struct vkms_composer *primary_composer,
>> struct vkms_composer *plane_composer,
>> void *vaddr_out)
>> {
>> - struct drm_framebuffer *fb = &plane_composer->fb;
>> + struct drm_framebuffer *fb = plane_composer->fb;
>> void *vaddr;
>> void (*pixel_blend)(const u8 *p_src, u8 *p_dst);
>>
>> @@ -174,7 +174,7 @@ static int compose_active_planes(void **vaddr_out,
>> struct vkms_composer *primary_composer,
>> struct vkms_crtc_state *crtc_state)
>> {
>> - struct drm_framebuffer *fb = &primary_composer->fb;
>> + struct drm_framebuffer *fb = primary_composer->fb;
>> struct drm_gem_object *gem_obj = drm_gem_fb_get_obj(fb, 0);
>> const void *vaddr;
>> int i;
>> diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
>> index 64e62993b06f..9e4c1e95bbb1 100644
>> --- a/drivers/gpu/drm/vkms/vkms_drv.h
>> +++ b/drivers/gpu/drm/vkms/vkms_drv.h
>> @@ -20,13 +20,8 @@
>> #define XRES_MAX 8192
>> #define YRES_MAX 8192
>>
>> -struct vkms_writeback_job {
>> - struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];
>> - struct dma_buf_map data[DRM_FORMAT_MAX_PLANES];
>> -};
>> -
>> struct vkms_composer {
>> - struct drm_framebuffer fb;
>> + struct drm_framebuffer *fb;
>> struct drm_rect src, dst;
>> struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];
>> unsigned int offset;
>> @@ -34,6 +29,11 @@ struct vkms_composer {
>> unsigned int cpp;
>> };
>>
>> +struct vkms_writeback_job {
>> + struct dma_buf_map data[DRM_FORMAT_MAX_PLANES];
>> + struct vkms_composer composer;
>> +};
>> +
>> /**
>> * vkms_plane_state - Driver specific plane state
>> * @base: base plane state
>> diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
>> index 32409e15244b..0a28cb7a85e2 100644
>> --- a/drivers/gpu/drm/vkms/vkms_plane.c
>> +++ b/drivers/gpu/drm/vkms/vkms_plane.c
>> @@ -50,12 +50,12 @@ static void vkms_plane_destroy_state(struct drm_plane *plane,
>> struct vkms_plane_state *vkms_state = to_vkms_plane_state(old_state);
>> struct drm_crtc *crtc = vkms_state->base.base.crtc;
>>
>> - if (crtc) {
>> + if (crtc && vkms_state->composer->fb) {
>> /* dropping the reference we acquired in
>> * vkms_primary_plane_update()
>> */
>> - if (drm_framebuffer_read_refcount(&vkms_state->composer->fb))
>> - drm_framebuffer_put(&vkms_state->composer->fb);
>> + if (drm_framebuffer_read_refcount(vkms_state->composer->fb))
>> + drm_framebuffer_put(vkms_state->composer->fb);
>> }
>>
>> kfree(vkms_state->composer);
>> @@ -110,9 +110,9 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,
>> composer = vkms_plane_state->composer;
>> memcpy(&composer->src, &new_state->src, sizeof(struct drm_rect));
>> memcpy(&composer->dst, &new_state->dst, sizeof(struct drm_rect));
>> - memcpy(&composer->fb, fb, sizeof(struct drm_framebuffer));
>> + composer->fb = fb;
>> memcpy(&composer->map, &shadow_plane_state->data, sizeof(composer->map));
>> - drm_framebuffer_get(&composer->fb);
>> + drm_framebuffer_get(composer->fb);
>> composer->offset = fb->offsets[0];
>> composer->pitch = fb->pitches[0];
>> composer->cpp = fb->format->cpp[0];
>> diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c
>> index 8694227f555f..32734cdbf6c2 100644
>> --- a/drivers/gpu/drm/vkms/vkms_writeback.c
>> +++ b/drivers/gpu/drm/vkms/vkms_writeback.c
>> @@ -75,12 +75,15 @@ static int vkms_wb_prepare_job(struct drm_writeback_connector *wb_connector,
>> if (!vkmsjob)
>> return -ENOMEM;
>>
>> - ret = drm_gem_fb_vmap(job->fb, vkmsjob->map, vkmsjob->data);
>> + ret = drm_gem_fb_vmap(job->fb, vkmsjob->composer.map, vkmsjob->data);
>> if (ret) {
>> DRM_ERROR("vmap failed: %d\n", ret);
>> goto err_kfree;
>> }
>>
>> + vkmsjob->composer.fb = job->fb;
>> + drm_framebuffer_get(vkmsjob->composer.fb);
>> +
>> job->priv = vkmsjob;
>>
>> return 0;
>> @@ -99,7 +102,10 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
>> if (!job->fb)
>> return;
>>
>> - drm_gem_fb_vunmap(job->fb, vkmsjob->map);
>> + drm_gem_fb_vunmap(job->fb, vkmsjob->composer.map);
>> +
>> + if (drm_framebuffer_read_refcount(vkmsjob->composer.fb))
>> + drm_framebuffer_put(vkmsjob->composer.fb);
>
> Why is this protected by an if conditional?
Here, I followed what was done in the vkms_plane code, just adapting it
to the writeback callbacks.
I put this if because I wasn't 100% sure that for each
`vkms_wb_prepare_job` I would have exactly one `vkms_wb_cleanup_job`
after it.
It happened in my testings, but I can't guarantee that it will always
happen.
>
> Best regards
> Thomas
>
>>
>> vkmsdev = drm_device_to_vkms_device(job->fb->dev);
>> vkms_set_composer(&vkmsdev->output, false);
>> @@ -116,14 +122,23 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
>> struct drm_writeback_connector *wb_conn = &output->wb_connector;
>> struct drm_connector_state *conn_state = wb_conn->base.state;
>> struct vkms_crtc_state *crtc_state = output->composer_state;
>> + struct drm_framebuffer *fb = connector_state->writeback_job->fb;
>> + struct vkms_writeback_job *active_wb;
>> + struct vkms_composer *wb_composer;
>>
>> if (!conn_state)
>> return;
>>
>> vkms_set_composer(&vkmsdev->output, true);
>>
>> + active_wb = conn_state->writeback_job->priv;
>> + wb_composer = &active_wb->composer;
>> +
>> spin_lock_irq(&output->composer_lock);
>> - crtc_state->active_writeback = conn_state->writeback_job->priv;
>> + crtc_state->active_writeback = active_wb;
>> + wb_composer->offset = fb->offsets[0];
>> + wb_composer->pitch = fb->pitches[0];
>> + wb_composer->cpp = fb->format->cpp[0];
>> crtc_state->wb_pending = true;
>> spin_unlock_irq(&output->composer_lock);
>> drm_writeback_queue_job(wb_conn, connector_state);
>>
>
Thanks,
---
Igor M. A. Torrente
More information about the dri-devel
mailing list