Skip to content

Commit 27f5b72

Browse files
committed
Merge tag 'drm-misc-fixes-2024-08-29' of https://gitlab.freedesktop.org/drm/misc/kernel into drm-fixes
A revert for a previous TTM commit causing stuttering, 3 fixes for vmwgfx related to buffer operations, a fix for video/aperture with non-VGA primary devices, and a preemption status fix for v3d Signed-off-by: Dave Airlie <[email protected]> From: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/20240829-efficient-swift-from-lemuria-f60c05@houat
2 parents dde72a5 + 9d824c7 commit 27f5b72

File tree

12 files changed

+161
-37
lines changed

12 files changed

+161
-37
lines changed

drivers/firmware/sysfb.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static struct platform_device *pd;
3939
static DEFINE_MUTEX(disable_lock);
4040
static bool disabled;
4141

42+
static struct device *sysfb_parent_dev(const struct screen_info *si);
43+
4244
static bool sysfb_unregister(void)
4345
{
4446
if (IS_ERR_OR_NULL(pd))
@@ -52,6 +54,7 @@ static bool sysfb_unregister(void)
5254

5355
/**
5456
* sysfb_disable() - disable the Generic System Framebuffers support
57+
* @dev: the device to check if non-NULL
5558
*
5659
* This disables the registration of system framebuffer devices that match the
5760
* generic drivers that make use of the system framebuffer set up by firmware.
@@ -61,17 +64,21 @@ static bool sysfb_unregister(void)
6164
* Context: The function can sleep. A @disable_lock mutex is acquired to serialize
6265
* against sysfb_init(), that registers a system framebuffer device.
6366
*/
64-
void sysfb_disable(void)
67+
void sysfb_disable(struct device *dev)
6568
{
69+
struct screen_info *si = &screen_info;
70+
6671
mutex_lock(&disable_lock);
67-
sysfb_unregister();
68-
disabled = true;
72+
if (!dev || dev == sysfb_parent_dev(si)) {
73+
sysfb_unregister();
74+
disabled = true;
75+
}
6976
mutex_unlock(&disable_lock);
7077
}
7178
EXPORT_SYMBOL_GPL(sysfb_disable);
7279

7380
#if defined(CONFIG_PCI)
74-
static __init bool sysfb_pci_dev_is_enabled(struct pci_dev *pdev)
81+
static bool sysfb_pci_dev_is_enabled(struct pci_dev *pdev)
7582
{
7683
/*
7784
* TODO: Try to integrate this code into the PCI subsystem
@@ -87,13 +94,13 @@ static __init bool sysfb_pci_dev_is_enabled(struct pci_dev *pdev)
8794
return true;
8895
}
8996
#else
90-
static __init bool sysfb_pci_dev_is_enabled(struct pci_dev *pdev)
97+
static bool sysfb_pci_dev_is_enabled(struct pci_dev *pdev)
9198
{
9299
return false;
93100
}
94101
#endif
95102

96-
static __init struct device *sysfb_parent_dev(const struct screen_info *si)
103+
static struct device *sysfb_parent_dev(const struct screen_info *si)
97104
{
98105
struct pci_dev *pdev;
99106

drivers/gpu/drm/v3d/v3d_sched.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,17 @@ v3d_job_start_stats(struct v3d_job *job, enum v3d_queue queue)
134134
struct v3d_stats *local_stats = &file->stats[queue];
135135
u64 now = local_clock();
136136

137+
preempt_disable();
138+
137139
write_seqcount_begin(&local_stats->lock);
138140
local_stats->start_ns = now;
139141
write_seqcount_end(&local_stats->lock);
140142

141143
write_seqcount_begin(&global_stats->lock);
142144
global_stats->start_ns = now;
143145
write_seqcount_end(&global_stats->lock);
146+
147+
preempt_enable();
144148
}
145149

146150
static void
@@ -162,8 +166,10 @@ v3d_job_update_stats(struct v3d_job *job, enum v3d_queue queue)
162166
struct v3d_stats *local_stats = &file->stats[queue];
163167
u64 now = local_clock();
164168

169+
preempt_disable();
165170
v3d_stats_update(local_stats, now);
166171
v3d_stats_update(global_stats, now);
172+
preempt_enable();
167173
}
168174

169175
static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job)

drivers/gpu/drm/vmwgfx/vmwgfx_blit.c

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
**************************************************************************/
2828

2929
#include "vmwgfx_drv.h"
30+
31+
#include "vmwgfx_bo.h"
3032
#include <linux/highmem.h>
3133

3234
/*
@@ -420,13 +422,105 @@ static int vmw_bo_cpu_blit_line(struct vmw_bo_blit_line_data *d,
420422
return 0;
421423
}
422424

425+
static void *map_external(struct vmw_bo *bo, struct iosys_map *map)
426+
{
427+
struct vmw_private *vmw =
428+
container_of(bo->tbo.bdev, struct vmw_private, bdev);
429+
void *ptr = NULL;
430+
int ret;
431+
432+
if (bo->tbo.base.import_attach) {
433+
ret = dma_buf_vmap(bo->tbo.base.dma_buf, map);
434+
if (ret) {
435+
drm_dbg_driver(&vmw->drm,
436+
"Wasn't able to map external bo!\n");
437+
goto out;
438+
}
439+
ptr = map->vaddr;
440+
} else {
441+
ptr = vmw_bo_map_and_cache(bo);
442+
}
443+
444+
out:
445+
return ptr;
446+
}
447+
448+
static void unmap_external(struct vmw_bo *bo, struct iosys_map *map)
449+
{
450+
if (bo->tbo.base.import_attach)
451+
dma_buf_vunmap(bo->tbo.base.dma_buf, map);
452+
else
453+
vmw_bo_unmap(bo);
454+
}
455+
456+
static int vmw_external_bo_copy(struct vmw_bo *dst, u32 dst_offset,
457+
u32 dst_stride, struct vmw_bo *src,
458+
u32 src_offset, u32 src_stride,
459+
u32 width_in_bytes, u32 height,
460+
struct vmw_diff_cpy *diff)
461+
{
462+
struct vmw_private *vmw =
463+
container_of(dst->tbo.bdev, struct vmw_private, bdev);
464+
size_t dst_size = dst->tbo.resource->size;
465+
size_t src_size = src->tbo.resource->size;
466+
struct iosys_map dst_map = {0};
467+
struct iosys_map src_map = {0};
468+
int ret, i;
469+
int x_in_bytes;
470+
u8 *vsrc;
471+
u8 *vdst;
472+
473+
vsrc = map_external(src, &src_map);
474+
if (!vsrc) {
475+
drm_dbg_driver(&vmw->drm, "Wasn't able to map src\n");
476+
ret = -ENOMEM;
477+
goto out;
478+
}
479+
480+
vdst = map_external(dst, &dst_map);
481+
if (!vdst) {
482+
drm_dbg_driver(&vmw->drm, "Wasn't able to map dst\n");
483+
ret = -ENOMEM;
484+
goto out;
485+
}
486+
487+
vsrc += src_offset;
488+
vdst += dst_offset;
489+
if (src_stride == dst_stride) {
490+
dst_size -= dst_offset;
491+
src_size -= src_offset;
492+
memcpy(vdst, vsrc,
493+
min(dst_stride * height, min(dst_size, src_size)));
494+
} else {
495+
WARN_ON(dst_stride < width_in_bytes);
496+
for (i = 0; i < height; ++i) {
497+
memcpy(vdst, vsrc, width_in_bytes);
498+
vsrc += src_stride;
499+
vdst += dst_stride;
500+
}
501+
}
502+
503+
x_in_bytes = (dst_offset % dst_stride);
504+
diff->rect.x1 = x_in_bytes / diff->cpp;
505+
diff->rect.y1 = ((dst_offset - x_in_bytes) / dst_stride);
506+
diff->rect.x2 = diff->rect.x1 + width_in_bytes / diff->cpp;
507+
diff->rect.y2 = diff->rect.y1 + height;
508+
509+
ret = 0;
510+
out:
511+
unmap_external(src, &src_map);
512+
unmap_external(dst, &dst_map);
513+
514+
return ret;
515+
}
516+
423517
/**
424518
* vmw_bo_cpu_blit - in-kernel cpu blit.
425519
*
426-
* @dst: Destination buffer object.
520+
* @vmw_dst: Destination buffer object.
427521
* @dst_offset: Destination offset of blit start in bytes.
428522
* @dst_stride: Destination stride in bytes.
429-
* @src: Source buffer object.
523+
* @vmw_src: Source buffer object.
430524
* @src_offset: Source offset of blit start in bytes.
431525
* @src_stride: Source stride in bytes.
432526
* @w: Width of blit.
@@ -444,13 +538,15 @@ static int vmw_bo_cpu_blit_line(struct vmw_bo_blit_line_data *d,
444538
* Neither of the buffer objects may be placed in PCI memory
445539
* (Fixed memory in TTM terminology) when using this function.
446540
*/
447-
int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
541+
int vmw_bo_cpu_blit(struct vmw_bo *vmw_dst,
448542
u32 dst_offset, u32 dst_stride,
449-
struct ttm_buffer_object *src,
543+
struct vmw_bo *vmw_src,
450544
u32 src_offset, u32 src_stride,
451545
u32 w, u32 h,
452546
struct vmw_diff_cpy *diff)
453547
{
548+
struct ttm_buffer_object *src = &vmw_src->tbo;
549+
struct ttm_buffer_object *dst = &vmw_dst->tbo;
454550
struct ttm_operation_ctx ctx = {
455551
.interruptible = false,
456552
.no_wait_gpu = false
@@ -460,6 +556,11 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
460556
int ret = 0;
461557
struct page **dst_pages = NULL;
462558
struct page **src_pages = NULL;
559+
bool src_external = (src->ttm->page_flags & TTM_TT_FLAG_EXTERNAL) != 0;
560+
bool dst_external = (dst->ttm->page_flags & TTM_TT_FLAG_EXTERNAL) != 0;
561+
562+
if (WARN_ON(dst == src))
563+
return -EINVAL;
463564

464565
/* Buffer objects need to be either pinned or reserved: */
465566
if (!(dst->pin_count))
@@ -479,6 +580,11 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
479580
return ret;
480581
}
481582

583+
if (src_external || dst_external)
584+
return vmw_external_bo_copy(vmw_dst, dst_offset, dst_stride,
585+
vmw_src, src_offset, src_stride,
586+
w, h, diff);
587+
482588
if (!src->ttm->pages && src->ttm->sg) {
483589
src_pages = kvmalloc_array(src->ttm->num_pages,
484590
sizeof(struct page *), GFP_KERNEL);

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ void *vmw_bo_map_and_cache_size(struct vmw_bo *vbo, size_t size)
360360
void *virtual;
361361
int ret;
362362

363+
atomic_inc(&vbo->map_count);
364+
363365
virtual = ttm_kmap_obj_virtual(&vbo->map, &not_used);
364366
if (virtual)
365367
return virtual;
@@ -383,11 +385,17 @@ void *vmw_bo_map_and_cache_size(struct vmw_bo *vbo, size_t size)
383385
*/
384386
void vmw_bo_unmap(struct vmw_bo *vbo)
385387
{
388+
int map_count;
389+
386390
if (vbo->map.bo == NULL)
387391
return;
388392

389-
ttm_bo_kunmap(&vbo->map);
390-
vbo->map.bo = NULL;
393+
map_count = atomic_dec_return(&vbo->map_count);
394+
395+
if (!map_count) {
396+
ttm_bo_kunmap(&vbo->map);
397+
vbo->map.bo = NULL;
398+
}
391399
}
392400

393401

@@ -421,6 +429,7 @@ static int vmw_bo_init(struct vmw_private *dev_priv,
421429
vmw_bo->tbo.priority = 3;
422430
vmw_bo->res_tree = RB_ROOT;
423431
xa_init(&vmw_bo->detached_resources);
432+
atomic_set(&vmw_bo->map_count, 0);
424433

425434
params->size = ALIGN(params->size, PAGE_SIZE);
426435
drm_gem_private_object_init(vdev, &vmw_bo->tbo.base, params->size);

drivers/gpu/drm/vmwgfx/vmwgfx_bo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ struct vmw_bo_params {
7171
* @map: Kmap object for semi-persistent mappings
7272
* @res_tree: RB tree of resources using this buffer object as a backing MOB
7373
* @res_prios: Eviction priority counts for attached resources
74+
* @map_count: The number of currently active maps. Will differ from the
75+
* cpu_writers because it includes kernel maps.
7476
* @cpu_writers: Number of synccpu write grabs. Protected by reservation when
7577
* increased. May be decreased without reservation.
7678
* @dx_query_ctx: DX context if this buffer object is used as a DX query MOB
@@ -90,6 +92,7 @@ struct vmw_bo {
9092
u32 res_prios[TTM_MAX_BO_PRIORITY];
9193
struct xarray detached_resources;
9294

95+
atomic_t map_count;
9396
atomic_t cpu_writers;
9497
/* Not ref-counted. Protected by binding_mutex */
9598
struct vmw_resource *dx_query_ctx;

drivers/gpu/drm/vmwgfx/vmwgfx_drv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,9 +1353,9 @@ void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
13531353

13541354
void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
13551355

1356-
int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
1356+
int vmw_bo_cpu_blit(struct vmw_bo *dst,
13571357
u32 dst_offset, u32 dst_stride,
1358-
struct ttm_buffer_object *src,
1358+
struct vmw_bo *src,
13591359
u32 src_offset, u32 src_stride,
13601360
u32 w, u32 h,
13611361
struct vmw_diff_cpy *diff);

drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static void vmw_stdu_bo_cpu_commit(struct vmw_kms_dirty *dirty)
502502
container_of(dirty->unit, typeof(*stdu), base);
503503
s32 width, height;
504504
s32 src_pitch, dst_pitch;
505-
struct ttm_buffer_object *src_bo, *dst_bo;
505+
struct vmw_bo *src_bo, *dst_bo;
506506
u32 src_offset, dst_offset;
507507
struct vmw_diff_cpy diff = VMW_CPU_BLIT_DIFF_INITIALIZER(stdu->cpp);
508508

@@ -517,11 +517,11 @@ static void vmw_stdu_bo_cpu_commit(struct vmw_kms_dirty *dirty)
517517

518518
/* Assume we are blitting from Guest (bo) to Host (display_srf) */
519519
src_pitch = stdu->display_srf->metadata.base_size.width * stdu->cpp;
520-
src_bo = &stdu->display_srf->res.guest_memory_bo->tbo;
520+
src_bo = stdu->display_srf->res.guest_memory_bo;
521521
src_offset = ddirty->top * src_pitch + ddirty->left * stdu->cpp;
522522

523523
dst_pitch = ddirty->pitch;
524-
dst_bo = &ddirty->buf->tbo;
524+
dst_bo = ddirty->buf;
525525
dst_offset = ddirty->fb_top * dst_pitch + ddirty->fb_left * stdu->cpp;
526526

527527
(void) vmw_bo_cpu_blit(dst_bo, dst_offset, dst_pitch,
@@ -1170,7 +1170,7 @@ vmw_stdu_bo_populate_update_cpu(struct vmw_du_update_plane *update, void *cmd,
11701170
struct vmw_diff_cpy diff = VMW_CPU_BLIT_DIFF_INITIALIZER(0);
11711171
struct vmw_stdu_update_gb_image *cmd_img = cmd;
11721172
struct vmw_stdu_update *cmd_update;
1173-
struct ttm_buffer_object *src_bo, *dst_bo;
1173+
struct vmw_bo *src_bo, *dst_bo;
11741174
u32 src_offset, dst_offset;
11751175
s32 src_pitch, dst_pitch;
11761176
s32 width, height;
@@ -1184,11 +1184,11 @@ vmw_stdu_bo_populate_update_cpu(struct vmw_du_update_plane *update, void *cmd,
11841184

11851185
diff.cpp = stdu->cpp;
11861186

1187-
dst_bo = &stdu->display_srf->res.guest_memory_bo->tbo;
1187+
dst_bo = stdu->display_srf->res.guest_memory_bo;
11881188
dst_pitch = stdu->display_srf->metadata.base_size.width * stdu->cpp;
11891189
dst_offset = bb->y1 * dst_pitch + bb->x1 * stdu->cpp;
11901190

1191-
src_bo = &vfbbo->buffer->tbo;
1191+
src_bo = vfbbo->buffer;
11921192
src_pitch = update->vfb->base.pitches[0];
11931193
src_offset = bo_update->fb_top * src_pitch + bo_update->fb_left *
11941194
stdu->cpp;

drivers/gpu/drm/vmwgfx/vmwgfx_surface.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,9 +2283,11 @@ int vmw_dumb_create(struct drm_file *file_priv,
22832283
/*
22842284
* Without mob support we're just going to use raw memory buffer
22852285
* because we wouldn't be able to support full surface coherency
2286-
* without mobs
2286+
* without mobs. There also no reason to support surface coherency
2287+
* without 3d (i.e. gpu usage on the host) because then all the
2288+
* contents is going to be rendered guest side.
22872289
*/
2288-
if (!dev_priv->has_mob) {
2290+
if (!dev_priv->has_mob || !vmw_supports_3d(dev_priv)) {
22892291
int cpp = DIV_ROUND_UP(args->bpp, 8);
22902292

22912293
switch (cpp) {

drivers/of/platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int __init of_platform_default_populate_init(void)
592592
* This can happen for example on DT systems that do EFI
593593
* booting and may provide a GOP handle to the EFI stub.
594594
*/
595-
sysfb_disable();
595+
sysfb_disable(NULL);
596596
of_platform_device_create(node, NULL, NULL);
597597
of_node_put(node);
598598
}

0 commit comments

Comments
 (0)