| 1 | /* |
| 2 | * Copyright (c) 2019, Intel Corporation |
| 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 |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS 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 | //! |
| 23 | //! \file encodecp.cpp |
| 24 | //! \brief Defines the common interface for secure encode |
| 25 | //! |
| 26 | #include "encodecp.h" |
| 27 | #include "encode_utils.h" |
| 28 | #include "encode_status_report.h" |
| 29 | #include "codechal_setting.h" |
| 30 | #include "mos_os_cp_interface_specific.h" |
| 31 | |
| 32 | namespace encode { |
| 33 | |
| 34 | bool EncodeCp::isCpEnabled() |
| 35 | { |
| 36 | return m_cpEnabled; |
| 37 | } |
| 38 | |
| 39 | MOS_STATUS EncodeCp::setStatusReport(MediaStatusReport *statusReport) |
| 40 | { |
| 41 | m_statusReport = statusReport; |
| 42 | return MOS_STATUS_SUCCESS; |
| 43 | } |
| 44 | MOS_STATUS EncodeCp::RegisterParams(void *settings) |
| 45 | { |
| 46 | ENCODE_FUNC_CALL(); |
| 47 | ENCODE_CHK_NULL_RETURN(settings); |
| 48 | ENCODE_CHK_NULL_RETURN(m_cpInterface); |
| 49 | m_cpInterface->RegisterParams(((CodechalSetting *)settings)->GetCpParams()); |
| 50 | m_cpEnabled = m_osInterface->osCpInterface->IsCpEnabled(); |
| 51 | return MOS_STATUS_SUCCESS; |
| 52 | } |
| 53 | |
| 54 | MOS_STATUS EncodeCp::UpdateParams(bool input) |
| 55 | { |
| 56 | if (!m_cpEnabled) |
| 57 | { |
| 58 | return MOS_STATUS_SUCCESS; |
| 59 | } |
| 60 | ENCODE_FUNC_CALL(); |
| 61 | ENCODE_CHK_NULL_RETURN(m_cpInterface); |
| 62 | ENCODE_CHK_STATUS_RETURN(m_cpInterface->UpdateParams(input)); |
| 63 | return MOS_STATUS_SUCCESS; |
| 64 | } |
| 65 | |
| 66 | MOS_STATUS EncodeCp::StartCpStatusReport(MOS_COMMAND_BUFFER *cmdBuffer) |
| 67 | { |
| 68 | if (!m_cpEnabled) |
| 69 | { |
| 70 | return MOS_STATUS_SUCCESS; |
| 71 | } |
| 72 | |
| 73 | PMOS_RESOURCE m_hwcounterBuf = (static_cast<EncoderStatusReport *>(m_statusReport))->GetHwCtrBuf(); |
| 74 | ENCODE_CHK_NULL_RETURN(m_hwcounterBuf); |
| 75 | ENCODE_CHK_NULL_RETURN(m_cpInterface); |
| 76 | |
| 77 | uint32_t offset = m_statusReport->GetIndex(m_statusReport->GetSubmittedCount()); |
| 78 | |
| 79 | ENCODE_CHK_STATUS_RETURN(m_cpInterface->ReadEncodeCounterFromHW( |
| 80 | m_osInterface, |
| 81 | cmdBuffer, |
| 82 | m_hwcounterBuf, |
| 83 | (uint16_t)offset)); |
| 84 | return MOS_STATUS_SUCCESS; |
| 85 | } |
| 86 | |
| 87 | MOS_STATUS EncodeCp::UpdateCpStatusReport(void *pStatusReportData) |
| 88 | { |
| 89 | if (!m_cpEnabled) |
| 90 | { |
| 91 | return MOS_STATUS_SUCCESS; |
| 92 | } |
| 93 | |
| 94 | ENCODE_CHK_NULL_RETURN(pStatusReportData); |
| 95 | EncodeStatusReportData *statusReportData = static_cast<EncodeStatusReportData*>(pStatusReportData); |
| 96 | uint64_t * hwcounter = statusReportData->hwCtr; |
| 97 | ENCODE_CHK_NULL_RETURN(hwcounter); |
| 98 | |
| 99 | statusReportData->hwCounterValue.Count = *hwcounter; |
| 100 | //Report back in Big endian |
| 101 | statusReportData->hwCounterValue.Count = SwapEndianness(statusReportData->hwCounterValue.Count); |
| 102 | //IV value computation |
| 103 | statusReportData->hwCounterValue.IV = *(++hwcounter); |
| 104 | statusReportData->hwCounterValue.IV = SwapEndianness(statusReportData->hwCounterValue.IV); |
| 105 | ENCODE_NORMALMESSAGE( |
| 106 | "encodeStatusReport->HWCounterValue.Count = 0x%llx, encodeStatusReport->HWCounterValue.IV = 0x%llx", |
| 107 | statusReportData->hwCounterValue.Count, |
| 108 | statusReportData->hwCounterValue.IV); |
| 109 | return MOS_STATUS_SUCCESS; |
| 110 | } |
| 111 | |
| 112 | MOS_STATUS EncodeCp::patchForHM() |
| 113 | { |
| 114 | if (m_cpEnabled && m_osInterface && m_osInterface->osCpInterface) |
| 115 | { |
| 116 | return m_osInterface->osCpInterface->PermeatePatchForHM(nullptr, nullptr, nullptr); |
| 117 | } |
| 118 | return MOS_STATUS_SUCCESS; |
| 119 | } |
| 120 | } |