dcn10_mpc.c 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright 2012-15 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

#include "reg_helper.h"
#include "dcn10_mpc.h"
28
#include "dc.h"
29
#include "mem_input.h"
30 31

#define REG(reg)\
32
	mpc10->mpc_regs->reg
33 34

#define CTX \
35
	mpc10->base.ctx
36 37 38

#undef FN
#define FN(reg_name, field_name) \
39
	mpc10->mpc_shift->field_name, mpc10->mpc_mask->field_name
40

41 42
#define MODE_TOP_ONLY 1
#define MODE_BLEND 3
43 44
#define BLND_PP_ALPHA 0
#define BLND_GLOBAL_ALPHA 2
45

46

47 48 49 50
static void mpc10_set_bg_color(
		struct dcn10_mpc *mpc10,
		struct tg_color *bg_color,
		int id)
51 52 53 54 55 56 57 58 59
{
	/* mpc color is 12 bit.  tg_color is 10 bit */
	/* todo: might want to use 16 bit to represent color and have each
	 * hw block translate to correct color depth.
	 */
	uint32_t bg_r_cr = bg_color->color_r_cr << 2;
	uint32_t bg_g_y = bg_color->color_g_y << 2;
	uint32_t bg_b_cb = bg_color->color_b_cb << 2;

60
	REG_SET(MPCC_BG_R_CR[id], 0,
61
			MPCC_BG_R_CR, bg_r_cr);
62
	REG_SET(MPCC_BG_G_Y[id], 0,
63
			MPCC_BG_G_Y, bg_g_y);
64
	REG_SET(MPCC_BG_B_CB[id], 0,
65 66 67
			MPCC_BG_B_CB, bg_b_cb);
}

68
static void mpc10_assert_idle_mpcc(struct mpc *mpc, int id)
69
{
70 71 72 73
	struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);

	ASSERT(!(mpc10->mpcc_in_use_mask & 1 << id));
	REG_WAIT(MPCC_STATUS[id],
74
			MPCC_IDLE, 1,
75
			1000, 1000);
76 77
}

78
static int mpc10_get_idle_mpcc_id(struct dcn10_mpc *mpc10)
79
{
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
	int i;
	int last_free_mpcc_id = -1;

	for (i = 0; i < mpc10->num_mpcc; i++) {
		uint32_t is_idle = 0;

		if (mpc10->mpcc_in_use_mask & 1 << i)
			continue;

		last_free_mpcc_id = i;
		REG_GET(MPCC_STATUS[i], MPCC_IDLE, &is_idle);
		if (is_idle)
			return i;
	}

	/* This assert should never trigger, we have mpcc leak if it does */
	ASSERT(last_free_mpcc_id != -1);

	mpc10_assert_idle_mpcc(&mpc10->base, last_free_mpcc_id);
	return last_free_mpcc_id;
100 101
}

102
static void mpc10_assert_mpcc_idle_before_connect(struct dcn10_mpc *mpc10, int id)
103
{
104
	unsigned int top_sel, mpc_busy, mpc_idle;
105

106
	REG_GET(MPCC_TOP_SEL[id],
107 108 109
			MPCC_TOP_SEL, &top_sel);

	if (top_sel == 0xf) {
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
		REG_GET_2(MPCC_STATUS[id],
				MPCC_BUSY, &mpc_busy,
				MPCC_IDLE, &mpc_idle);

		ASSERT(mpc_busy == 0);
		ASSERT(mpc_idle == 1);
	}
}

static void mpc10_mpcc_remove(
		struct mpc *mpc,
		struct output_pixel_processor *opp,
		int dpp_id)
{
	struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
	int mpcc_id, z_idx;

	for (z_idx = 0; z_idx < opp->mpc_tree.num_pipes; z_idx++)
		if (opp->mpc_tree.dpp[z_idx] == dpp_id)
			break;
	if (z_idx == opp->mpc_tree.num_pipes) {
		ASSERT(0);
		return;
	}
	mpcc_id = opp->mpc_tree.mpcc[z_idx];

	REG_SET(MPCC_OPP_ID[mpcc_id], 0,
			MPCC_OPP_ID, 0xf);
	REG_SET(MPCC_TOP_SEL[mpcc_id], 0,
			MPCC_TOP_SEL, 0xf);
	REG_SET(MPCC_BOT_SEL[mpcc_id], 0,
			MPCC_BOT_SEL, 0xf);
142

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	if (z_idx > 0) {
		int top_mpcc_id = opp->mpc_tree.mpcc[z_idx - 1];

		if (z_idx + 1 < opp->mpc_tree.num_pipes)
			REG_SET(MPCC_BOT_SEL[top_mpcc_id], 0,
					MPCC_BOT_SEL, opp->mpc_tree.mpcc[z_idx + 1]);
		else {
			REG_SET(MPCC_BOT_SEL[top_mpcc_id], 0,
					MPCC_BOT_SEL, 0xf);
			REG_UPDATE(MPCC_CONTROL[top_mpcc_id],
					MPCC_MODE, MODE_TOP_ONLY);
		}
	} else if (opp->mpc_tree.num_pipes > 1)
		REG_SET(MUX[opp->inst], 0,
				MPC_OUT_MUX, opp->mpc_tree.mpcc[z_idx + 1]);
	else
		REG_SET(MUX[opp->inst], 0, MPC_OUT_MUX, 0xf);

	mpc10->mpcc_in_use_mask &= ~(1 << mpcc_id);
	opp->mpc_tree.num_pipes--;
	for (; z_idx < opp->mpc_tree.num_pipes; z_idx++) {
		opp->mpc_tree.dpp[z_idx] = opp->mpc_tree.dpp[z_idx + 1];
		opp->mpc_tree.mpcc[z_idx] = opp->mpc_tree.mpcc[z_idx + 1];
166
	}
167 168
	opp->mpc_tree.dpp[opp->mpc_tree.num_pipes] = 0xdeadbeef;
	opp->mpc_tree.mpcc[opp->mpc_tree.num_pipes] = 0xdeadbeef;
169 170
}

