dc_stream.h 13.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 28 29 30 31 32 33 34
/*
 * Copyright 2012-14 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
 *
 */

#ifndef DC_STREAM_H_
#define DC_STREAM_H_

#include "dc_types.h"
#include "grph_object_defs.h"

/*******************************************************************************
 * Stream Interfaces
 ******************************************************************************/
35 36 37 38 39
struct timing_sync_info {
	int group_id;
	int group_size;
	bool master;
};
40 41 42 43 44

struct dc_stream_status {
	int primary_otg_inst;
	int stream_enc_inst;
	int plane_count;
45
	int audio_inst;
46
	struct timing_sync_info timing_sync_info;
47 48 49
	struct dc_plane_state *plane_states[MAX_SURFACE_NUM];
};

50 51 52 53 54
// TODO: References to this needs to be removed..
struct freesync_context {
	bool dummy;
};

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
enum hubp_dmdata_mode {
	DMDATA_SW_MODE,
	DMDATA_HW_MODE
};

struct dc_dmdata_attributes {
	/* Specifies whether dynamic meta data will be updated by software
	 * or has to be fetched by hardware (DMA mode)
	 */
	enum hubp_dmdata_mode dmdata_mode;
	/* Specifies if current dynamic meta data is to be used only for the current frame */
	bool dmdata_repeat;
	/* Specifies the size of Dynamic Metadata surface in byte.  Size of 0 means no Dynamic metadata is fetched */
	uint32_t dmdata_size;
	/* Specifies if a new dynamic meta data should be fetched for an upcoming frame */
	bool dmdata_updated;
	/* If hardware mode is used, the base address where DMDATA surface is located */
	PHYSICAL_ADDRESS_LOC address;
	/* Specifies whether QOS level will be provided by TTU or it will come from DMDATA_QOS_LEVEL */
	bool dmdata_qos_mode;
	/* If qos_mode = 1, this is the QOS value to be used: */
	uint32_t dmdata_qos_level;
	/* Specifies the value in unit of REFCLK cycles to be added to the
	 * current time to produce the Amortized deadline for Dynamic Metadata chunk request
	 */
	uint32_t dmdata_dl_delta;
	/* An unbounded array of uint32s, represents software dmdata to be loaded */
	uint32_t *dmdata_sw_data;
};

struct dc_writeback_info {
	bool wb_enabled;
	int dwb_pipe_inst;
	struct dc_dwb_params dwb_params;
	struct mcif_buf_params mcif_buf_params;
};

struct dc_writeback_update {
	unsigned int num_wb_info;
	struct dc_writeback_info writeback_info[MAX_DWB_PIPES];
};

97 98 99 100 101 102 103 104 105 106 107 108 109
enum vertical_interrupt_ref_point {
	START_V_UPDATE = 0,
	START_V_SYNC,
	INVALID_POINT

	//For now, only v_update interrupt is used.
	//START_V_BLANK,
	//START_V_ACTIVE
};

struct periodic_interrupt_config {
	enum vertical_interrupt_ref_point ref_point;
	int lines_offset;
110 111
};

112 113 114 115 116 117 118 119 120 121 122 123 124
union stream_update_flags {
	struct {
		uint32_t scaling:1;
		uint32_t out_tf:1;
		uint32_t out_csc:1;
		uint32_t abm_level:1;
		uint32_t dpms_off:1;
		uint32_t gamut_remap:1;
		uint32_t wb_update:1;
	} bits;

	uint32_t raw;
};
125

126
struct dc_stream_state {
127 128
	// sink is deprecated, new code should not reference
	// this pointer
129
	struct dc_sink *sink;
130 131 132 133

	struct dc_link *link;
	struct dc_panel_patch sink_patches;
	union display_content_support content_support;
134
	struct dc_crtc_timing timing;
135 136
	struct dc_crtc_timing_adjust adjust;
	struct dc_info_packet vrr_infopacket;
137
	struct dc_info_packet vsc_infopacket;
138
	struct dc_info_packet vsp_infopacket;
139 140 141 142

	struct rect src; /* composition area */
	struct rect dst; /* stream addressable area */

143
	// TODO: References to this needs to be removed..
144 145
	struct freesync_context freesync_ctx;

146 147
	struct audio_info audio_info;

148
	struct dc_info_packet hdr_static_metadata;
149
	PHYSICAL_ADDRESS_LOC dmdata_address;
150
	bool   use_dynamic_meta;
151

152 153
	struct dc_transfer_func *out_transfer_func;
	struct colorspace_transform gamut_remap_matrix;
154
	struct dc_csc_transform csc_color_matrix;
155 156 157 158 159 160

	enum dc_color_space output_color_space;
	enum dc_dither_option dither_option;

	enum view_3d_format view_format;

161
	bool use_vsc_sdp_for_colorimetry;
162
	bool ignore_msa_timing_param;
163 164 165
	bool converter_disable_audio;
	uint8_t qs_bit;
	uint8_t qy_bit;
166

167 168
	/* TODO: custom INFO packets */
	/* TODO: ABM info (DMCU) */
169 170
	/* PSR info */
	unsigned char psr_version;
171 172
	/* TODO: CEA VIC */

173
	/* DMCU info */
174
	unsigned int abm_level;
175

176 177
	struct periodic_interrupt_config periodic_interrupt0;
	struct periodic_interrupt_config periodic_interrupt1;
178

179 180 181 182 183 184 185 186 187 188 189
	/* from core_stream struct */
	struct dc_context *ctx;

