drivers/gpu/drm/imx/dc/dc-plane.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/imx/dc/dc-plane.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/imx/dc/dc-plane.c
Extension
.c
Size
6093 bytes
Lines
225
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 2024 NXP
 */

#include <linux/container_of.h>

#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_atomic_state_helper.h>
#include <drm/drm_crtc.h>
#include <drm/drm_drv.h>
#include <drm/drm_fb_dma_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_framebuffer.h>
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_plane_helper.h>
#include <drm/drm_print.h>

#include "dc-drv.h"
#include "dc-fu.h"
#include "dc-kms.h"

#define DC_PLANE_MAX_PITCH	0x10000
#define DC_PLANE_MAX_PIX_CNT	8192

#define dc_plane_dbg(plane, fmt, ...)					\
do {									\
	struct drm_plane *_plane = (plane);				\
	drm_dbg_kms(_plane->dev, "[PLANE:%d:%s] " fmt,			\
		    _plane->base.id, _plane->name, ##__VA_ARGS__);	\
} while (0)

static const uint32_t dc_plane_formats[] = {
	DRM_FORMAT_XRGB8888,
};

static const struct drm_plane_funcs dc_plane_funcs = {
	.update_plane		= drm_atomic_helper_update_plane,
	.disable_plane		= drm_atomic_helper_disable_plane,
	.destroy		= drm_plane_cleanup,
	.reset			= drm_atomic_helper_plane_reset,
	.atomic_duplicate_state	= drm_atomic_helper_plane_duplicate_state,
	.atomic_destroy_state	= drm_atomic_helper_plane_destroy_state,
};

static inline struct dc_plane *to_dc_plane(struct drm_plane *plane)
{
	return container_of(plane, struct dc_plane, base);
}

static int dc_plane_check_max_source_resolution(struct drm_plane_state *state)
{
	int src_h = drm_rect_height(&state->src) >> 16;
	int src_w = drm_rect_width(&state->src) >> 16;

	if (src_w > DC_PLANE_MAX_PIX_CNT || src_h > DC_PLANE_MAX_PIX_CNT) {
		dc_plane_dbg(state->plane, "invalid source resolution\n");
		return -EINVAL;
	}

	return 0;
}

static int dc_plane_check_fb(struct drm_plane_state *state)
{
	struct drm_framebuffer *fb = state->fb;
	dma_addr_t baseaddr = drm_fb_dma_get_gem_addr(fb, state, 0);

	/* base address alignment */
	if (baseaddr & 0x3) {
		dc_plane_dbg(state->plane, "fb bad baddr alignment\n");
		return -EINVAL;
	}

	/* pitches[0] range */
	if (fb->pitches[0] > DC_PLANE_MAX_PITCH) {
		dc_plane_dbg(state->plane, "fb pitches[0] is out of range\n");
		return -EINVAL;
	}

	/* pitches[0] alignment */
	if (fb->pitches[0] & 0x3) {
		dc_plane_dbg(state->plane, "fb bad pitches[0] alignment\n");
		return -EINVAL;
	}

	return 0;
}

Annotation

Implementation Notes