1 /* 2 * Copyright (c) 2023, 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 decode_huc_authcheck_packet_m12.cpp 24 //! \brief Defines the interface for HuC authentication check packet 25 //! 26 27 #include "decode_huc_authcheck_packet_m12.h" 28 #include "decode_resource_auto_lock.h" 29 #include "mhw_mmio_g12.h" 30 #include "mhw_mi_g12_X.h" 31 32 namespace decode 33 { Init()34 MOS_STATUS DecodeHucAuthCheckPktM12::Init() 35 { 36 DECODE_FUNC_CALL(); 37 38 DECODE_CHK_NULL(m_miInterface); 39 DECODE_CHK_NULL(m_osInterface); 40 DECODE_CHK_NULL(m_pipeline); 41 42 m_allocator = m_pipeline->GetDecodeAllocator(); 43 DECODE_CHK_NULL(m_allocator); 44 45 if (m_hucAuthCheckBuf == nullptr) 46 { 47 // Init buffer for storing Huc auth status MMIO 48 m_hucAuthCheckBuf = m_allocator->AllocateBuffer( 49 sizeof(uint64_t), "Huc authentication register store Buffer", 50 resourceInternalReadWriteCache, lockableVideoMem, true, 0); 51 DECODE_CHK_NULL(m_hucAuthCheckBuf); 52 53 // add MMIO mask in DW0 54 MOS_LOCK_PARAMS lockFlags; 55 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); 56 lockFlags.WriteOnly = 1; 57 uint32_t *hucRegData = (uint32_t *)m_osInterface->pfnLockResource(m_osInterface, &m_hucAuthCheckBuf->OsResource, &lockFlags); 58 DECODE_CHK_NULL(hucRegData); 59 *hucRegData = HUC_LOAD_INFO_REG_MASK_G12; 60 m_osInterface->pfnUnlockResource(m_osInterface, &m_hucAuthCheckBuf->OsResource); 61 } 62 63 if (m_secondLevelBBArray == nullptr) 64 { 65 // 1 CL enough for huc auth check 66 m_secondLevelBBArray = m_allocator->AllocateBatchBufferArray( 67 CODECHAL_CACHELINE_SIZE, 1, CODECHAL_HEVC_NUM_DMEM_BUFFERS, true, lockableVideoMem); 68 DECODE_CHK_NULL(m_secondLevelBBArray); 69 } 70 71 return MOS_STATUS_SUCCESS; 72 } 73 Destroy()74 MOS_STATUS DecodeHucAuthCheckPktM12::Destroy() 75 { 76 DECODE_FUNC_CALL(); 77 78 DECODE_CHK_NULL(m_allocator); 79 DECODE_CHK_STATUS(m_allocator->Destroy(m_hucAuthCheckBuf)); 80 DECODE_CHK_STATUS(m_allocator->Destroy(m_secondLevelBBArray)); 81 82 return MOS_STATUS_SUCCESS; 83 } 84 Execute(MOS_COMMAND_BUFFER & cmdBuffer)85 MOS_STATUS DecodeHucAuthCheckPktM12::Execute(MOS_COMMAND_BUFFER &cmdBuffer) 86 { 87 DECODE_FUNC_CALL(); 88 89 // add media reset check 100ms, which equals to 1080p WDT threshold 90 DECODE_CHK_STATUS(m_miInterface->SetWatchdogTimerThreshold(1920, 1080, true)); 91 DECODE_CHK_STATUS(m_miInterface->AddWatchdogTimerStopCmd(&cmdBuffer)); 92 DECODE_CHK_STATUS(m_miInterface->AddWatchdogTimerStartCmd(&cmdBuffer)); 93 94 // program 2nd level chained BB for Huc auth 95 m_batchBuf = m_secondLevelBBArray->Fetch(); 96 if (m_batchBuf != nullptr) 97 { 98 ResourceAutoLock resLock(m_allocator, &m_batchBuf->OsResource); 99 uint8_t *batchBufBase = (uint8_t *)resLock.LockResourceForWrite(); 100 DECODE_CHK_NULL(batchBufBase); 101 DECODE_CHK_STATUS(Init2ndLevelCmdBuffer(*m_batchBuf, batchBufBase)); 102 m_hucAuthCmdBuffer.cmdBuf1stLvl = &cmdBuffer; 103 DECODE_CHK_STATUS(PackHucAuthCmds(m_hucAuthCmdBuffer)); 104 if (!m_osInterface->pfnIsMismatchOrderProgrammingSupported()) 105 { 106 DECODE_CHK_STATUS(m_miInterface->AddMiBatchBufferEnd(&m_hucAuthCmdBuffer, nullptr)); 107 } 108 } 109 110 // BB start for 2nd level BB 111 DECODE_CHK_STATUS(m_miInterface->AddMiBatchBufferStartCmd(&cmdBuffer, m_batchBuf)); 112 113 return MOS_STATUS_SUCCESS; 114 } 115 Init2ndLevelCmdBuffer(MHW_BATCH_BUFFER & batchBuffer,uint8_t * batchBufBase)116 MOS_STATUS DecodeHucAuthCheckPktM12::Init2ndLevelCmdBuffer(MHW_BATCH_BUFFER &batchBuffer, uint8_t *batchBufBase) 117 { 118 DECODE_FUNC_CALL(); 119 120 auto &cmdBuffer = m_hucAuthCmdBuffer; 121 MOS_ZeroMemory(&cmdBuffer, sizeof(MOS_COMMAND_BUFFER)); 122 cmdBuffer.pCmdBase = (uint32_t *)batchBufBase; 123 cmdBuffer.pCmdPtr = cmdBuffer.pCmdBase; 124 cmdBuffer.iRemaining = batchBuffer.iSize; 125 cmdBuffer.OsResource = batchBuffer.OsResource; 126 127 return MOS_STATUS_SUCCESS; 128 } 129 PackHucAuthCmds(MOS_COMMAND_BUFFER & cmdBuffer)130 MOS_STATUS DecodeHucAuthCheckPktM12::PackHucAuthCmds(MOS_COMMAND_BUFFER &cmdBuffer) 131 { 132 DECODE_FUNC_CALL(); 133 134 // Store Huc Auth register 135 MHW_MI_STORE_REGISTER_MEM_PARAMS storeRegParams; 136 MOS_ZeroMemory(&storeRegParams, sizeof(storeRegParams)); 137 storeRegParams.presStoreBuffer = &m_hucAuthCheckBuf->OsResource; 138 storeRegParams.dwOffset = sizeof(uint32_t); 139 storeRegParams.dwRegister = m_hucInterface->GetMmioRegisters(MHW_VDBOX_NODE_1)->hucLoadInfoOffset; 140 DECODE_CHK_STATUS(m_miInterface->AddMiStoreRegisterMemCmd(&cmdBuffer, &storeRegParams)); 141 142 MHW_MI_FLUSH_DW_PARAMS flushDwParams; 143 MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams)); 144 DECODE_CHK_STATUS(m_miInterface->AddMiFlushDwCmd(&cmdBuffer, &flushDwParams)); 145 146 // Check Huc auth: if equals to 0 continue chained BB until reset, otherwise send BB end cmd. 147 uint32_t compareOperation = mhw_mi_g12_X::MI_CONDITIONAL_BATCH_BUFFER_END_CMD::COMPARE_OPERATION_MADEQUALIDD; 148 DECODE_CHK_STATUS(m_hwInterface->SendCondBbEndCmd( 149 &m_hucAuthCheckBuf->OsResource, 0, 0, false, true, compareOperation, &cmdBuffer)); 150 151 // Chained BB loop 152 DECODE_CHK_STATUS(static_cast<MhwMiInterfaceG12 *>(m_miInterface)->AddMiBatchBufferStartCmd(&cmdBuffer, m_batchBuf, true)); 153 154 return MOS_STATUS_SUCCESS; 155 } 156 } 157