drivers/gpu/drm/loongson/lsdc_benchmark.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/loongson/lsdc_benchmark.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/loongson/lsdc_benchmark.c
Extension
.c
Size
2959 bytes
Lines
135
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2023 Loongson Technology Corporation Limited
 */

#include <drm/drm_debugfs.h>
#include <drm/drm_print.h>

#include "lsdc_benchmark.h"
#include "lsdc_drv.h"
#include "lsdc_gem.h"
#include "lsdc_ttm.h"

typedef void (*lsdc_copy_proc_t)(struct lsdc_bo *src_bo,
				 struct lsdc_bo *dst_bo,
				 unsigned int size,
				 int n);

static void lsdc_copy_gtt_to_vram_cpu(struct lsdc_bo *src_bo,
				      struct lsdc_bo *dst_bo,
				      unsigned int size,
				      int n)
{
	lsdc_bo_kmap(src_bo);
	lsdc_bo_kmap(dst_bo);

	while (n--)
		memcpy_toio(dst_bo->kptr, src_bo->kptr, size);

	lsdc_bo_kunmap(src_bo);
	lsdc_bo_kunmap(dst_bo);
}

static void lsdc_copy_vram_to_gtt_cpu(struct lsdc_bo *src_bo,
				      struct lsdc_bo *dst_bo,
				      unsigned int size,
				      int n)
{
	lsdc_bo_kmap(src_bo);
	lsdc_bo_kmap(dst_bo);

	while (n--)
		memcpy_fromio(dst_bo->kptr, src_bo->kptr, size);

	lsdc_bo_kunmap(src_bo);
	lsdc_bo_kunmap(dst_bo);
}

static void lsdc_copy_gtt_to_gtt_cpu(struct lsdc_bo *src_bo,
				     struct lsdc_bo *dst_bo,
				     unsigned int size,
				     int n)
{
	lsdc_bo_kmap(src_bo);
	lsdc_bo_kmap(dst_bo);

	while (n--)
		memcpy(dst_bo->kptr, src_bo->kptr, size);

	lsdc_bo_kunmap(src_bo);
	lsdc_bo_kunmap(dst_bo);
}

static void lsdc_benchmark_copy(struct lsdc_device *ldev,
				unsigned int size,
				unsigned int n,
				u32 src_domain,
				u32 dst_domain,
				lsdc_copy_proc_t copy_proc,
				struct drm_printer *p)
{
	struct drm_device *ddev = &ldev->base;
	struct lsdc_bo *src_bo;
	struct lsdc_bo *dst_bo;
	unsigned long start_jiffies;
	unsigned long end_jiffies;
	unsigned int throughput;
	unsigned int time;

	src_bo = lsdc_bo_create_kernel_pinned(ddev, src_domain, size);
	dst_bo = lsdc_bo_create_kernel_pinned(ddev, dst_domain, size);

	start_jiffies = jiffies;

	copy_proc(src_bo, dst_bo, size, n);

	end_jiffies = jiffies;

	lsdc_bo_free_kernel_pinned(src_bo);
	lsdc_bo_free_kernel_pinned(dst_bo);

Annotation

Implementation Notes