mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-21 23:01:04 +07:00
438b74a549
Replace uses of fb->pixel_format with fb->format->format. Less duplicated information is a good thing. Note that coccinelle failed to eliminate the "/* fourcc format */" comment from drm_framebuffer.h, so I had to do that part manually. @@ struct drm_framebuffer *FB; expression E; @@ drm_helper_mode_fill_fb_struct(...) { ... - FB->pixel_format = E; ... } @@ struct drm_framebuffer *FB; expression E; @@ i9xx_get_initial_plane_config(...) { ... - FB->pixel_format = E; ... } @@ struct drm_framebuffer *FB; expression E; @@ ironlake_get_initial_plane_config(...) { ... - FB->pixel_format = E; ... } @@ struct drm_framebuffer *FB; expression E; @@ skylake_get_initial_plane_config(...) { ... - FB->pixel_format = E; ... } @@ struct drm_framebuffer *a; struct drm_framebuffer b; @@ ( - a->pixel_format + a->format->format | - b.pixel_format + b.format->format ) @@ struct drm_plane_state *a; struct drm_plane_state b; @@ ( - a->fb->pixel_format + a->fb->format->format | - b.fb->pixel_format + b.fb->format->format ) @@ struct drm_crtc *CRTC; @@ ( - CRTC->primary->fb->pixel_format + CRTC->primary->fb->format->format | - CRTC->primary->state->fb->pixel_format + CRTC->primary->state->fb->format->format ) @@ struct drm_mode_set *set; @@ ( - set->fb->pixel_format + set->fb->format->format | - set->crtc->primary->fb->pixel_format + set->crtc->primary->fb->format->format ) @@ @@ struct drm_framebuffer { ... - uint32_t pixel_format; ... }; v2: Fix commit message (Laurent) Rebase due to earlier removal of many fb->pixel_format uses, including the 'fb->format = drm_format_info(fb->format->format);' snafu v3: Adjusted the semantic patch a bit and regenerated due to code changes Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v1) Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Link: http://patchwork.freedesktop.org/patch/msgid/1481751175-18463-1-git-send-email-ville.syrjala@linux.intel.com
186 lines
4.9 KiB
C
186 lines
4.9 KiB
C
/*
|
|
* Copyright (c) 2015 MediaTek Inc.
|
|
* Author: CK Hu <ck.hu@mediatek.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include <drm/drmP.h>
|
|
#include <drm/drm_atomic.h>
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_plane_helper.h>
|
|
|
|
#include "mtk_drm_crtc.h"
|
|
#include "mtk_drm_ddp_comp.h"
|
|
#include "mtk_drm_drv.h"
|
|
#include "mtk_drm_fb.h"
|
|
#include "mtk_drm_gem.h"
|
|
#include "mtk_drm_plane.h"
|
|
|
|
static const u32 formats[] = {
|
|
DRM_FORMAT_XRGB8888,
|
|
DRM_FORMAT_ARGB8888,
|
|
DRM_FORMAT_RGB565,
|
|
};
|
|
|
|
static void mtk_plane_reset(struct drm_plane *plane)
|
|
{
|
|
struct mtk_plane_state *state;
|
|
|
|
if (plane->state) {
|
|
__drm_atomic_helper_plane_destroy_state(plane->state);
|
|
|
|
state = to_mtk_plane_state(plane->state);
|
|
memset(state, 0, sizeof(*state));
|
|
} else {
|
|
state = kzalloc(sizeof(*state), GFP_KERNEL);
|
|
if (!state)
|
|
return;
|
|
plane->state = &state->base;
|
|
}
|
|
|
|
state->base.plane = plane;
|
|
state->pending.format = DRM_FORMAT_RGB565;
|
|
}
|
|
|
|
static struct drm_plane_state *mtk_plane_duplicate_state(struct drm_plane *plane)
|
|
{
|
|
struct mtk_plane_state *old_state = to_mtk_plane_state(plane->state);
|
|
struct mtk_plane_state *state;
|
|
|
|
state = kzalloc(sizeof(*state), GFP_KERNEL);
|
|
if (!state)
|
|
return NULL;
|
|
|
|
__drm_atomic_helper_plane_duplicate_state(plane, &state->base);
|
|
|
|
WARN_ON(state->base.plane != plane);
|
|
|
|
state->pending = old_state->pending;
|
|
|
|
return &state->base;
|
|
}
|
|
|
|
static void mtk_drm_plane_destroy_state(struct drm_plane *plane,
|
|
struct drm_plane_state *state)
|
|
{
|
|
__drm_atomic_helper_plane_destroy_state(state);
|
|
kfree(to_mtk_plane_state(state));
|
|
}
|
|
|
|
static const struct drm_plane_funcs mtk_plane_funcs = {
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
.destroy = drm_plane_cleanup,
|
|
.reset = mtk_plane_reset,
|
|
.atomic_duplicate_state = mtk_plane_duplicate_state,
|
|
.atomic_destroy_state = mtk_drm_plane_destroy_state,
|
|
};
|
|
|
|
static int mtk_plane_atomic_check(struct drm_plane *plane,
|
|
struct drm_plane_state *state)
|
|
{
|
|
struct drm_framebuffer *fb = state->fb;
|
|
struct drm_crtc_state *crtc_state;
|
|
struct drm_rect clip = { 0, };
|
|
|
|
if (!fb)
|
|
return 0;
|
|
|
|
if (!mtk_fb_get_gem_obj(fb)) {
|
|
DRM_DEBUG_KMS("buffer is null\n");
|
|
return -EFAULT;
|
|
}
|
|
|
|
if (!state->crtc)
|
|
return 0;
|
|
|
|
crtc_state = drm_atomic_get_crtc_state(state->state, state->crtc);
|
|
if (IS_ERR(crtc_state))
|
|
return PTR_ERR(crtc_state);
|
|
|
|
clip.x2 = crtc_state->mode.hdisplay;
|
|
clip.y2 = crtc_state->mode.vdisplay;
|
|
|
|
return drm_plane_helper_check_state(state, &clip,
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
true, true);
|
|
}
|
|
|
|
static void mtk_plane_atomic_update(struct drm_plane *plane,
|
|
struct drm_plane_state *old_state)
|
|
{
|
|
struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
|
|
struct drm_crtc *crtc = plane->state->crtc;
|
|
struct drm_framebuffer *fb = plane->state->fb;
|
|
struct drm_gem_object *gem;
|
|
struct mtk_drm_gem_obj *mtk_gem;
|
|
unsigned int pitch, format;
|
|
dma_addr_t addr;
|
|
|
|
if (!crtc || WARN_ON(!fb))
|
|
return;
|
|
|
|
gem = mtk_fb_get_gem_obj(fb);
|
|
mtk_gem = to_mtk_gem_obj(gem);
|
|
addr = mtk_gem->dma_addr;
|
|
pitch = fb->pitches[0];
|
|
format = fb->format->format;
|
|
|
|
addr += (plane->state->src.x1 >> 16) * fb->format->cpp[0];
|
|
addr += (plane->state->src.y1 >> 16) * pitch;
|
|
|
|
state->pending.enable = true;
|
|
state->pending.pitch = pitch;
|
|
state->pending.format = format;
|
|
state->pending.addr = addr;
|
|
state->pending.x = plane->state->dst.x1;
|
|
state->pending.y = plane->state->dst.y1;
|
|
state->pending.width = drm_rect_width(&plane->state->dst);
|
|
state->pending.height = drm_rect_height(&plane->state->dst);
|
|
wmb(); /* Make sure the above parameters are set before update */
|
|
state->pending.dirty = true;
|
|
}
|
|
|
|
static void mtk_plane_atomic_disable(struct drm_plane *plane,
|
|
struct drm_plane_state *old_state)
|
|
{
|
|
struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
|
|
|
|
state->pending.enable = false;
|
|
wmb(); /* Make sure the above parameter is set before update */
|
|
state->pending.dirty = true;
|
|
}
|
|
|
|
static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
|
|
.atomic_check = mtk_plane_atomic_check,
|
|
.atomic_update = mtk_plane_atomic_update,
|
|
.atomic_disable = mtk_plane_atomic_disable,
|
|
};
|
|
|
|
int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
|
|
unsigned long possible_crtcs, enum drm_plane_type type)
|
|
{
|
|
int err;
|
|
|
|
err = drm_universal_plane_init(dev, plane, possible_crtcs,
|
|
&mtk_plane_funcs, formats,
|
|
ARRAY_SIZE(formats), type, NULL);
|
|
if (err) {
|
|
DRM_ERROR("failed to initialize plane\n");
|
|
return err;
|
|
}
|
|
|
|
drm_plane_helper_add(plane, &mtk_plane_helper_funcs);
|
|
|
|
return 0;
|
|
}
|