	/* used by DCP and FMT */
	struct bit_depth_reduction_params bit_depth_params;
	struct clamping_and_pixel_encoding_params clamping;

	int phy_pix_clk;
	enum signal_type signal;
	bool dpms_off;

190 191
	void *dm_stream_context;

192
	struct dc_cursor_attributes cursor_attributes;
193
	struct dc_cursor_position cursor_position;
194
	uint32_t sdr_white_level; // for boosting (SDR) cursor in HDR mode
195 196 197 198 199 200

	/* from stream struct */
	struct kref refcount;

	struct crtc_trigger_info triggered_crtc_reset;

201 202 203
	/* writeback */
	unsigned int num_wb_info;
	struct dc_writeback_info writeback_info[MAX_DWB_PIPES];
204 205 206
	/* Computed state bits */
	bool mode_changed : 1;

207 208 209 210 211 212 213 214 215 216 217
	/* Output from DC when stream state is committed or altered
	 * DC may only access these values during:
	 * dc_commit_state, dc_commit_state_no_check, dc_commit_streams
	 * values may not change outside of those calls
	 */
	struct {
		// For interrupt management, some hardware instance
		// offsets need to be exposed to DM
		uint8_t otg_offset;
	} out;

218 219 220
	bool apply_edp_fast_boot_optimization;
	bool apply_seamless_boot_optimization;

221
	uint32_t stream_id;
222
	bool is_dsc_enabled;
223
	union stream_update_flags update_flags;
224 225
};

226 227
#define ABM_LEVEL_IMMEDIATE_DISABLE 0xFFFFFFFF

228
struct dc_stream_update {
229 230
	struct dc_stream_state *stream;

231 232 233
	struct rect src;
	struct rect dst;
	struct dc_transfer_func *out_transfer_func;
234
	struct dc_info_packet *hdr_static_metadata;
235
	unsigned int *abm_level;
236

237 238
	struct periodic_interrupt_config *periodic_interrupt0;
	struct periodic_interrupt_config *periodic_interrupt1;
239

240
	struct dc_info_packet *vrr_infopacket;
241
	struct dc_info_packet *vsc_infopacket;
242
	struct dc_info_packet *vsp_infopacket;
243 244

	bool *dpms_off;
245
	bool integer_scaling_update;
246 247 248

	struct colorspace_transform *gamut_remap;
	enum dc_color_space *output_color_space;
249
	enum dc_dither_option *dither_option;
250

251
	struct dc_csc_transform *output_csc_transform;
252

253
	struct dc_writeback_update *wb_update;
254
	struct dc_dsc_config *dsc_config;
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
};

bool dc_is_stream_unchanged(
	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
bool dc_is_stream_scaling_unchanged(
	struct dc_stream_state *old_stream, struct dc_stream_state *stream);

/*
 * Set up surface attributes and associate to a stream
 * The surfaces parameter is an absolute set of all surface active for the stream.
 * If no surfaces are provided, the stream will be blanked; no memory read.
 * Any flip related attribute changes must be done through this interface.
 *
 * After this call:
 *   Surfaces attributes are programmed and configured to be composed into stream.
 *   This does not trigger a flip.  No surface address is programmed.
 */

void dc_commit_updates_for_stream(struct dc *dc,
		struct dc_surface_update *srf_updates,
		int surface_count,
		struct dc_stream_state *stream,
		struct dc_stream_update *stream_update,
		struct dc_state *state);
/*
 * Log the current stream state.
 */
282
void dc_stream_log(const struct dc *dc, const struct dc_stream_state *stream);
283 284 285 286 287 288 289 290 291

uint8_t dc_get_current_stream_count(struct dc *dc);
struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i);

/*
 * Return the current frame counter.
 */
uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream);

292 293 294 295 296 297 298
/*
 * Send dp sdp message.
 */
bool dc_stream_send_dp_sdp(const struct dc_stream_state *stream,
		const uint8_t *custom_sdp_message,
		unsigned int sdp_message_size);

299
/* TODO: Return parsed values rather than direct register read
300
 * This has a dependency on the caller (amdgpu_display_get_crtc_scanoutpos)
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
 * being refactored properly to be dce-specific
 */
bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream,
				  uint32_t *v_blank_start,
				  uint32_t *v_blank_end,
				  uint32_t *h_position,
				  uint32_t *v_position);

enum dc_status dc_add_stream_to_ctx(
			struct dc *dc,
		struct dc_state *new_ctx,
		struct dc_stream_state *stream);

enum dc_status dc_remove_stream_from_ctx(
		struct dc *dc,
			struct dc_state *new_ctx,
			struct dc_stream_state *stream);


bool dc_add_plane_to_context(
		const struct dc *dc,
		struct dc_stream_state *stream,
		struct dc_plane_state *plane_state,
		struct dc_state *context);

