drivers/gpu/drm/verisilicon/vs_cursor_plane.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/verisilicon/vs_cursor_plane.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/verisilicon/vs_cursor_plane.c
Extension
.c
Size
8181 bytes
Lines
273
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-only
/*
 * Copyright (C) 2026 Institute of Software, Chinese Academy of Sciences (ISCAS)
 *
 * Authors:
 * Icenowy Zheng <zhengxingda@iscas.ac.cn>
 */

#include <linux/log2.h>
#include <linux/regmap.h>

#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_crtc.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_framebuffer.h>
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_modeset_helper_vtables.h>
#include <drm/drm_plane.h>
#include <drm/drm_print.h>

#include "vs_crtc.h"
#include "vs_plane.h"
#include "vs_dc.h"
#include "vs_hwdb.h"
#include "vs_cursor_plane_regs.h"

#define VSDC_MIN_CURSOR_SIZE 32
#define VSDC_MAX_CURSOR_SIZE 256

#define VSDC_CURSOR_LOCATION_MAX_POSITIVE BIT_MASK(15)
#define VSDC_CURSOR_LOCATION_MAX_NEGATIVE BIT_MASK(5)

static bool vs_cursor_plane_check_coord(int32_t coord)
{
	if (coord >= 0)
		return coord <= VSDC_CURSOR_LOCATION_MAX_POSITIVE;
	else
		return (-coord) <= VSDC_CURSOR_LOCATION_MAX_NEGATIVE;
}

static int vs_cursor_plane_atomic_check(struct drm_plane *plane,
					struct drm_atomic_commit *state)
{
	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
										 plane);
	struct drm_crtc *crtc = new_plane_state->crtc;
	struct drm_framebuffer *fb = new_plane_state->fb;
	struct drm_crtc_state *crtc_state = NULL;
	struct vs_crtc *vcrtc;
	struct vs_dc *dc;
	int ret;

	if (crtc)
		crtc_state = drm_atomic_get_new_crtc_state(state, crtc);

	ret = drm_atomic_helper_check_plane_state(new_plane_state,
						  crtc_state,
						  DRM_PLANE_NO_SCALING,
						  DRM_PLANE_NO_SCALING,
						  true, true);
	if (ret)
		return ret;

	if (!new_plane_state->visible)
		return 0; /* Skip validity check */

	vcrtc = drm_crtc_to_vs_crtc(crtc);
	dc = vcrtc->dc;

	/* Only certain PoT square sizes is supported. */
	if (!is_power_of_2(new_plane_state->crtc_w) ||
	    new_plane_state->crtc_w < VSDC_MIN_CURSOR_SIZE ||
	    new_plane_state->crtc_w > dc->identity.max_cursor_size)
		return -EINVAL;

	if (new_plane_state->crtc_w != new_plane_state->crtc_h)
		return -EINVAL;

	/* Check if the cursor is inside the register fields' range */
	if (!vs_cursor_plane_check_coord(new_plane_state->crtc_x) ||
	    !vs_cursor_plane_check_coord(new_plane_state->crtc_y))
		return -EINVAL;

	/* Extra line padding isn't supported */
	if (fb->pitches[0] !=
	    drm_format_info_min_pitch(fb->format, 0, new_plane_state->crtc_w))
		return -EINVAL;

	return 0;

Annotation

Implementation Notes