2015-03-02 14:01:12 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Broadcom
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC: VC4 plane module
|
|
|
|
*
|
|
|
|
* Each DRM plane is a layer of pixels being scanned out by the HVS.
|
|
|
|
*
|
|
|
|
* At atomic modeset check time, we compute the HVS display element
|
|
|
|
* state that would be necessary for displaying the plane (giving us a
|
|
|
|
* chance to figure out if a plane configuration is invalid), then at
|
|
|
|
* atomic flush time the CRTC will ask us to write our element state
|
|
|
|
* into the region of the HVS that it has allocated for us.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "vc4_drv.h"
|
|
|
|
#include "vc4_regs.h"
|
|
|
|
#include "drm_atomic_helper.h"
|
|
|
|
#include "drm_fb_cma_helper.h"
|
|
|
|
#include "drm_plane_helper.h"
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
enum vc4_scaling_mode {
|
|
|
|
VC4_SCALING_NONE,
|
|
|
|
VC4_SCALING_TPZ,
|
|
|
|
VC4_SCALING_PPF,
|
|
|
|
};
|
|
|
|
|
2015-03-02 14:01:12 -07:00
|
|
|
struct vc4_plane_state {
|
|
|
|
struct drm_plane_state base;
|
2015-12-28 15:14:09 -07:00
|
|
|
/* System memory copy of the display list for this element, computed
|
|
|
|
* at atomic_check time.
|
|
|
|
*/
|
2015-03-02 14:01:12 -07:00
|
|
|
u32 *dlist;
|
2015-12-28 15:14:09 -07:00
|
|
|
u32 dlist_size; /* Number of dwords allocated for the display list */
|
2015-03-02 14:01:12 -07:00
|
|
|
u32 dlist_count; /* Number of used dwords in the display list. */
|
2015-11-30 13:34:01 -07:00
|
|
|
|
2015-12-30 12:50:22 -07:00
|
|
|
/* Offset in the dlist to various words, for pageflip or
|
|
|
|
* cursor updates.
|
|
|
|
*/
|
|
|
|
u32 pos0_offset;
|
|
|
|
u32 pos2_offset;
|
|
|
|
u32 ptr0_offset;
|
2015-11-30 13:34:01 -07:00
|
|
|
|
|
|
|
/* Offset where the plane's dlist was last stored in the
|
2015-12-28 15:14:09 -07:00
|
|
|
* hardware at vc4_crtc_atomic_flush() time.
|
|
|
|
*/
|
2015-12-28 15:14:57 -07:00
|
|
|
u32 __iomem *hw_dlist;
|
2015-12-28 15:34:44 -07:00
|
|
|
|
|
|
|
/* Clipped coordinates of the plane on the display. */
|
|
|
|
int crtc_x, crtc_y, crtc_w, crtc_h;
|
2015-10-20 09:06:57 -06:00
|
|
|
/* Clipped area being scanned from in the FB. */
|
|
|
|
u32 src_x, src_y, src_w, src_h;
|
|
|
|
|
|
|
|
enum vc4_scaling_mode x_scaling, y_scaling;
|
|
|
|
bool is_unity;
|
2015-12-28 15:34:44 -07:00
|
|
|
|
|
|
|
/* Offset to start scanning out from the start of the plane's
|
|
|
|
* BO.
|
|
|
|
*/
|
|
|
|
u32 offset;
|
2015-10-20 09:06:57 -06:00
|
|
|
|
|
|
|
/* Our allocation in LBM for temporary storage during scaling. */
|
|
|
|
struct drm_mm_node lbm;
|
2015-03-02 14:01:12 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct vc4_plane_state *
|
|
|
|
to_vc4_plane_state(struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
return (struct vc4_plane_state *)state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct hvs_format {
|
|
|
|
u32 drm; /* DRM_FORMAT_* */
|
|
|
|
u32 hvs; /* HVS_FORMAT_* */
|
|
|
|
u32 pixel_order;
|
|
|
|
bool has_alpha;
|
|
|
|
} hvs_formats[] = {
|
|
|
|
{
|
|
|
|
.drm = DRM_FORMAT_XRGB8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888,
|
|
|
|
.pixel_order = HVS_PIXEL_ORDER_ABGR, .has_alpha = false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.drm = DRM_FORMAT_ARGB8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888,
|
|
|
|
.pixel_order = HVS_PIXEL_ORDER_ABGR, .has_alpha = true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct hvs_format *vc4_get_hvs_format(u32 drm_format)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(hvs_formats); i++) {
|
|
|
|
if (hvs_formats[i].drm == drm_format)
|
|
|
|
return &hvs_formats[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
static enum vc4_scaling_mode vc4_get_scaling_mode(u32 src, u32 dst)
|
|
|
|
{
|
|
|
|
if (dst > src)
|
|
|
|
return VC4_SCALING_PPF;
|
|
|
|
else if (dst < src)
|
|
|
|
return VC4_SCALING_TPZ;
|
|
|
|
else
|
|
|
|
return VC4_SCALING_NONE;
|
|
|
|
}
|
|
|
|
|
2015-03-02 14:01:12 -07:00
|
|
|
static bool plane_enabled(struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
return state->fb && state->crtc;
|
|
|
|
}
|
|
|
|
|
2015-10-21 21:12:26 -06:00
|
|
|
static struct drm_plane_state *vc4_plane_duplicate_state(struct drm_plane *plane)
|
2015-03-02 14:01:12 -07:00
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state;
|
|
|
|
|
|
|
|
if (WARN_ON(!plane->state))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vc4_state = kmemdup(plane->state, sizeof(*vc4_state), GFP_KERNEL);
|
|
|
|
if (!vc4_state)
|
|
|
|
return NULL;
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
memset(&vc4_state->lbm, 0, sizeof(vc4_state->lbm));
|
|
|
|
|
2015-03-02 14:01:12 -07:00
|
|
|
__drm_atomic_helper_plane_duplicate_state(plane, &vc4_state->base);
|
|
|
|
|
|
|
|
if (vc4_state->dlist) {
|
|
|
|
vc4_state->dlist = kmemdup(vc4_state->dlist,
|
|
|
|
vc4_state->dlist_count * 4,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!vc4_state->dlist) {
|
|
|
|
kfree(vc4_state);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
vc4_state->dlist_size = vc4_state->dlist_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &vc4_state->base;
|
|
|
|
}
|
|
|
|
|
2015-10-21 21:12:26 -06:00
|
|
|
static void vc4_plane_destroy_state(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
2015-03-02 14:01:12 -07:00
|
|
|
{
|
2015-10-20 09:06:57 -06:00
|
|
|
struct vc4_dev *vc4 = to_vc4_dev(plane->dev);
|
2015-03-02 14:01:12 -07:00
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
if (vc4_state->lbm.allocated) {
|
|
|
|
unsigned long irqflags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&vc4->hvs->mm_lock, irqflags);
|
|
|
|
drm_mm_remove_node(&vc4_state->lbm);
|
|
|
|
spin_unlock_irqrestore(&vc4->hvs->mm_lock, irqflags);
|
|
|
|
}
|
|
|
|
|
2015-03-02 14:01:12 -07:00
|
|
|
kfree(vc4_state->dlist);
|
|
|
|
__drm_atomic_helper_plane_destroy_state(plane, &vc4_state->base);
|
|
|
|
kfree(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called during init to allocate the plane's atomic state. */
|
2015-10-21 21:12:26 -06:00
|
|
|
static void vc4_plane_reset(struct drm_plane *plane)
|
2015-03-02 14:01:12 -07:00
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state;
|
|
|
|
|
|
|
|
WARN_ON(plane->state);
|
|
|
|
|
|
|
|
vc4_state = kzalloc(sizeof(*vc4_state), GFP_KERNEL);
|
|
|
|
if (!vc4_state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
plane->state = &vc4_state->base;
|
|
|
|
vc4_state->base.plane = plane;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vc4_dlist_write(struct vc4_plane_state *vc4_state, u32 val)
|
|
|
|
{
|
|
|
|
if (vc4_state->dlist_count == vc4_state->dlist_size) {
|
|
|
|
u32 new_size = max(4u, vc4_state->dlist_count * 2);
|
|
|
|
u32 *new_dlist = kmalloc(new_size * 4, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!new_dlist)
|
|
|
|
return;
|
|
|
|
memcpy(new_dlist, vc4_state->dlist, vc4_state->dlist_count * 4);
|
|
|
|
|
|
|
|
kfree(vc4_state->dlist);
|
|
|
|
vc4_state->dlist = new_dlist;
|
|
|
|
vc4_state->dlist_size = new_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
vc4_state->dlist[vc4_state->dlist_count++] = val;
|
|
|
|
}
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
/* Returns the scl0/scl1 field based on whether the dimensions need to
|
|
|
|
* be up/down/non-scaled.
|
|
|
|
*
|
|
|
|
* This is a replication of a table from the spec.
|
|
|
|
*/
|
|
|
|
static u32 vc4_get_scl_field(struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
|
|
|
|
|
|
|
|
switch (vc4_state->x_scaling << 2 | vc4_state->y_scaling) {
|
|
|
|
case VC4_SCALING_PPF << 2 | VC4_SCALING_PPF:
|
|
|
|
return SCALER_CTL0_SCL_H_PPF_V_PPF;
|
|
|
|
case VC4_SCALING_TPZ << 2 | VC4_SCALING_PPF:
|
|
|
|
return SCALER_CTL0_SCL_H_TPZ_V_PPF;
|
|
|
|
case VC4_SCALING_PPF << 2 | VC4_SCALING_TPZ:
|
|
|
|
return SCALER_CTL0_SCL_H_PPF_V_TPZ;
|
|
|
|
case VC4_SCALING_TPZ << 2 | VC4_SCALING_TPZ:
|
|
|
|
return SCALER_CTL0_SCL_H_TPZ_V_TPZ;
|
|
|
|
case VC4_SCALING_PPF << 2 | VC4_SCALING_NONE:
|
|
|
|
return SCALER_CTL0_SCL_H_PPF_V_NONE;
|
|
|
|
case VC4_SCALING_NONE << 2 | VC4_SCALING_PPF:
|
|
|
|
return SCALER_CTL0_SCL_H_NONE_V_PPF;
|
|
|
|
case VC4_SCALING_NONE << 2 | VC4_SCALING_TPZ:
|
|
|
|
return SCALER_CTL0_SCL_H_NONE_V_TPZ;
|
|
|
|
case VC4_SCALING_TPZ << 2 | VC4_SCALING_NONE:
|
|
|
|
return SCALER_CTL0_SCL_H_TPZ_V_NONE;
|
|
|
|
default:
|
|
|
|
case VC4_SCALING_NONE << 2 | VC4_SCALING_NONE:
|
|
|
|
/* The unity case is independently handled by
|
|
|
|
* SCALER_CTL0_UNITY.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-28 15:34:44 -07:00
|
|
|
static int vc4_plane_setup_clipping_and_scaling(struct drm_plane_state *state)
|
2015-03-02 14:01:12 -07:00
|
|
|
{
|
2015-10-20 09:06:57 -06:00
|
|
|
struct drm_plane *plane = state->plane;
|
2015-03-02 14:01:12 -07:00
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
|
|
|
|
struct drm_framebuffer *fb = state->fb;
|
2015-10-20 09:06:57 -06:00
|
|
|
u32 subpixel_src_mask = (1 << 16) - 1;
|
2015-12-28 15:34:44 -07:00
|
|
|
|
|
|
|
vc4_state->offset = fb->offsets[0];
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
/* We don't support subpixel source positioning for scaling. */
|
|
|
|
if ((state->src_x & subpixel_src_mask) ||
|
|
|
|
(state->src_y & subpixel_src_mask) ||
|
|
|
|
(state->src_w & subpixel_src_mask) ||
|
|
|
|
(state->src_h & subpixel_src_mask)) {
|
2015-10-23 03:36:27 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
vc4_state->src_x = state->src_x >> 16;
|
|
|
|
vc4_state->src_y = state->src_y >> 16;
|
2015-12-28 15:45:25 -07:00
|
|
|
vc4_state->src_w = state->src_w >> 16;
|
|
|
|
vc4_state->src_h = state->src_h >> 16;
|
|
|
|
|
|
|
|
vc4_state->crtc_x = state->crtc_x;
|
|
|
|
vc4_state->crtc_y = state->crtc_y;
|
|
|
|
vc4_state->crtc_w = state->crtc_w;
|
|
|
|
vc4_state->crtc_h = state->crtc_h;
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
vc4_state->x_scaling = vc4_get_scaling_mode(vc4_state->src_w,
|
|
|
|
vc4_state->crtc_w);
|
|
|
|
vc4_state->y_scaling = vc4_get_scaling_mode(vc4_state->src_h,
|
|
|
|
vc4_state->crtc_h);
|
|
|
|
vc4_state->is_unity = (vc4_state->x_scaling == VC4_SCALING_NONE &&
|
|
|
|
vc4_state->y_scaling == VC4_SCALING_NONE);
|
|
|
|
|
|
|
|
/* No configuring scaling on the cursor plane, since it gets
|
|
|
|
non-vblank-synced updates, and scaling requires requires
|
|
|
|
LBM changes which have to be vblank-synced.
|
|
|
|
*/
|
|
|
|
if (plane->type == DRM_PLANE_TYPE_CURSOR && !vc4_state->is_unity)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Clamp the on-screen start x/y to 0. The hardware doesn't
|
|
|
|
* support negative y, and negative x wastes bandwidth.
|
|
|
|
*/
|
2015-12-28 15:34:44 -07:00
|
|
|
if (vc4_state->crtc_x < 0) {
|
|
|
|
vc4_state->offset += (drm_format_plane_cpp(fb->pixel_format,
|
|
|
|
0) *
|
|
|
|
-vc4_state->crtc_x);
|
2015-12-28 15:45:25 -07:00
|
|
|
vc4_state->src_w += vc4_state->crtc_x;
|
2015-12-28 15:34:44 -07:00
|
|
|
vc4_state->crtc_x = 0;
|
2015-03-02 14:01:12 -07:00
|
|
|
}
|
|
|
|
|
2015-12-28 15:34:44 -07:00
|
|
|
if (vc4_state->crtc_y < 0) {
|
|
|
|
vc4_state->offset += fb->pitches[0] * -vc4_state->crtc_y;
|
2015-12-28 15:45:25 -07:00
|
|
|
vc4_state->src_h += vc4_state->crtc_y;
|
2015-12-28 15:34:44 -07:00
|
|
|
vc4_state->crtc_y = 0;
|
2015-03-02 14:01:12 -07:00
|
|
|
}
|
|
|
|
|
2015-12-28 15:34:44 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
static void vc4_write_tpz(struct vc4_plane_state *vc4_state, u32 src, u32 dst)
|
|
|
|
{
|
|
|
|
u32 scale, recip;
|
|
|
|
|
|
|
|
scale = (1 << 16) * src / dst;
|
|
|
|
|
|
|
|
/* The specs note that while the reciprocal would be defined
|
|
|
|
* as (1<<32)/scale, ~0 is close enough.
|
|
|
|
*/
|
|
|
|
recip = ~0 / scale;
|
|
|
|
|
|
|
|
vc4_dlist_write(vc4_state,
|
|
|
|
VC4_SET_FIELD(scale, SCALER_TPZ0_SCALE) |
|
|
|
|
VC4_SET_FIELD(0, SCALER_TPZ0_IPHASE));
|
|
|
|
vc4_dlist_write(vc4_state,
|
|
|
|
VC4_SET_FIELD(recip, SCALER_TPZ1_RECIP));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vc4_write_ppf(struct vc4_plane_state *vc4_state, u32 src, u32 dst)
|
|
|
|
{
|
|
|
|
u32 scale = (1 << 16) * src / dst;
|
|
|
|
|
|
|
|
vc4_dlist_write(vc4_state,
|
|
|
|
SCALER_PPF_AGC |
|
|
|
|
VC4_SET_FIELD(scale, SCALER_PPF_SCALE) |
|
|
|
|
VC4_SET_FIELD(0, SCALER_PPF_IPHASE));
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 vc4_lbm_size(struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
|
|
|
|
/* This is the worst case number. One of the two sizes will
|
|
|
|
* be used depending on the scaling configuration.
|
|
|
|
*/
|
|
|
|
u32 pix_per_line = max(vc4_state->src_w, (u32)vc4_state->crtc_w);
|
|
|
|
u32 lbm;
|
|
|
|
|
|
|
|
if (vc4_state->is_unity)
|
|
|
|
return 0;
|
|
|
|
else if (vc4_state->y_scaling == VC4_SCALING_TPZ)
|
|
|
|
lbm = pix_per_line * 8;
|
|
|
|
else {
|
|
|
|
/* In special cases, this multiplier might be 12. */
|
|
|
|
lbm = pix_per_line * 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
lbm = roundup(lbm, 32);
|
|
|
|
|
|
|
|
return lbm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vc4_write_scaling_parameters(struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
|
|
|
|
|
|
|
|
/* Ch0 H-PPF Word 0: Scaling Parameters */
|
|
|
|
if (vc4_state->x_scaling == VC4_SCALING_PPF) {
|
|
|
|
vc4_write_ppf(vc4_state,
|
|
|
|
vc4_state->src_w, vc4_state->crtc_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ch0 V-PPF Words 0-1: Scaling Parameters, Context */
|
|
|
|
if (vc4_state->y_scaling == VC4_SCALING_PPF) {
|
|
|
|
vc4_write_ppf(vc4_state,
|
|
|
|
vc4_state->src_h, vc4_state->crtc_h);
|
|
|
|
vc4_dlist_write(vc4_state, 0xc0c0c0c0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ch0 H-TPZ Words 0-1: Scaling Parameters, Recip */
|
|
|
|
if (vc4_state->x_scaling == VC4_SCALING_TPZ) {
|
|
|
|
vc4_write_tpz(vc4_state,
|
|
|
|
vc4_state->src_w, vc4_state->crtc_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ch0 V-TPZ Words 0-2: Scaling Parameters, Recip, Context */
|
|
|
|
if (vc4_state->y_scaling == VC4_SCALING_TPZ) {
|
|
|
|
vc4_write_tpz(vc4_state,
|
|
|
|
vc4_state->src_h, vc4_state->crtc_h);
|
|
|
|
vc4_dlist_write(vc4_state, 0xc0c0c0c0);
|
|
|
|
}
|
|
|
|
}
|
2015-12-28 15:34:44 -07:00
|
|
|
|
|
|
|
/* Writes out a full display list for an active plane to the plane's
|
|
|
|
* private dlist state.
|
|
|
|
*/
|
|
|
|
static int vc4_plane_mode_set(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
|
|
|
{
|
2015-10-20 09:06:57 -06:00
|
|
|
struct vc4_dev *vc4 = to_vc4_dev(plane->dev);
|
2015-12-28 15:34:44 -07:00
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
|
|
|
|
struct drm_framebuffer *fb = state->fb;
|
|
|
|
struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0);
|
|
|
|
u32 ctl0_offset = vc4_state->dlist_count;
|
|
|
|
const struct hvs_format *format = vc4_get_hvs_format(fb->pixel_format);
|
2015-10-20 09:06:57 -06:00
|
|
|
u32 scl;
|
|
|
|
u32 lbm_size;
|
|
|
|
unsigned long irqflags;
|
2015-12-28 15:34:44 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = vc4_plane_setup_clipping_and_scaling(state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
/* Allocate the LBM memory that the HVS will use for temporary
|
|
|
|
* storage due to our scaling/format conversion.
|
|
|
|
*/
|
|
|
|
lbm_size = vc4_lbm_size(state);
|
|
|
|
if (lbm_size) {
|
|
|
|
if (!vc4_state->lbm.allocated) {
|
|
|
|
spin_lock_irqsave(&vc4->hvs->mm_lock, irqflags);
|
|
|
|
ret = drm_mm_insert_node(&vc4->hvs->lbm_mm,
|
|
|
|
&vc4_state->lbm,
|
|
|
|
lbm_size, 32, 0);
|
|
|
|
spin_unlock_irqrestore(&vc4->hvs->mm_lock, irqflags);
|
|
|
|
} else {
|
|
|
|
WARN_ON_ONCE(lbm_size != vc4_state->lbm.size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
scl = vc4_get_scl_field(state);
|
|
|
|
|
|
|
|
/* Control word */
|
2015-03-02 14:01:12 -07:00
|
|
|
vc4_dlist_write(vc4_state,
|
|
|
|
SCALER_CTL0_VALID |
|
|
|
|
(format->pixel_order << SCALER_CTL0_ORDER_SHIFT) |
|
|
|
|
(format->hvs << SCALER_CTL0_PIXEL_FORMAT_SHIFT) |
|
2015-10-20 09:06:57 -06:00
|
|
|
(vc4_state->is_unity ? SCALER_CTL0_UNITY : 0) |
|
|
|
|
VC4_SET_FIELD(scl, SCALER_CTL0_SCL0) |
|
|
|
|
VC4_SET_FIELD(scl, SCALER_CTL0_SCL1));
|
2015-03-02 14:01:12 -07:00
|
|
|
|
|
|
|
/* Position Word 0: Image Positions and Alpha Value */
|
2015-12-30 12:50:22 -07:00
|
|
|
vc4_state->pos0_offset = vc4_state->dlist_count;
|
2015-03-02 14:01:12 -07:00
|
|
|
vc4_dlist_write(vc4_state,
|
|
|
|
VC4_SET_FIELD(0xff, SCALER_POS0_FIXED_ALPHA) |
|
2015-12-28 15:34:44 -07:00
|
|
|
VC4_SET_FIELD(vc4_state->crtc_x, SCALER_POS0_START_X) |
|
|
|
|
VC4_SET_FIELD(vc4_state->crtc_y, SCALER_POS0_START_Y));
|
2015-03-02 14:01:12 -07:00
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
/* Position Word 1: Scaled Image Dimensions. */
|
|
|
|
if (!vc4_state->is_unity) {
|
|
|
|
vc4_dlist_write(vc4_state,
|
|
|
|
VC4_SET_FIELD(vc4_state->crtc_w,
|
|
|
|
SCALER_POS1_SCL_WIDTH) |
|
|
|
|
VC4_SET_FIELD(vc4_state->crtc_h,
|
|
|
|
SCALER_POS1_SCL_HEIGHT));
|
|
|
|
}
|
2015-03-02 14:01:12 -07:00
|
|
|
|
|
|
|
/* Position Word 2: Source Image Size, Alpha Mode */
|
2015-12-30 12:50:22 -07:00
|
|
|
vc4_state->pos2_offset = vc4_state->dlist_count;
|
2015-03-02 14:01:12 -07:00
|
|
|
vc4_dlist_write(vc4_state,
|
|
|
|
VC4_SET_FIELD(format->has_alpha ?
|
|
|
|
SCALER_POS2_ALPHA_MODE_PIPELINE :
|
|
|
|
SCALER_POS2_ALPHA_MODE_FIXED,
|
|
|
|
SCALER_POS2_ALPHA_MODE) |
|
2015-12-28 15:45:25 -07:00
|
|
|
VC4_SET_FIELD(vc4_state->src_w, SCALER_POS2_WIDTH) |
|
|
|
|
VC4_SET_FIELD(vc4_state->src_h, SCALER_POS2_HEIGHT));
|
2015-03-02 14:01:12 -07:00
|
|
|
|
|
|
|
/* Position Word 3: Context. Written by the HVS. */
|
|
|
|
vc4_dlist_write(vc4_state, 0xc0c0c0c0);
|
|
|
|
|
|
|
|
/* Pointer Word 0: RGB / Y Pointer */
|
2015-12-30 12:50:22 -07:00
|
|
|
vc4_state->ptr0_offset = vc4_state->dlist_count;
|
2015-12-28 15:34:44 -07:00
|
|
|
vc4_dlist_write(vc4_state, bo->paddr + vc4_state->offset);
|
2015-03-02 14:01:12 -07:00
|
|
|
|
|
|
|
/* Pointer Context Word 0: Written by the HVS */
|
|
|
|
vc4_dlist_write(vc4_state, 0xc0c0c0c0);
|
|
|
|
|
|
|
|
/* Pitch word 0: Pointer 0 Pitch */
|
|
|
|
vc4_dlist_write(vc4_state,
|
|
|
|
VC4_SET_FIELD(fb->pitches[0], SCALER_SRC_PITCH));
|
|
|
|
|
2015-10-20 09:06:57 -06:00
|
|
|
if (!vc4_state->is_unity) {
|
|
|
|
/* LBM Base Address. */
|
|
|
|
if (vc4_state->y_scaling != VC4_SCALING_NONE)
|
|
|
|
vc4_dlist_write(vc4_state, vc4_state->lbm.start);
|
|
|
|
|
|
|
|
vc4_write_scaling_parameters(state);
|
|
|
|
|
|
|
|
/* If any PPF setup was done, then all the kernel
|
|
|
|
* pointers get uploaded.
|
|
|
|
*/
|
|
|
|
if (vc4_state->x_scaling == VC4_SCALING_PPF ||
|
|
|
|
vc4_state->y_scaling == VC4_SCALING_PPF) {
|
|
|
|
u32 kernel = VC4_SET_FIELD(vc4->hvs->mitchell_netravali_filter.start,
|
|
|
|
SCALER_PPF_KERNEL_OFFSET);
|
|
|
|
|
|
|
|
/* HPPF plane 0 */
|
|
|
|
vc4_dlist_write(vc4_state, kernel);
|
|
|
|
/* VPPF plane 0 */
|
|
|
|
vc4_dlist_write(vc4_state, kernel);
|
|
|
|
/* HPPF plane 1 */
|
|
|
|
vc4_dlist_write(vc4_state, kernel);
|
|
|
|
/* VPPF plane 1 */
|
|
|
|
vc4_dlist_write(vc4_state, kernel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 14:01:12 -07:00
|
|
|
vc4_state->dlist[ctl0_offset] |=
|
|
|
|
VC4_SET_FIELD(vc4_state->dlist_count, SCALER_CTL0_SIZE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If a modeset involves changing the setup of a plane, the atomic
|
|
|
|
* infrastructure will call this to validate a proposed plane setup.
|
|
|
|
* However, if a plane isn't getting updated, this (and the
|
|
|
|
* corresponding vc4_plane_atomic_update) won't get called. Thus, we
|
|
|
|
* compute the dlist here and have all active plane dlists get updated
|
|
|
|
* in the CRTC's flush.
|
|
|
|
*/
|
|
|
|
static int vc4_plane_atomic_check(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
|
|
|
|
|
|
|
|
vc4_state->dlist_count = 0;
|
|
|
|
|
|
|
|
if (plane_enabled(state))
|
|
|
|
return vc4_plane_mode_set(plane, state);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vc4_plane_atomic_update(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *old_state)
|
|
|
|
{
|
|
|
|
/* No contents here. Since we don't know where in the CRTC's
|
|
|
|
* dlist we should be stored, our dlist is uploaded to the
|
|
|
|
* hardware with vc4_plane_write_dlist() at CRTC atomic_flush
|
|
|
|
* time.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist)
|
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(plane->state);
|
|
|
|
int i;
|
|
|
|
|
2015-11-30 13:34:01 -07:00
|
|
|
vc4_state->hw_dlist = dlist;
|
|
|
|
|
2015-03-02 14:01:12 -07:00
|
|
|
/* Can't memcpy_toio() because it needs to be 32-bit writes. */
|
|
|
|
for (i = 0; i < vc4_state->dlist_count; i++)
|
|
|
|
writel(vc4_state->dlist[i], &dlist[i]);
|
|
|
|
|
|
|
|
return vc4_state->dlist_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 vc4_plane_dlist_size(struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
|
|
|
|
|
|
|
|
return vc4_state->dlist_count;
|
|
|
|
}
|
|
|
|
|
2015-11-30 13:34:01 -07:00
|
|
|
/* Updates the plane to immediately (well, once the FIFO needs
|
|
|
|
* refilling) scan out from at a new framebuffer.
|
|
|
|
*/
|
|
|
|
void vc4_plane_async_set_fb(struct drm_plane *plane, struct drm_framebuffer *fb)
|
|
|
|
{
|
|
|
|
struct vc4_plane_state *vc4_state = to_vc4_plane_state(plane->state);
|
|
|
|
struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0);
|
|
|
|
uint32_t addr;
|
|
|
|
|
|
|
|
/* We're skipping the address adjustment for negative origin,
|
|
|
|
* because this is only called on the primary plane.
|
|
|
|
*/
|
|
|
|
WARN_ON_ONCE(plane->state->crtc_x < 0 || plane->state->crtc_y < 0);
|
|
|
|
addr = bo->paddr + fb->offsets[0];
|
|
|
|
|
|
|
|
/* Write the new address into the hardware immediately. The
|
|
|
|
* scanout will start from this address as soon as the FIFO
|
|
|
|
* needs to refill with pixels.
|
|
|
|
*/
|
2015-12-30 12:50:22 -07:00
|
|
|
writel(addr, &vc4_state->hw_dlist[vc4_state->ptr0_offset]);
|
2015-11-30 13:34:01 -07:00
|
|
|
|
|
|
|
/* Also update the CPU-side dlist copy, so that any later
|
|
|
|
* atomic updates that don't do a new modeset on our plane
|
|
|
|
* also use our updated address.
|
|
|
|
*/
|
2015-12-30 12:50:22 -07:00
|
|
|
vc4_state->dlist[vc4_state->ptr0_offset] = addr;
|
2015-11-30 13:34:01 -07:00
|
|
|
}
|
|
|
|
|
2015-03-02 14:01:12 -07:00
|
|
|
static const struct drm_plane_helper_funcs vc4_plane_helper_funcs = {
|
|
|
|
.prepare_fb = NULL,
|
|
|
|
.cleanup_fb = NULL,
|
|
|
|
.atomic_check = vc4_plane_atomic_check,
|
|
|
|
.atomic_update = vc4_plane_atomic_update,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void vc4_plane_destroy(struct drm_plane *plane)
|
|
|
|
{
|
|
|
|
drm_plane_helper_disable(plane);
|
|
|
|
drm_plane_cleanup(plane);
|
|
|
|
}
|
|
|
|
|
2015-12-30 12:50:22 -07:00
|
|
|
/* Implements immediate (non-vblank-synced) updates of the cursor
|
|
|
|
* position, or falls back to the atomic helper otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vc4_update_plane(struct drm_plane *plane,
|
|
|
|
struct drm_crtc *crtc,
|
|
|
|
struct drm_framebuffer *fb,
|
|
|
|
int crtc_x, int crtc_y,
|
|
|
|
unsigned int crtc_w, unsigned int crtc_h,
|
|
|
|
uint32_t src_x, uint32_t src_y,
|
|
|
|
uint32_t src_w, uint32_t src_h)
|
|
|
|
{
|
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
struct vc4_plane_state *vc4_state;
|
|
|
|
|
|
|
|
if (plane != crtc->cursor)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
plane_state = plane->state;
|
|
|
|
vc4_state = to_vc4_plane_state(plane_state);
|
|
|
|
|
|
|
|
if (!plane_state)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* If we're changing the cursor contents, do that in the
|
|
|
|
* normal vblank-synced atomic path.
|
|
|
|
*/
|
|
|
|
if (fb != plane_state->fb)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* No configuring new scaling in the fast path. */
|
|
|
|
if (crtc_w != plane_state->crtc_w ||
|
|
|
|
crtc_h != plane_state->crtc_h ||
|
|
|
|
src_w != plane_state->src_w ||
|
|
|
|
src_h != plane_state->src_h) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the cursor's position on the screen. This is the
|
|
|
|
* expected change from the drm_mode_cursor_universal()
|
|
|
|
* helper.
|
|
|
|
*/
|
|
|
|
plane_state->crtc_x = crtc_x;
|
|
|
|
plane_state->crtc_y = crtc_y;
|
|
|
|
|
|
|
|
/* Allow changing the start position within the cursor BO, if
|
|
|
|
* that matters.
|
|
|
|
*/
|
|
|
|
plane_state->src_x = src_x;
|
|
|
|
plane_state->src_y = src_y;
|
|
|
|
|
|
|
|
/* Update the display list based on the new crtc_x/y. */
|
|
|
|
vc4_plane_atomic_check(plane, plane_state);
|
|
|
|
|
|
|
|
/* Note that we can't just call vc4_plane_write_dlist()
|
|
|
|
* because that would smash the context data that the HVS is
|
|
|
|
* currently using.
|
|
|
|
*/
|
|
|
|
writel(vc4_state->dlist[vc4_state->pos0_offset],
|
|
|
|
&vc4_state->hw_dlist[vc4_state->pos0_offset]);
|
|
|
|
writel(vc4_state->dlist[vc4_state->pos2_offset],
|
|
|
|
&vc4_state->hw_dlist[vc4_state->pos2_offset]);
|
|
|
|
writel(vc4_state->dlist[vc4_state->ptr0_offset],
|
|
|
|
&vc4_state->hw_dlist[vc4_state->ptr0_offset]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return drm_atomic_helper_update_plane(plane, crtc, fb,
|
|
|
|
crtc_x, crtc_y,
|
|
|
|
crtc_w, crtc_h,
|
|
|
|
src_x, src_y,
|
|
|
|
src_w, src_h);
|
|
|
|
}
|
|
|
|
|
2015-03-02 14:01:12 -07:00
|
|
|
static const struct drm_plane_funcs vc4_plane_funcs = {
|
2015-12-30 12:50:22 -07:00
|
|
|
.update_plane = vc4_update_plane,
|
2015-03-02 14:01:12 -07:00
|
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
|
|
.destroy = vc4_plane_destroy,
|
|
|
|
.set_property = NULL,
|
|
|
|
.reset = vc4_plane_reset,
|
|
|
|
.atomic_duplicate_state = vc4_plane_duplicate_state,
|
|
|
|
.atomic_destroy_state = vc4_plane_destroy_state,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct drm_plane *vc4_plane_init(struct drm_device *dev,
|
|
|
|
enum drm_plane_type type)
|
|
|
|
{
|
|
|
|
struct drm_plane *plane = NULL;
|
|
|
|
struct vc4_plane *vc4_plane;
|
|
|
|
u32 formats[ARRAY_SIZE(hvs_formats)];
|
|
|
|
int ret = 0;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
vc4_plane = devm_kzalloc(dev->dev, sizeof(*vc4_plane),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!vc4_plane) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(hvs_formats); i++)
|
|
|
|
formats[i] = hvs_formats[i].drm;
|
|
|
|
plane = &vc4_plane->base;
|
|
|
|
ret = drm_universal_plane_init(dev, plane, 0xff,
|
|
|
|
&vc4_plane_funcs,
|
|
|
|
formats, ARRAY_SIZE(formats),
|
drm: Pass 'name' to drm_universal_plane_init()
Done with coccinelle for the most part. It choked on
msm/mdp/mdp5/mdp5_plane.c like so:
"BAD:!!!!! enum drm_plane_type type;"
No idea how to deal with that, so I just fixed that up
by hand.
Also it thinks '...' is part of the semantic patch, so I put an
'int DOTDOTDOT' placeholder in its place and got rid of it with
sed afterwards.
I didn't convert drm_plane_init() since passing the varargs through
would mean either cpp macros or va_list, and I figured we don't
care about these legacy functions enough to warrant the extra pain.
@@
typedef uint32_t;
identifier dev, plane, possible_crtcs, funcs, formats, format_count, type;
@@
int drm_universal_plane_init(struct drm_device *dev,
struct drm_plane *plane,
unsigned long possible_crtcs,
const struct drm_plane_funcs *funcs,
const uint32_t *formats,
unsigned int format_count,
enum drm_plane_type type
+ ,const char *name, int DOTDOTDOT
)
{ ... }
@@
identifier dev, plane, possible_crtcs, funcs, formats, format_count, type;
@@
int drm_universal_plane_init(struct drm_device *dev,
struct drm_plane *plane,
unsigned long possible_crtcs,
const struct drm_plane_funcs *funcs,
const uint32_t *formats,
unsigned int format_count,
enum drm_plane_type type
+ ,const char *name, int DOTDOTDOT
);
@@
expression E1, E2, E3, E4, E5, E6, E7;
@@
drm_universal_plane_init(E1, E2, E3, E4, E5, E6, E7
+ ,NULL
)
v2: Split crtc and plane changes apart
Pass NUL for no-name instead of ""
Leave drm_plane_init() alone
v3: Add ', or NULL...' to @name kernel doc (Jani)
Annotate the function with __printf() attribute (Jani)
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1449670795-2853-1-git-send-email-ville.syrjala@linux.intel.com
2015-12-09 07:19:55 -07:00
|
|
|
type, NULL);
|
2015-03-02 14:01:12 -07:00
|
|
|
|
|
|
|
drm_plane_helper_add(plane, &vc4_plane_helper_funcs);
|
|
|
|
|
|
|
|
return plane;
|
|
|
|
fail:
|
|
|
|
if (plane)
|
|
|
|
vc4_plane_destroy(plane);
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|