bool dc_remove_plane_from_context(
		const struct dc *dc,
		struct dc_stream_state *stream,
		struct dc_plane_state *plane_state,
		struct dc_state *context);

bool dc_rem_all_planes_for_stream(
		const struct dc *dc,
		struct dc_stream_state *stream,
		struct dc_state *context);

bool dc_add_all_planes_for_stream(
		const struct dc *dc,
		struct dc_stream_state *stream,
		struct dc_plane_state * const *plane_states,
		int plane_count,
		struct dc_state *context);

344 345 346
bool dc_stream_add_writeback(struct dc *dc,
		struct dc_stream_state *stream,
		struct dc_writeback_info *wb_info);
347

348 349 350
bool dc_stream_remove_writeback(struct dc *dc,
		struct dc_stream_state *stream,
		uint32_t dwb_pipe_inst);
351 352 353 354 355

bool dc_stream_warmup_writeback(struct dc *dc,
		int num_dwb,
		struct dc_writeback_info *wb_info);

356
bool dc_stream_dmdata_status_done(struct dc *dc, struct dc_stream_state *stream);
357

358 359 360 361
bool dc_stream_set_dynamic_metadata(struct dc *dc,
		struct dc_stream_state *stream,
		struct dc_dmdata_attributes *dmdata_attr);

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
enum dc_status dc_validate_stream(struct dc *dc, struct dc_stream_state *stream);

/*
 * Set up streams and links associated to drive sinks
 * The streams parameter is an absolute set of all active streams.
 *
 * After this call:
 *   Phy, Encoder, Timing Generator are programmed and enabled.
 *   New streams are enabled with blank stream; no memory read.
 */
/*
 * Enable stereo when commit_streams is not required,
 * for example, frame alternate.
 */
bool dc_enable_stereo(
	struct dc *dc,
	struct dc_state *context,
	struct dc_stream_state *streams[],
	uint8_t stream_count);


enum surface_update_type dc_check_update_surfaces_for_stream(
		struct dc *dc,
		struct dc_surface_update *updates,
		int surface_count,
		struct dc_stream_update *stream_update,
		const struct dc_stream_status *stream_status);

/**
 * Create a new default stream for the requested sink
 */
struct dc_stream_state *dc_create_stream_for_sink(struct dc_sink *dc_sink);

395 396
struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream);

397
void update_stream_signal(struct dc_stream_state *stream, struct dc_sink *sink);
398

399 400 401
void dc_stream_retain(struct dc_stream_state *dc_stream);
void dc_stream_release(struct dc_stream_state *dc_stream);

402 403 404
struct dc_stream_status *dc_stream_get_status_from_state(
	struct dc_state *state,
	struct dc_stream_state *stream);
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
struct dc_stream_status *dc_stream_get_status(
	struct dc_stream_state *dc_stream);

/*******************************************************************************
 * Cursor interfaces - To manages the cursor within a stream
 ******************************************************************************/
/* TODO: Deprecated once we switch to dc_set_cursor_position */
bool dc_stream_set_cursor_attributes(
	struct dc_stream_state *stream,
	const struct dc_cursor_attributes *attributes);

bool dc_stream_set_cursor_position(
	struct dc_stream_state *stream,
	const struct dc_cursor_position *position);

420

421
bool dc_stream_adjust_vmin_vmax(struct dc *dc,
422 423
				struct dc_stream_state *stream,
				struct dc_crtc_timing_adjust *adjust);
424 425 426 427 428 429 430

bool dc_stream_get_crtc_position(struct dc *dc,
				 struct dc_stream_state **stream,
				 int num_streams,
				 unsigned int *v_pos,
				 unsigned int *nom_v_pos);

431 432 433 434 435 436 437 438 439 440 441
bool dc_stream_configure_crc(struct dc *dc,
			     struct dc_stream_state *stream,
			     bool enable,
			     bool continuous);

bool dc_stream_get_crc(struct dc *dc,
		       struct dc_stream_state *stream,
		       uint32_t *r_cr,
		       uint32_t *g_y,
		       uint32_t *b_cb);

442 443 444 445 446
void dc_stream_set_static_screen_events(struct dc *dc,
					struct dc_stream_state **stream,
					int num_streams,
					const struct dc_static_screen_events *events);

447 448 449
void dc_stream_set_dyn_expansion(struct dc *dc, struct dc_stream_state *stream,
		enum dc_dynamic_expansion option);

450 451 452
void dc_stream_set_dither_option(struct dc_stream_state *stream,
				 enum dc_dither_option option);

453 454 455
bool dc_stream_set_gamut_remap(struct dc *dc,
			       const struct dc_stream_state *stream);

456 457 458
bool dc_stream_program_csc_matrix(struct dc *dc,
				  struct dc_stream_state *stream);

459 460 461 462 463 464 465
bool dc_stream_get_crtc_position(struct dc *dc,
				 struct dc_stream_state **stream,
				 int num_streams,
				 unsigned int *v_pos,
				 unsigned int *nom_v_pos);

#endif /* DC_STREAM_H_ */