cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

dc_link.h (16291B)


      1/*
      2 * Copyright 2012-14 Advanced Micro Devices, Inc.
      3 *
      4 * Permission is hereby granted, free of charge, to any person obtaining a
      5 * copy of this software and associated documentation files (the "Software"),
      6 * to deal in the Software without restriction, including without limitation
      7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8 * and/or sell copies of the Software, and to permit persons to whom the
      9 * Software is furnished to do so, subject to the following conditions:
     10 *
     11 * The above copyright notice and this permission notice shall be included in
     12 * all copies or substantial portions of the Software.
     13 *
     14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     20 * OTHER DEALINGS IN THE SOFTWARE.
     21 *
     22 * Authors: AMD
     23 *
     24 */
     25
     26#ifndef DC_LINK_H_
     27#define DC_LINK_H_
     28
     29#include "dc.h"
     30#include "dc_types.h"
     31#include "grph_object_defs.h"
     32
     33struct link_resource;
     34
     35enum dc_link_fec_state {
     36	dc_link_fec_not_ready,
     37	dc_link_fec_ready,
     38	dc_link_fec_enabled
     39};
     40
     41struct dc_link_status {
     42	bool link_active;
     43	struct dpcd_caps *dpcd_caps;
     44};
     45
     46struct dprx_states {
     47	bool cable_id_written;
     48};
     49
     50/* DP MST stream allocation (payload bandwidth number) */
     51struct link_mst_stream_allocation {
     52	/* DIG front */
     53	const struct stream_encoder *stream_enc;
     54	/* HPO DP Stream Encoder */
     55	const struct hpo_dp_stream_encoder *hpo_dp_stream_enc;
     56	/* associate DRM payload table with DC stream encoder */
     57	uint8_t vcp_id;
     58	/* number of slots required for the DP stream in transport packet */
     59	uint8_t slot_count;
     60};
     61
     62/* DP MST stream allocation table */
     63struct link_mst_stream_allocation_table {
     64	/* number of DP video streams */
     65	int stream_count;
     66	/* array of stream allocations */
     67	struct link_mst_stream_allocation stream_allocations[MAX_CONTROLLER_NUM];
     68};
     69
     70struct edp_trace_power_timestamps {
     71	uint64_t poweroff;
     72	uint64_t poweron;
     73};
     74
     75struct dp_trace_lt_counts {
     76	unsigned int total;
     77	unsigned int fail;
     78};
     79
     80struct dp_trace_lt {
     81	struct dp_trace_lt_counts counts;
     82	struct dp_trace_timestamps {
     83		unsigned long long start;
     84		unsigned long long end;
     85	} timestamps;
     86	enum link_training_result result;
     87	bool is_logged;
     88};
     89
     90struct dp_trace {
     91	struct dp_trace_lt detect_lt_trace;
     92	struct dp_trace_lt commit_lt_trace;
     93	unsigned int link_loss_count;
     94	bool is_initialized;
     95	struct edp_trace_power_timestamps edp_trace_power_timestamps;
     96};
     97
     98/* PSR feature flags */
     99struct psr_settings {
    100	bool psr_feature_enabled;		// PSR is supported by sink
    101	bool psr_allow_active;			// PSR is currently active
    102	enum dc_psr_version psr_version;		// Internal PSR version, determined based on DPCD
    103
    104	/* These parameters are calculated in Driver,
    105	 * based on display timing and Sink capabilities.
    106	 * If VBLANK region is too small and Sink takes a long time
    107	 * to set up RFB, it may take an extra frame to enter PSR state.
    108	 */
    109	bool psr_frame_capture_indication_req;
    110	unsigned int psr_sdp_transmit_line_num_deadline;
    111	unsigned int psr_power_opt;
    112};
    113
    114/*
    115 * A link contains one or more sinks and their connected status.
    116 * The currently active signal type (HDMI, DP-SST, DP-MST) is also reported.
    117 */
    118struct dc_link {
    119	struct dc_sink *remote_sinks[MAX_SINKS_PER_LINK];
    120	unsigned int sink_count;
    121	struct dc_sink *local_sink;
    122	unsigned int link_index;
    123	enum dc_connection_type type;
    124	enum signal_type connector_signal;
    125	enum dc_irq_source irq_source_hpd;
    126	enum dc_irq_source irq_source_hpd_rx;/* aka DP Short Pulse  */
    127	bool is_hpd_filter_disabled;
    128	bool dp_ss_off;
    129	bool link_state_valid;
    130	bool aux_access_disabled;
    131	bool sync_lt_in_progress;
    132	enum lttpr_mode lttpr_mode;
    133	bool is_internal_display;
    134
    135	/* TODO: Rename. Flag an endpoint as having a programmable mapping to a
    136	 * DIG encoder. */
    137	bool is_dig_mapping_flexible;
    138	bool hpd_status; /* HPD status of link without physical HPD pin. */
    139	bool is_hpd_pending; /* Indicates a new received hpd */
    140
    141	bool edp_sink_present;
    142
    143	struct dp_trace dp_trace;
    144
    145	/* caps is the same as reported_link_cap. link_traing use
    146	 * reported_link_cap. Will clean up.  TODO
    147	 */
    148	struct dc_link_settings reported_link_cap;
    149	struct dc_link_settings verified_link_cap;
    150	struct dc_link_settings cur_link_settings;
    151	struct dc_lane_settings cur_lane_setting[LANE_COUNT_DP_MAX];
    152	struct dc_link_settings preferred_link_setting;
    153	/* preferred_training_settings are override values that
    154	 * come from DM. DM is responsible for the memory
    155	 * management of the override pointers.
    156	 */
    157	struct dc_link_training_overrides preferred_training_settings;
    158	struct dp_audio_test_data audio_test_data;
    159
    160	uint8_t ddc_hw_inst;
    161
    162	uint8_t hpd_src;
    163
    164	uint8_t link_enc_hw_inst;
    165	/* DIG link encoder ID. Used as index in link encoder resource pool.
    166	 * For links with fixed mapping to DIG, this is not changed after dc_link
    167	 * object creation.
    168	 */
    169	enum engine_id eng_id;
    170
    171	bool test_pattern_enabled;
    172	union compliance_test_state compliance_test_state;
    173
    174	void *priv;
    175
    176	struct ddc_service *ddc;
    177
    178	bool aux_mode;
    179
    180	/* Private to DC core */
    181
    182	const struct dc *dc;
    183
    184	struct dc_context *ctx;
    185
    186	struct panel_cntl *panel_cntl;
    187	struct link_encoder *link_enc;
    188	struct graphics_object_id link_id;
    189	/* Endpoint type distinguishes display endpoints which do not have entries
    190	 * in the BIOS connector table from those that do. Helps when tracking link
    191	 * encoder to display endpoint assignments.
    192	 */
    193	enum display_endpoint_type ep_type;
    194	union ddi_channel_mapping ddi_channel_mapping;
    195	struct connector_device_tag_info device_tag;
    196	struct dpcd_caps dpcd_caps;
    197	uint32_t dongle_max_pix_clk;
    198	unsigned short chip_caps;
    199	unsigned int dpcd_sink_count;
    200#if defined(CONFIG_DRM_AMD_DC_HDCP)
    201	struct hdcp_caps hdcp_caps;
    202#endif
    203	enum edp_revision edp_revision;
    204	union dpcd_sink_ext_caps dpcd_sink_ext_caps;
    205
    206	struct psr_settings psr_settings;
    207
    208	/* Drive settings read from integrated info table */
    209	struct dc_lane_settings bios_forced_drive_settings;
    210
    211	/* Vendor specific LTTPR workaround variables */
    212	uint8_t vendor_specific_lttpr_link_rate_wa;
    213	bool apply_vendor_specific_lttpr_link_rate_wa;
    214
    215	/* MST record stream using this link */
    216	struct link_flags {
    217		bool dp_keep_receiver_powered;
    218		bool dp_skip_DID2;
    219		bool dp_skip_reset_segment;
    220		bool dp_mot_reset_segment;
    221		/* Some USB4 docks do not handle turning off MST DSC once it has been enabled. */
    222		bool dpia_mst_dsc_always_on;
    223		/* Forced DPIA into TBT3 compatibility mode. */
    224		bool dpia_forced_tbt3_mode;
    225	} wa_flags;
    226	struct link_mst_stream_allocation_table mst_stream_alloc_table;
    227
    228	struct dc_link_status link_status;
    229	struct dprx_states dprx_states;
    230
    231	struct gpio *hpd_gpio;
    232	enum dc_link_fec_state fec_state;
    233};
    234
    235const struct dc_link_status *dc_link_get_status(const struct dc_link *dc_link);
    236
    237/**
    238 * dc_get_link_at_index() - Return an enumerated dc_link.
    239 *
    240 * dc_link order is constant and determined at
    241 * boot time.  They cannot be created or destroyed.
    242 * Use dc_get_caps() to get number of links.
    243 */
    244static inline struct dc_link *dc_get_link_at_index(struct dc *dc, uint32_t link_index)
    245{
    246	return dc->links[link_index];
    247}
    248
    249static inline void get_edp_links(const struct dc *dc,
    250		struct dc_link **edp_links,
    251		int *edp_num)
    252{
    253	int i;
    254
    255	*edp_num = 0;
    256	for (i = 0; i < dc->link_count; i++) {
    257		// report any eDP links, even unconnected DDI's
    258		if (!dc->links[i])
    259			continue;
    260		if (dc->links[i]->connector_signal == SIGNAL_TYPE_EDP) {
    261			edp_links[*edp_num] = dc->links[i];
    262			if (++(*edp_num) == MAX_NUM_EDP)
    263				return;
    264		}
    265	}
    266}
    267
    268static inline bool dc_get_edp_link_panel_inst(const struct dc *dc,
    269		const struct dc_link *link,
    270		unsigned int *inst_out)
    271{
    272	struct dc_link *edp_links[MAX_NUM_EDP];
    273	int edp_num;
    274
    275	if (link->connector_signal != SIGNAL_TYPE_EDP)
    276		return false;
    277	get_edp_links(dc, edp_links, &edp_num);
    278	if ((edp_num > 1) && (link->link_index > edp_links[0]->link_index))
    279		*inst_out = 1;
    280	else
    281		*inst_out = 0;
    282	return true;
    283}
    284
    285/* Set backlight level of an embedded panel (eDP, LVDS).
    286 * backlight_pwm_u16_16 is unsigned 32 bit with 16 bit integer
    287 * and 16 bit fractional, where 1.0 is max backlight value.
    288 */
    289bool dc_link_set_backlight_level(const struct dc_link *dc_link,
    290		uint32_t backlight_pwm_u16_16,
    291		uint32_t frame_ramp);
    292
    293/* Set/get nits-based backlight level of an embedded panel (eDP, LVDS). */
    294bool dc_link_set_backlight_level_nits(struct dc_link *link,
    295		bool isHDR,
    296		uint32_t backlight_millinits,
    297		uint32_t transition_time_in_ms);
    298
    299bool dc_link_get_backlight_level_nits(struct dc_link *link,
    300		uint32_t *backlight_millinits,
    301		uint32_t *backlight_millinits_peak);
    302
    303bool dc_link_backlight_enable_aux(struct dc_link *link, bool enable);
    304
    305bool dc_link_read_default_bl_aux(struct dc_link *link, uint32_t *backlight_millinits);
    306bool dc_link_set_default_brightness_aux(struct dc_link *link);
    307
    308int dc_link_get_backlight_level(const struct dc_link *dc_link);
    309
    310int dc_link_get_target_backlight_pwm(const struct dc_link *link);
    311
    312bool dc_link_set_psr_allow_active(struct dc_link *dc_link, const bool *enable,
    313		bool wait, bool force_static, const unsigned int *power_opts);
    314
    315bool dc_link_get_psr_state(const struct dc_link *dc_link, enum dc_psr_state *state);
    316
    317bool dc_link_setup_psr(struct dc_link *dc_link,
    318		const struct dc_stream_state *stream, struct psr_config *psr_config,
    319		struct psr_context *psr_context);
    320
    321void dc_link_get_psr_residency(const struct dc_link *link, uint32_t *residency);
    322
    323void dc_link_blank_all_dp_displays(struct dc *dc);
    324
    325void dc_link_blank_dp_stream(struct dc_link *link, bool hw_init);
    326
    327/* Request DC to detect if there is a Panel connected.
    328 * boot - If this call is during initial boot.
    329 * Return false for any type of detection failure or MST detection
    330 * true otherwise. True meaning further action is required (status update
    331 * and OS notification).
    332 */
    333enum dc_detect_reason {
    334	DETECT_REASON_BOOT,
    335	DETECT_REASON_RESUMEFROMS3S4,
    336	DETECT_REASON_HPD,
    337	DETECT_REASON_HPDRX,
    338	DETECT_REASON_FALLBACK,
    339	DETECT_REASON_RETRAIN,
    340};
    341
    342bool dc_link_detect(struct dc_link *dc_link, enum dc_detect_reason reason);
    343bool dc_link_get_hpd_state(struct dc_link *dc_link);
    344enum dc_status dc_link_allocate_mst_payload(struct pipe_ctx *pipe_ctx);
    345enum dc_status dc_link_reduce_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t req_pbn);
    346enum dc_status dc_link_increase_mst_payload(struct pipe_ctx *pipe_ctx, uint32_t req_pbn);
    347
    348/* Notify DC about DP RX Interrupt (aka Short Pulse Interrupt).
    349 * Return:
    350 * true - Downstream port status changed. DM should call DC to do the
    351 * detection.
    352 * false - no change in Downstream port status. No further action required
    353 * from DM. */
    354bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link,
    355		union hpd_irq_data *hpd_irq_dpcd_data, bool *out_link_loss,
    356		bool defer_handling, bool *has_left_work);
    357
    358/*
    359 * On eDP links this function call will stall until T12 has elapsed.
    360 * If the panel is not in power off state, this function will return
    361 * immediately.
    362 */
    363bool dc_link_wait_for_t12(struct dc_link *link);
    364
    365void dc_link_dp_handle_automated_test(struct dc_link *link);
    366void dc_link_dp_handle_link_loss(struct dc_link *link);
    367bool dc_link_dp_allow_hpd_rx_irq(const struct dc_link *link);
    368
    369struct dc_sink_init_data;
    370
    371struct dc_sink *dc_link_add_remote_sink(
    372		struct dc_link *dc_link,
    373		const uint8_t *edid,
    374		int len,
    375		struct dc_sink_init_data *init_data);
    376
    377void dc_link_remove_remote_sink(
    378	struct dc_link *link,
    379	struct dc_sink *sink);
    380
    381/* Used by diagnostics for virtual link at the moment */
    382
    383void dc_link_dp_set_drive_settings(
    384	struct dc_link *link,
    385	const struct link_resource *link_res,
    386	struct link_training_settings *lt_settings);
    387
    388bool dc_link_dp_perform_link_training_skip_aux(
    389	struct dc_link *link,
    390	const struct link_resource *link_res,
    391	const struct dc_link_settings *link_setting);
    392
    393enum link_training_result dc_link_dp_perform_link_training(
    394	struct dc_link *link,
    395	const struct link_resource *link_res,
    396	const struct dc_link_settings *link_settings,
    397	bool skip_video_pattern);
    398
    399bool dc_link_dp_sync_lt_begin(struct dc_link *link);
    400
    401enum link_training_result dc_link_dp_sync_lt_attempt(
    402	struct dc_link *link,
    403	const struct link_resource *link_res,
    404	struct dc_link_settings *link_setting,
    405	struct dc_link_training_overrides *lt_settings);
    406
    407bool dc_link_dp_sync_lt_end(struct dc_link *link, bool link_down);
    408
    409void dc_link_dp_enable_hpd(const struct dc_link *link);
    410
    411void dc_link_dp_disable_hpd(const struct dc_link *link);
    412
    413bool dc_link_dp_set_test_pattern(
    414	struct dc_link *link,
    415	enum dp_test_pattern test_pattern,
    416	enum dp_test_pattern_color_space test_pattern_color_space,
    417	const struct link_training_settings *p_link_settings,
    418	const unsigned char *p_custom_pattern,
    419	unsigned int cust_pattern_size);
    420
    421bool dc_link_dp_get_max_link_enc_cap(const struct dc_link *link, struct dc_link_settings *max_link_enc_cap);
    422
    423void dc_link_enable_hpd_filter(struct dc_link *link, bool enable);
    424
    425bool dc_link_is_dp_sink_present(struct dc_link *link);
    426
    427bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type);
    428/*
    429 * DPCD access interfaces
    430 */
    431
    432#ifdef CONFIG_DRM_AMD_DC_HDCP
    433bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal);
    434bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal);
    435#endif
    436void dc_link_set_drive_settings(struct dc *dc,
    437				struct link_training_settings *lt_settings,
    438				const struct dc_link *link);
    439void dc_link_set_preferred_link_settings(struct dc *dc,
    440					 struct dc_link_settings *link_setting,
    441					 struct dc_link *link);
    442void dc_link_set_preferred_training_settings(struct dc *dc,
    443					struct dc_link_settings *link_setting,
    444					struct dc_link_training_overrides *lt_overrides,
    445					struct dc_link *link,
    446					bool skip_immediate_retrain);
    447void dc_link_enable_hpd(const struct dc_link *link);
    448void dc_link_disable_hpd(const struct dc_link *link);
    449void dc_link_set_test_pattern(struct dc_link *link,
    450			enum dp_test_pattern test_pattern,
    451			enum dp_test_pattern_color_space test_pattern_color_space,
    452			const struct link_training_settings *p_link_settings,
    453			const unsigned char *p_custom_pattern,
    454			unsigned int cust_pattern_size);
    455uint32_t dc_link_bandwidth_kbps(
    456	const struct dc_link *link,
    457	const struct dc_link_settings *link_setting);
    458
    459const struct dc_link_settings *dc_link_get_link_cap(
    460		const struct dc_link *link);
    461
    462void dc_link_overwrite_extended_receiver_cap(
    463		struct dc_link *link);
    464
    465bool dc_is_oem_i2c_device_present(
    466	struct dc *dc,
    467	size_t slave_address
    468);
    469
    470bool dc_submit_i2c(
    471		struct dc *dc,
    472		uint32_t link_index,
    473		struct i2c_command *cmd);
    474
    475bool dc_submit_i2c_oem(
    476		struct dc *dc,
    477		struct i2c_command *cmd);
    478
    479uint32_t dc_bandwidth_in_kbps_from_timing(
    480	const struct dc_crtc_timing *timing);
    481
    482bool dc_link_is_fec_supported(const struct dc_link *link);
    483bool dc_link_should_enable_fec(const struct dc_link *link);
    484
    485uint32_t dc_link_bw_kbps_from_raw_frl_link_rate_data(uint8_t bw);
    486enum dp_link_encoding dc_link_dp_mst_decide_link_encoding_format(const struct dc_link *link);
    487
    488void dc_link_get_cur_link_res(const struct dc_link *link,
    489		struct link_resource *link_res);
    490/* take a snapshot of current link resource allocation state */
    491void dc_get_cur_link_res_map(const struct dc *dc, uint32_t *map);
    492/* restore link resource allocation state from a snapshot */
    493void dc_restore_link_res_map(const struct dc *dc, uint32_t *map);
    494void dc_link_clear_dprx_states(struct dc_link *link);
    495struct gpio *get_hpd_gpio(struct dc_bios *dcb,
    496		struct graphics_object_id link_id,
    497		struct gpio_service *gpio_service);
    498void dp_trace_reset(struct dc_link *link);
    499bool dc_dp_trace_is_initialized(struct dc_link *link);
    500unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
    501		bool in_detection);
    502void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
    503		bool in_detection,
    504		bool is_logged);
    505bool dc_dp_trace_is_logged(struct dc_link *link,
    506		bool in_detection);
    507struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
    508		bool in_detection);
    509unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link);
    510#endif /* DC_LINK_H_ */