Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vkms: Use dma-buf mapping from shadow-plane state for composing

Store the shadow-buffer mapping's address in struct vkms_composer and
use the value when composing the output. It's the same value as stored
in the GEM SHMEM BO, but frees the composer code from its dependency
on GEM SHMEM.

Using struct dma_buf_map is how framebuffer access is supposed to be.
The long-term plan is to perform all framebuffer access via struct
dma_buf_map and avoid the details of accessing I/O and system memory.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Melissa Wen <melissa.srw@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210705074633.9425-5-tzimmermann@suse.de

+15 -13
+11 -13
drivers/gpu/drm/vkms/vkms_composer.c
··· 6 6 #include <drm/drm_atomic_helper.h> 7 7 #include <drm/drm_fourcc.h> 8 8 #include <drm/drm_gem_framebuffer_helper.h> 9 - #include <drm/drm_gem_shmem_helper.h> 10 9 #include <drm/drm_vblank.h> 11 10 12 11 #include "vkms_drv.h" ··· 153 154 struct vkms_composer *plane_composer, 154 155 void *vaddr_out) 155 156 { 156 - struct drm_gem_object *plane_obj; 157 - struct drm_gem_shmem_object *plane_shmem_obj; 158 157 struct drm_framebuffer *fb = &plane_composer->fb; 158 + void *vaddr; 159 159 void (*pixel_blend)(const u8 *p_src, u8 *p_dst); 160 160 161 - plane_obj = drm_gem_fb_get_obj(&plane_composer->fb, 0); 162 - plane_shmem_obj = to_drm_gem_shmem_obj(plane_obj); 163 - 164 - if (WARN_ON(!plane_shmem_obj->vaddr)) 161 + if (WARN_ON(dma_buf_map_is_null(&primary_composer->map[0]))) 165 162 return; 163 + 164 + vaddr = plane_composer->map[0].vaddr; 166 165 167 166 if (fb->format->format == DRM_FORMAT_ARGB8888) 168 167 pixel_blend = &alpha_blend; 169 168 else 170 169 pixel_blend = &x_blend; 171 170 172 - blend(vaddr_out, plane_shmem_obj->vaddr, primary_composer, 173 - plane_composer, pixel_blend); 171 + blend(vaddr_out, vaddr, primary_composer, plane_composer, pixel_blend); 174 172 } 175 173 176 174 static int compose_active_planes(void **vaddr_out, ··· 176 180 { 177 181 struct drm_framebuffer *fb = &primary_composer->fb; 178 182 struct drm_gem_object *gem_obj = drm_gem_fb_get_obj(fb, 0); 179 - struct drm_gem_shmem_object *shmem_obj = to_drm_gem_shmem_obj(gem_obj); 183 + const void *vaddr; 180 184 int i; 181 185 182 186 if (!*vaddr_out) { 183 - *vaddr_out = kzalloc(shmem_obj->base.size, GFP_KERNEL); 187 + *vaddr_out = kzalloc(gem_obj->size, GFP_KERNEL); 184 188 if (!*vaddr_out) { 185 189 DRM_ERROR("Cannot allocate memory for output frame."); 186 190 return -ENOMEM; 187 191 } 188 192 } 189 193 190 - if (WARN_ON(!shmem_obj->vaddr)) 194 + if (WARN_ON(dma_buf_map_is_null(&primary_composer->map[0]))) 191 195 return -EINVAL; 192 196 193 - memcpy(*vaddr_out, shmem_obj->vaddr, shmem_obj->base.size); 197 + vaddr = primary_composer->map[0].vaddr; 198 + 199 + memcpy(*vaddr_out, vaddr, gem_obj->size); 194 200 195 201 /* If there are other planes besides primary, we consider the active 196 202 * planes should be in z-order and compose them associatively:
+1
drivers/gpu/drm/vkms/vkms_drv.h
··· 23 23 struct vkms_composer { 24 24 struct drm_framebuffer fb; 25 25 struct drm_rect src, dst; 26 + struct dma_buf_map map[4]; 26 27 unsigned int offset; 27 28 unsigned int pitch; 28 29 unsigned int cpp;
+3
drivers/gpu/drm/vkms/vkms_plane.c
··· 97 97 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, 98 98 plane); 99 99 struct vkms_plane_state *vkms_plane_state; 100 + struct drm_shadow_plane_state *shadow_plane_state; 100 101 struct drm_framebuffer *fb = new_state->fb; 101 102 struct vkms_composer *composer; 102 103 ··· 105 104 return; 106 105 107 106 vkms_plane_state = to_vkms_plane_state(new_state); 107 + shadow_plane_state = &vkms_plane_state->base; 108 108 109 109 composer = vkms_plane_state->composer; 110 110 memcpy(&composer->src, &new_state->src, sizeof(struct drm_rect)); 111 111 memcpy(&composer->dst, &new_state->dst, sizeof(struct drm_rect)); 112 112 memcpy(&composer->fb, fb, sizeof(struct drm_framebuffer)); 113 + memcpy(&composer->map, &shadow_plane_state->map, sizeof(composer->map)); 113 114 drm_framebuffer_get(&composer->fb); 114 115 composer->offset = fb->offsets[0]; 115 116 composer->pitch = fb->pitches[0];