Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928// SPDX-License-Identifier: MIT/* * Copyright 2019 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 "amdgpu_dm_hdcp.h"#include "amdgpu.h"#include "amdgpu_dm.h"#include "dc_fused_io.h"#include "dm_helpers.h"#include <drm/display/drm_hdcp_helper.h>#include "hdcp_psp.h"
/* * If the SRM version being loaded is less than or equal to the * currently loaded SRM, psp will return 0xFFFF as the version */#define PSP_SRM_VERSION_MAX 0xFFFF
STATIC_IFN_KUNIT bool lp_write_i2c(void *handle, uint32_t address, const uint8_t *data, uint32_t size){ struct dc_link *link = handle; struct i2c_payload i2c_payloads[] = {{true, address, size, (void *)data} }; struct i2c_command cmd = {i2c_payloads, 1, I2C_COMMAND_ENGINE_HW, link->dc->caps.i2c_speed_in_khz};
return dm_helpers_submit_i2c(link->ctx, link, &cmd);}EXPORT_IF_KUNIT(lp_write_i2c);
STATIC_IFN_KUNIT bool lp_read_i2c(void *handle, uint32_t address, uint8_t offset, uint8_t *data, uint32_t size){ struct dc_link *link = handle;
struct i2c_payload i2c_payloads[] = {{true, address, 1, &offset}, {false, address, size, data} }; struct i2c_command cmd = {i2c_payloads, 2, I2C_COMMAND_ENGINE_HW, link->dc->caps.i2c_speed_in_khz};
return dm_helpers_submit_i2c(link->ctx, link, &cmd);}EXPORT_IF_KUNIT(lp_read_i2c);
STATIC_IFN_KUNIT bool lp_write_dpcd(void *handle, uint32_t address, const uint8_t *data, uint32_t size){ struct dc_link *link = handle;
return dm_helpers_dp_write_dpcd(link->ctx, link, address, data, size);}EXPORT_IF_KUNIT(lp_write_dpcd);
STATIC_IFN_KUNIT bool lp_read_dpcd(void *handle, uint32_t address, uint8_t *data, uint32_t size){ struct dc_link *link = handle;
return dm_helpers_dp_read_dpcd(link->ctx, link, address, data, size);}EXPORT_IF_KUNIT(lp_read_dpcd);
STATIC_IFN_KUNIT bool lp_atomic_write_poll_read_i2c( void *handle, const struct mod_hdcp_atomic_op_i2c *write, const struct mod_hdcp_atomic_op_i2c *poll, struct mod_hdcp_atomic_op_i2c *read, uint32_t poll_timeout_us, uint8_t poll_mask_msb){ struct dc_link *link = handle;
return dm_atomic_write_poll_read_i2c(link, write, poll, read, poll_timeout_us, poll_mask_msb);}EXPORT_IF_KUNIT(lp_atomic_write_poll_read_i2c);
STATIC_IFN_KUNIT bool lp_atomic_write_poll_read_aux( void *handle, const struct mod_hdcp_atomic_op_aux *write, const struct mod_hdcp_atomic_op_aux *poll, struct mod_hdcp_atomic_op_aux *read, uint32_t poll_timeout_us, uint8_t poll_mask_msb){ struct dc_link *link = handle;
return dm_atomic_write_poll_read_aux(link, write, poll, read, poll_timeout_us, poll_mask_msb);}EXPORT_IF_KUNIT(lp_atomic_write_poll_read_aux);
STATIC_IFN_KUNITuint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *srm_size){ struct ta_hdcp_shared_memory *hdcp_cmd;
if (!psp->hdcp_context.context.initialized) { DRM_WARN("Failed to get hdcp srm. HDCP TA is not initialized."); return NULL; }
hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.context.mem_context.shared_buf; memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP_GET_SRM; psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS) return NULL;
*srm_version = hdcp_cmd->out_msg.hdcp_get_srm.srm_version; *srm_size = hdcp_cmd->out_msg.hdcp_get_srm.srm_buf_size;
return hdcp_cmd->out_msg.hdcp_get_srm.srm_buf;}EXPORT_IF_KUNIT(psp_get_srm);
STATIC_IFN_KUNITint psp_set_srm(struct psp_context *psp, u8 *srm, uint32_t srm_size, uint32_t *srm_version){ struct ta_hdcp_shared_memory *hdcp_cmd;
if (!psp->hdcp_context.context.initialized) { DRM_WARN("Failed to get hdcp srm. HDCP TA is not initialized."); return -EINVAL; }
hdcp_cmd = (struct ta_hdcp_shared_memory *)psp->hdcp_context.context.mem_context.shared_buf; memset(hdcp_cmd, 0, sizeof(struct ta_hdcp_shared_memory));
memcpy(hdcp_cmd->in_msg.hdcp_set_srm.srm_buf, srm, srm_size); hdcp_cmd->in_msg.hdcp_set_srm.srm_buf_size = srm_size; hdcp_cmd->cmd_id = TA_HDCP_COMMAND__HDCP_SET_SRM;
psp_hdcp_invoke(psp, hdcp_cmd->cmd_id);
if (hdcp_cmd->hdcp_status != TA_HDCP_STATUS__SUCCESS || hdcp_cmd->out_msg.hdcp_set_srm.valid_signature != 1 || hdcp_cmd->out_msg.hdcp_set_srm.srm_version == PSP_SRM_VERSION_MAX) return -EINVAL;
*srm_version = hdcp_cmd->out_msg.hdcp_set_srm.srm_version; return 0;}EXPORT_IF_KUNIT(psp_set_srm);
STATIC_IFN_KUNITvoid process_output(struct hdcp_workqueue *hdcp_work){ struct mod_hdcp_output output = hdcp_work->output;
if (output.callback_stop) cancel_delayed_work(&hdcp_work->callback_dwork);
if (output.callback_needed) schedule_delayed_work(&hdcp_work->callback_dwork, msecs_to_jiffies(output.callback_delay));
if (output.watchdog_timer_stop) cancel_delayed_work(&hdcp_work->watchdog_timer_dwork);
if (output.watchdog_timer_needed) schedule_delayed_work(&hdcp_work->watchdog_timer_dwork, msecs_to_jiffies(output.watchdog_timer_delay));
schedule_delayed_work(&hdcp_work->property_validate_dwork, msecs_to_jiffies(0));}EXPORT_IF_KUNIT(process_output);
STATIC_IFN_KUNITbool hdcp_get_content_protection_from_status( unsigned int hdcp_content_type, enum mod_hdcp_encryption_status encryption_status, unsigned int *content_protection){ if (encryption_status == MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF) { *content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED; return true; }
if (hdcp_content_type == DRM_MODE_HDCP_CONTENT_TYPE0 && encryption_status <= MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE0_ON) { *content_protection = DRM_MODE_CONTENT_PROTECTION_ENABLED; return true; }
if (hdcp_content_type == DRM_MODE_HDCP_CONTENT_TYPE1 && encryption_status == MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON) { *content_protection = DRM_MODE_CONTENT_PROTECTION_ENABLED; return true; }
return false;}EXPORT_IF_KUNIT(hdcp_get_content_protection_from_status);
STATIC_IFN_KUNITvoid hdcp_get_link_display_adjustments( bool enable_encryption, u8 content_type, bool fused_io_supported, bool hdcp_lc_force_fw_enable, bool hdcp_lc_enable_sw_fallback, struct mod_hdcp_link_adjustment *link_adjust, struct mod_hdcp_display_adjustment *display_adjust){ memset(link_adjust, 0, sizeof(*link_adjust)); memset(display_adjust, 0, sizeof(*display_adjust));
if (!enable_encryption) { display_adjust->disable = MOD_HDCP_DISPLAY_DISABLE_AUTHENTICATION; return; }
display_adjust->disable = MOD_HDCP_DISPLAY_NOT_DISABLE; link_adjust->auth_delay = 2; link_adjust->retry_limit = MAX_NUM_OF_ATTEMPTS;
if (content_type == DRM_MODE_HDCP_CONTENT_TYPE0) { link_adjust->hdcp2.force_type = MOD_HDCP_FORCE_TYPE_0; } else if (content_type == DRM_MODE_HDCP_CONTENT_TYPE1) { link_adjust->hdcp1.disable = 1; link_adjust->hdcp2.force_type = MOD_HDCP_FORCE_TYPE_1; }
link_adjust->hdcp2.use_fw_locality_check = fused_io_supported || hdcp_lc_force_fw_enable; link_adjust->hdcp2.use_sw_locality_fallback = hdcp_lc_enable_sw_fallback;}EXPORT_IF_KUNIT(hdcp_get_link_display_adjustments);
STATIC_IFN_KUNITvoid link_lock(struct hdcp_workqueue *work, bool lock){ int i = 0;
for (i = 0; i < work->max_link; i++) { if (lock) mutex_lock(&work[i].mutex); else mutex_unlock(&work[i].mutex); }}EXPORT_IF_KUNIT(link_lock);
STATIC_IFN_KUNITvoid hdcp_update_display_encryption_control(struct hdcp_workqueue *hdcp_work, struct hdcp_workqueue *hdcp_w, unsigned int conn_index, bool enable_encryption){ if (enable_encryption) { /* Explicitly set the saved SRM as sysfs call will be after we already enabled hdcp * (s3 resume case) */ if (hdcp_work->srm_size > 0) psp_set_srm(hdcp_work->hdcp.config.psp.handle, hdcp_work->srm, hdcp_work->srm_size, &hdcp_work->srm_version);
schedule_delayed_work(&hdcp_w->property_validate_dwork, msecs_to_jiffies(DRM_HDCP_CHECK_PERIOD_MS)); } else { hdcp_w->encryption_status[conn_index] = MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF; cancel_delayed_work(&hdcp_w->property_validate_dwork); }}EXPORT_IF_KUNIT(hdcp_update_display_encryption_control);
void hdcp_update_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index, struct amdgpu_dm_connector *aconnector, u8 content_type, bool enable_encryption){ struct hdcp_workqueue *hdcp_w = &hdcp_work[link_index]; struct mod_hdcp_link_adjustment link_adjust; struct mod_hdcp_display_adjustment display_adjust; unsigned int conn_index = aconnector->base.index; const struct dc *dc = aconnector->dc_link->dc;
guard(mutex)(&hdcp_w->mutex); drm_connector_get(&aconnector->base); if (hdcp_w->aconnector[conn_index]) drm_connector_put(&hdcp_w->aconnector[conn_index]->base); hdcp_w->aconnector[conn_index] = aconnector;
hdcp_get_link_display_adjustments(enable_encryption, content_type, dc->caps.fused_io_supported, dc->debug.hdcp_lc_force_fw_enable, dc->debug.hdcp_lc_enable_sw_fallback, &link_adjust, &display_adjust); hdcp_update_display_encryption_control(hdcp_work, hdcp_w, conn_index, enable_encryption);
mod_hdcp_update_display(&hdcp_w->hdcp, conn_index, &link_adjust, &display_adjust, &hdcp_w->output);
process_output(hdcp_w);}EXPORT_IF_KUNIT(hdcp_update_display);
STATIC_IFN_KUNITvoid hdcp_remove_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index, struct amdgpu_dm_connector *aconnector){ struct hdcp_workqueue *hdcp_w = &hdcp_work[link_index]; struct drm_connector_state *conn_state = aconnector->base.state; unsigned int conn_index = aconnector->base.index;
guard(mutex)(&hdcp_w->mutex);
/* the removal of display will invoke auth reset -> hdcp destroy and * we'd expect the Content Protection (CP) property changed back to * DESIRED if at the time ENABLED. CP property change should occur * before the element removed from linked list. */ if (conn_state && conn_state->content_protection == DRM_MODE_CONTENT_PROTECTION_ENABLED) { conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED;
DRM_DEBUG_DRIVER("[HDCP_DM] display %d, CP 2 -> 1, type %u, DPMS %u\n", aconnector->base.index, conn_state->hdcp_content_type, aconnector->base.dpms); }
mod_hdcp_remove_display(&hdcp_w->hdcp, aconnector->base.index, &hdcp_w->output); if (hdcp_w->aconnector[conn_index]) { drm_connector_put(&hdcp_w->aconnector[conn_index]->base); hdcp_w->aconnector[conn_index] = NULL; } process_output(hdcp_w);}EXPORT_IF_KUNIT(hdcp_remove_display);
void hdcp_reset_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index){ struct hdcp_workqueue *hdcp_w = &hdcp_work[link_index]; unsigned int conn_index;
guard(mutex)(&hdcp_w->mutex);
mod_hdcp_reset_connection(&hdcp_w->hdcp, &hdcp_w->output);
cancel_delayed_work(&hdcp_w->property_validate_dwork);
for (conn_index = 0; conn_index < AMDGPU_DM_MAX_DISPLAY_COUNT; conn_index++) { hdcp_w->encryption_status[conn_index] = MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF; if (hdcp_w->aconnector[conn_index]) { drm_connector_put(&hdcp_w->aconnector[conn_index]->base); hdcp_w->aconnector[conn_index] = NULL; } }
process_output(hdcp_w);}EXPORT_IF_KUNIT(hdcp_reset_display);
void hdcp_handle_cpirq(struct hdcp_workqueue *hdcp_work, unsigned int link_index){ struct hdcp_workqueue *hdcp_w = &hdcp_work[link_index];
schedule_work(&hdcp_w->cpirq_work);}EXPORT_IF_KUNIT(hdcp_handle_cpirq);
STATIC_IFN_KUNITvoid event_callback(struct work_struct *work){ struct hdcp_workqueue *hdcp_work;
hdcp_work = container_of(to_delayed_work(work), struct hdcp_workqueue, callback_dwork);
guard(mutex)(&hdcp_work->mutex);
cancel_delayed_work(&hdcp_work->callback_dwork);
mod_hdcp_process_event(&hdcp_work->hdcp, MOD_HDCP_EVENT_CALLBACK, &hdcp_work->output);
process_output(hdcp_work);}EXPORT_IF_KUNIT(event_callback);
STATIC_IFN_KUNITvoid event_property_update(struct work_struct *work){ struct hdcp_workqueue *hdcp_work = container_of(work, struct hdcp_workqueue, property_update_work); struct amdgpu_dm_connector *aconnector = NULL; struct drm_device *dev; unsigned int content_protection; long ret; unsigned int conn_index; struct drm_connector *connector; struct drm_connector_state *conn_state;
for (conn_index = 0; conn_index < AMDGPU_DM_MAX_DISPLAY_COUNT; conn_index++) { aconnector = hdcp_work->aconnector[conn_index];
if (!aconnector) continue;
connector = &aconnector->base;
/* check if display connected */ if (connector->status != connector_status_connected) continue;
conn_state = aconnector->base.state;
if (!conn_state) continue;
dev = connector->dev;
if (!dev) continue;
drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); guard(mutex)(&hdcp_work->mutex);
if (conn_state->commit) { ret = wait_for_completion_interruptible_timeout(&conn_state->commit->hw_done, 10 * HZ); if (ret == 0) { DRM_ERROR("HDCP state unknown! Setting it to DESIRED\n"); hdcp_work->encryption_status[conn_index] = MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF; } } if (hdcp_get_content_protection_from_status(conn_state->hdcp_content_type, hdcp_work->encryption_status[conn_index], &content_protection)) { if (content_protection == DRM_MODE_CONTENT_PROTECTION_ENABLED) DRM_DEBUG_DRIVER("[HDCP_DM] DRM_MODE_CONTENT_PROTECTION_ENABLED\n"); else DRM_DEBUG_DRIVER("[HDCP_DM] DRM_MODE_CONTENT_PROTECTION_DESIRED\n");
drm_hdcp_update_content_protection(connector, content_protection); } drm_modeset_unlock(&dev->mode_config.connection_mutex); }}EXPORT_IF_KUNIT(event_property_update);
STATIC_IFN_KUNITvoid event_property_validate(struct work_struct *work){ struct hdcp_workqueue *hdcp_work = container_of(to_delayed_work(work), struct hdcp_workqueue, property_validate_dwork); struct mod_hdcp_display_query query; struct amdgpu_dm_connector *aconnector; unsigned int conn_index;
guard(mutex)(&hdcp_work->mutex);
for (conn_index = 0; conn_index < AMDGPU_DM_MAX_DISPLAY_COUNT; conn_index++) { aconnector = hdcp_work->aconnector[conn_index];
if (!aconnector) continue;
/* check if display connected */ if (aconnector->base.status != connector_status_connected) continue;
if (!aconnector->base.state) continue;
query.encryption_status = MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF; mod_hdcp_query_display(&hdcp_work->hdcp, aconnector->base.index, &query);
DRM_DEBUG_DRIVER("[HDCP_DM] disp %d, connector->CP %u, (query, work): (%d, %d)\n", aconnector->base.index, aconnector->base.state->content_protection, query.encryption_status, hdcp_work->encryption_status[conn_index]);
if (query.encryption_status != hdcp_work->encryption_status[conn_index]) { DRM_DEBUG_DRIVER("[HDCP_DM] encryption_status change from %x to %x\n", hdcp_work->encryption_status[conn_index], query.encryption_status);
hdcp_work->encryption_status[conn_index] = query.encryption_status;
DRM_DEBUG_DRIVER("[HDCP_DM] trigger property_update_work\n");
schedule_work(&hdcp_work->property_update_work); } }}EXPORT_IF_KUNIT(event_property_validate);
STATIC_IFN_KUNITvoid event_watchdog_timer(struct work_struct *work){ struct hdcp_workqueue *hdcp_work;
hdcp_work = container_of(to_delayed_work(work), struct hdcp_workqueue, watchdog_timer_dwork);
guard(mutex)(&hdcp_work->mutex);
cancel_delayed_work(&hdcp_work->watchdog_timer_dwork);
mod_hdcp_process_event(&hdcp_work->hdcp, MOD_HDCP_EVENT_WATCHDOG_TIMEOUT, &hdcp_work->output);
process_output(hdcp_work);}EXPORT_IF_KUNIT(event_watchdog_timer);
STATIC_IFN_KUNITvoid event_cpirq(struct work_struct *work){ struct hdcp_workqueue *hdcp_work;
hdcp_work = container_of(work, struct hdcp_workqueue, cpirq_work);
guard(mutex)(&hdcp_work->mutex);
mod_hdcp_process_event(&hdcp_work->hdcp, MOD_HDCP_EVENT_CPIRQ, &hdcp_work->output);
process_output(hdcp_work);}EXPORT_IF_KUNIT(event_cpirq);
void hdcp_destroy(struct kobject *kobj, struct hdcp_workqueue *hdcp_work){ int i = 0;
for (i = 0; i < hdcp_work->max_link; i++) { cancel_delayed_work_sync(&hdcp_work[i].callback_dwork); cancel_delayed_work_sync(&hdcp_work[i].watchdog_timer_dwork); cancel_delayed_work_sync(&hdcp_work[i].property_validate_dwork); }
sysfs_remove_bin_file(kobj, &hdcp_work[0].attr); kfree(hdcp_work->srm); kfree(hdcp_work->srm_temp); kfree(hdcp_work);}EXPORT_IF_KUNIT(hdcp_destroy);
STATIC_IFN_KUNITbool enable_assr(void *handle, struct dc_link *link){ struct hdcp_workqueue *hdcp_work = handle; struct mod_hdcp hdcp = hdcp_work->hdcp; struct psp_context *psp = hdcp.config.psp.handle; struct ta_dtm_shared_memory *dtm_cmd;
if (!psp->dtm_context.context.initialized) { drm_info(adev_to_drm(psp->adev), "Failed to enable ASSR, DTM TA is not initialized."); return false; }
dtm_cmd = (struct ta_dtm_shared_memory *)psp->dtm_context.context.mem_context.shared_buf;
guard(mutex)(&psp->dtm_context.mutex); memset(dtm_cmd, 0, sizeof(struct ta_dtm_shared_memory));
dtm_cmd->cmd_id = TA_DTM_COMMAND__TOPOLOGY_ASSR_ENABLE; dtm_cmd->dtm_in_message.topology_assr_enable.display_topology_dig_be_index = link->link_enc_hw_inst; dtm_cmd->dtm_status = TA_DTM_STATUS__GENERIC_FAILURE;
psp_dtm_invoke(psp, dtm_cmd->cmd_id);
if (dtm_cmd->dtm_status != TA_DTM_STATUS__SUCCESS) { drm_info(adev_to_drm(psp->adev), "Failed to enable ASSR"); return false; }
return true;}EXPORT_IF_KUNIT(enable_assr);
STATIC_IFN_KUNITvoid update_config(void *handle, struct cp_psp_stream_config *config){ struct hdcp_workqueue *hdcp_work = handle; struct amdgpu_dm_connector *aconnector; const struct dc *dc; int link_index; unsigned int conn_index; struct mod_hdcp_display *display; struct mod_hdcp_link *link; struct hdcp_workqueue *hdcp_w; struct dc_sink *sink = NULL; bool link_is_hdcp14 = false;
aconnector = config->dm_stream_ctx; if (!aconnector || !aconnector->dc_link) return;
link_index = aconnector->dc_link->link_index; display = &hdcp_work[link_index].display; link = &hdcp_work[link_index].link; hdcp_w = &hdcp_work[link_index];
conn_index = aconnector->base.index; dc = aconnector->dc_link->dc;
if (config->dpms_off) { hdcp_remove_display(hdcp_work, link_index, aconnector); return; }
memset(display, 0, sizeof(*display)); memset(link, 0, sizeof(*link));
display->index = aconnector->base.index; display->state = MOD_HDCP_DISPLAY_ACTIVE;
if (aconnector->dc_sink) sink = aconnector->dc_sink; else if (aconnector->dc_em_sink) sink = aconnector->dc_em_sink;
if (sink) link->mode = mod_hdcp_signal_type_to_operation_mode(sink->sink_signal);
display->controller = CONTROLLER_ID_D0 + config->otg_inst; display->dig_fe = config->dig_fe; link->dig_be = config->dig_be; link->ddc_line = aconnector->dc_link->ddc_hw_inst + 1; display->stream_enc_idx = config->stream_enc_idx; link->link_enc_idx = config->link_enc_idx; link->dio_output_id = config->dio_output_idx; link->phy_idx = config->phy_idx;
if (sink) link_is_hdcp14 = dc_link_is_hdcp14(aconnector->dc_link, sink->sink_signal); link->hdcp_supported_informational = link_is_hdcp14; link->dp.rev = aconnector->dc_link->dpcd_caps.dpcd_rev.raw; link->dp.assr_enabled = config->assr_enabled; link->dp.mst_enabled = config->mst_enabled; link->dp.dp2_enabled = config->dp2_enabled; link->dp.usb4_enabled = config->usb4_enabled; if (sink && sink->sink_signal == SIGNAL_TYPE_HDMI_FRL) link->hdmi.frl_enabled = config->frl_enabled; display->adjust.disable = MOD_HDCP_DISPLAY_DISABLE_AUTHENTICATION; link->adjust.auth_delay = 2; link->adjust.retry_limit = MAX_NUM_OF_ATTEMPTS; link->adjust.hdcp1.disable = 0; link->adjust.hdcp2.use_fw_locality_check = (dc->caps.fused_io_supported || dc->debug.hdcp_lc_force_fw_enable); link->adjust.hdcp2.use_sw_locality_fallback = dc->debug.hdcp_lc_enable_sw_fallback; hdcp_w->encryption_status[display->index] = MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF;
DRM_DEBUG_DRIVER("[HDCP_DM] display %d, CP %d, type %d\n", aconnector->base.index, (!!aconnector->base.state) ? aconnector->base.state->content_protection : -1, (!!aconnector->base.state) ? aconnector->base.state->hdcp_content_type : -1);
guard(mutex)(&hdcp_w->mutex);
mod_hdcp_add_display(&hdcp_w->hdcp, link, display, &hdcp_w->output); drm_connector_get(&aconnector->base); if (hdcp_w->aconnector[conn_index]) drm_connector_put(&hdcp_w->aconnector[conn_index]->base); hdcp_w->aconnector[conn_index] = aconnector; process_output(hdcp_w);}EXPORT_IF_KUNIT(update_config);
/** * DOC: Add sysfs interface for set/get srm * * NOTE: From the usermodes prospective you only need to call write *ONCE*, the kernel * will automatically call once or twice depending on the size * * call: "cat file > /sys/class/drm/card0/device/hdcp_srm" from usermode no matter what the size is * * The kernel can only send PAGE_SIZE at once and since MAX_SRM_FILE(5120) > PAGE_SIZE(4096), * srm_data_write can be called multiple times. * * sysfs interface doesn't tell us the size we will get so we are sending partial SRMs to psp and on * the last call we will send the full SRM. PSP will fail on every call before the last. * * This means we don't know if the SRM is good until the last call. And because of this * limitation we cannot throw errors early as it will stop the kernel from writing to sysfs * * Example 1: * Good SRM size = 5096 * first call to write 4096 -> PSP fails * Second call to write 1000 -> PSP Pass -> SRM is set * * Example 2: * Bad SRM size = 4096 * first call to write 4096 -> PSP fails (This is the same as above, but we don't know if this * is the last call) * * Solution?: * 1: Parse the SRM? -> It is signed so we don't know the EOF * 2: We can have another sysfs that passes the size before calling set. -> simpler solution * below * * Easy Solution: * Always call get after Set to verify if set was successful. * +----------------------+ * | Why it works: | * +----------------------+ * PSP will only update its srm if its older than the one we are trying to load. * Always do set first than get. * -if we try to "1. SET" a older version PSP will reject it and we can "2. GET" the newer * version and save it * * -if we try to "1. SET" a newer version PSP will accept it and we can "2. GET" the * same(newer) version back and save it * * -if we try to "1. SET" a newer version and PSP rejects it. That means the format is * incorrect/corrupted and we should correct our SRM by getting it from PSP */STATIC_IFN_KUNIT ssize_t srm_data_write(struct file *filp, struct kobject *kobj, const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count){ struct hdcp_workqueue *work; u32 srm_version = 0;
work = container_of(bin_attr, struct hdcp_workqueue, attr); link_lock(work, true);
memcpy(work->srm_temp + pos, buffer, count);
if (!psp_set_srm(work->hdcp.config.psp.handle, work->srm_temp, pos + count, &srm_version)) { DRM_DEBUG_DRIVER("HDCP SRM SET version 0x%X", srm_version); memcpy(work->srm, work->srm_temp, pos + count); work->srm_size = pos + count; work->srm_version = srm_version; }
link_lock(work, false);
return count;}EXPORT_IF_KUNIT(srm_data_write);
STATIC_IFN_KUNIT ssize_t srm_data_read(struct file *filp, struct kobject *kobj, const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count){ struct hdcp_workqueue *work; u8 *srm = NULL; u32 srm_version; u32 srm_size; size_t ret = count;
work = container_of(bin_attr, struct hdcp_workqueue, attr);
link_lock(work, true);
srm = psp_get_srm(work->hdcp.config.psp.handle, &srm_version, &srm_size);
if (!srm) { ret = -EINVAL; goto ret; }
if (pos >= srm_size) ret = 0;
if (srm_size - pos < count) { memcpy(buffer, srm + pos, srm_size - pos); ret = srm_size - pos; goto ret; }
memcpy(buffer, srm + pos, count);
ret: link_lock(work, false); return ret;}EXPORT_IF_KUNIT(srm_data_read);
/* From the hdcp spec (5.Renewability) SRM needs to be stored in a non-volatile memory. * * For example, * if Application "A" sets the SRM (ver 2) and we reboot/suspend and later when Application "B" * needs to use HDCP, the version in PSP should be SRM(ver 2). So SRM should be persistent * across boot/reboots/suspend/resume/shutdown * * Currently when the system goes down (suspend/shutdown) the SRM is cleared from PSP. For HDCP * we need to make the SRM persistent. * * -PSP owns the checking of SRM but doesn't have the ability to store it in a non-volatile memory. * -The kernel cannot write to the file systems. * -So we need usermode to do this for us, which is why an interface for usermode is needed * * * * Usermode can read/write to/from PSP using the sysfs interface * For example: * to save SRM from PSP to storage : cat /sys/class/drm/card0/device/hdcp_srm > srmfile * to load from storage to PSP: cat srmfile > /sys/class/drm/card0/device/hdcp_srm */static const struct bin_attribute data_attr = { .attr = {.name = "hdcp_srm", .mode = 0664}, .size = PSP_HDCP_SRM_FIRST_GEN_MAX_SIZE, /* Limit SRM size */ .write = srm_data_write, .read = srm_data_read,};
struct hdcp_workqueue *hdcp_create_workqueue(struct amdgpu_device *adev, struct cp_psp *cp_psp, struct dc *dc){ int max_caps = dc->caps.max_links; struct hdcp_workqueue *hdcp_work; int i = 0;
hdcp_work = kzalloc_objs(*hdcp_work, max_caps); if (ZERO_OR_NULL_PTR(hdcp_work)) return NULL;
hdcp_work->srm = kcalloc(PSP_HDCP_SRM_FIRST_GEN_MAX_SIZE, sizeof(*hdcp_work->srm), GFP_KERNEL);
if (!hdcp_work->srm) goto fail_alloc_context;
hdcp_work->srm_temp = kcalloc(PSP_HDCP_SRM_FIRST_GEN_MAX_SIZE, sizeof(*hdcp_work->srm_temp), GFP_KERNEL);
if (!hdcp_work->srm_temp) goto fail_alloc_context;
hdcp_work->max_link = max_caps;
for (i = 0; i < max_caps; i++) { mutex_init(&hdcp_work[i].mutex);
INIT_WORK(&hdcp_work[i].cpirq_work, event_cpirq); INIT_WORK(&hdcp_work[i].property_update_work, event_property_update); INIT_DELAYED_WORK(&hdcp_work[i].callback_dwork, event_callback); INIT_DELAYED_WORK(&hdcp_work[i].watchdog_timer_dwork, event_watchdog_timer); INIT_DELAYED_WORK(&hdcp_work[i].property_validate_dwork, event_property_validate);
struct mod_hdcp_config *config = &hdcp_work[i].hdcp.config; struct mod_hdcp_ddc_funcs *ddc_funcs = &config->ddc.funcs;
config->psp.handle = &adev->psp; if (dc->ctx->dce_version == DCN_VERSION_3_1 || dc->ctx->dce_version == DCN_VERSION_3_14 || dc->ctx->dce_version == DCN_VERSION_3_15 || dc->ctx->dce_version == DCN_VERSION_3_16 || dc->ctx->dce_version == DCN_VERSION_3_2 || dc->ctx->dce_version == DCN_VERSION_3_21 || dc->ctx->dce_version == DCN_VERSION_3_5 || dc->ctx->dce_version == DCN_VERSION_3_51 || dc->ctx->dce_version == DCN_VERSION_3_6 || dc->ctx->dce_version == DCN_VERSION_4_01) config->psp.caps.dtm_v3_supported = 1;
config->ddc.handle = dc_get_link_at_index(dc, i);
ddc_funcs->write_i2c = lp_write_i2c; ddc_funcs->read_i2c = lp_read_i2c; ddc_funcs->write_dpcd = lp_write_dpcd; ddc_funcs->read_dpcd = lp_read_dpcd; ddc_funcs->atomic_write_poll_read_i2c = lp_atomic_write_poll_read_i2c; ddc_funcs->atomic_write_poll_read_aux = lp_atomic_write_poll_read_aux;
memset(hdcp_work[i].aconnector, 0, sizeof(struct amdgpu_dm_connector *) * AMDGPU_DM_MAX_DISPLAY_COUNT); memset(hdcp_work[i].encryption_status, 0, sizeof(enum mod_hdcp_encryption_status) * AMDGPU_DM_MAX_DISPLAY_COUNT); }
cp_psp->funcs.update_stream_config = update_config; cp_psp->funcs.enable_assr = enable_assr; cp_psp->handle = hdcp_work;
/* File created at /sys/class/drm/card0/device/hdcp_srm*/ hdcp_work[0].attr = data_attr; sysfs_bin_attr_init(&hdcp_work[0].attr);
if (sysfs_create_bin_file(&adev->dev->kobj, &hdcp_work[0].attr)) drm_warn(adev_to_drm(adev), "Failed to create device file hdcp_srm\n");
return hdcp_work;
fail_alloc_context: kfree(hdcp_work->srm); kfree(hdcp_work->srm_temp); kfree(hdcp_work);
return NULL;}EXPORT_IF_KUNIT(hdcp_create_workqueue);