171
static void mpc10_mpcc_add(struct mpc *mpc, struct mpcc_cfg *cfg)
172
{
173
	struct dcn10_mpc *mpc10 = TO_DCN10_MPC(mpc);
174 175
	int alpha_blnd_mode = cfg->per_pixel_alpha ?
			BLND_PP_ALPHA : BLND_GLOBAL_ALPHA;
176 177 178 179
	int mpcc_mode = MODE_TOP_ONLY;
	int mpcc_id, z_idx;

	ASSERT(cfg->z_index < mpc10->num_mpcc);
180

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
	for (z_idx = 0; z_idx < cfg->opp->mpc_tree.num_pipes; z_idx++)
		if (cfg->opp->mpc_tree.dpp[z_idx] == cfg->mi->inst)
			break;
	if (z_idx == cfg->opp->mpc_tree.num_pipes) {
		ASSERT(cfg->z_index <= cfg->opp->mpc_tree.num_pipes);
		mpcc_id = mpc10_get_idle_mpcc_id(mpc10);
		/*todo: remove hack*/
		mpcc_id = cfg->mi->inst;
		ASSERT(!(mpc10->mpcc_in_use_mask & 1 << mpcc_id));

		if (mpc->ctx->dc->debug.sanity_checks)
			mpc10_assert_mpcc_idle_before_connect(mpc10, mpcc_id);
	} else {
		ASSERT(cfg->z_index < cfg->opp->mpc_tree.num_pipes);
		mpcc_id = cfg->opp->mpc_tree.mpcc[z_idx];
		mpc10_mpcc_remove(mpc, cfg->opp, cfg->mi->inst);
	}
198

199 200
	REG_SET(MPCC_OPP_ID[mpcc_id], 0,
			MPCC_OPP_ID, cfg->opp->inst);
201

202 203
	REG_SET(MPCC_TOP_SEL[mpcc_id], 0,
			MPCC_TOP_SEL, cfg->mi->inst);
204

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
	if (cfg->z_index > 0) {
		int top_mpcc_id = cfg->opp->mpc_tree.mpcc[cfg->z_index - 1];

		REG_SET(MPCC_BOT_SEL[top_mpcc_id], 0,
				MPCC_BOT_SEL, mpcc_id);
		REG_UPDATE(MPCC_CONTROL[top_mpcc_id],
				MPCC_MODE, MODE_BLEND);
	} else
		REG_SET(MUX[cfg->opp->inst], 0, MPC_OUT_MUX, mpcc_id);

	if (cfg->z_index < cfg->opp->mpc_tree.num_pipes) {
		int bot_mpcc_id = cfg->opp->mpc_tree.mpcc[cfg->z_index];

		REG_SET(MPCC_BOT_SEL[mpcc_id], 0,
				MPCC_BOT_SEL, bot_mpcc_id);
		mpcc_mode = MODE_BLEND;
	}
222

223
	REG_SET_4(MPCC_CONTROL[mpcc_id], 0xffffffff,
224 225
		MPCC_MODE, mpcc_mode,
		MPCC_ALPHA_BLND_MODE, alpha_blnd_mode,
226
		MPCC_ALPHA_MULTIPLIED_MODE, cfg->pre_multiplied_alpha,
227
		MPCC_BLND_ACTIVE_OVERLAP_ONLY, false);
228

229
	mpc10_set_bg_color(mpc10, &cfg->black_color, mpcc_id);
230

231 232 233 234 235 236 237 238 239 240
	mpc10->mpcc_in_use_mask |= 1 << mpcc_id;
	for (z_idx = cfg->z_index; z_idx < cfg->opp->mpc_tree.num_pipes; z_idx++) {
		cfg->opp->mpc_tree.dpp[z_idx + 1] = cfg->opp->mpc_tree.dpp[z_idx];
		cfg->opp->mpc_tree.mpcc[z_idx + 1] = cfg->opp->mpc_tree.mpcc[z_idx];
	}
	cfg->opp->mpc_tree.dpp[cfg->z_index] = cfg->mi->inst;
	cfg->opp->mpc_tree.mpcc[cfg->z_index] = mpcc_id;
	cfg->opp->mpc_tree.num_pipes++;
	cfg->mi->opp_id = cfg->opp->inst;
	cfg->mi->mpcc_id = mpcc_id;
241
}
242

243 244 245 246
const struct mpc_funcs dcn10_mpc_funcs = {
		.add = mpc10_mpcc_add,
		.remove = mpc10_mpcc_remove,
		.wait_for_idle = mpc10_assert_idle_mpcc
247
};
248

249
void dcn10_mpc_construct(struct dcn10_mpc *mpc10,
250
	struct dc_context *ctx,
251 252 253 254
	const struct dcn_mpc_registers *mpc_regs,
	const struct dcn_mpc_shift *mpc_shift,
	const struct dcn_mpc_mask *mpc_mask,
	int num_mpcc)
255
{
256
	mpc10->base.ctx = ctx;
257

258
	mpc10->base.funcs = &dcn10_mpc_funcs;
259

260 261 262
	mpc10->mpc_regs = mpc_regs;
	mpc10->mpc_shift = mpc_shift;
	mpc10->mpc_mask = mpc_mask;
263

264 265
	mpc10->mpcc_in_use_mask = 0;
	mpc10->num_mpcc = num_mpcc;
266
}