LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_device - ccu_drv_handle.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 1.5 % 65 1
Test Date: 2026-08-18 17:47:01 Functions: 16.7 % 6 1

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "ccu_drv_handle.h"
      12              : 
      13              : #include "ccu_log.h"
      14              : 
      15              : #include "hccp_tlv.h"
      16              : #include "hccp_tlv_hdc_mgr.h"
      17              : 
      18              : #include "ccu_res_specs.h"
      19              : #include "ccu_pfe_cfg_mgr.h"
      20              : #include "ccu_comp.h"
      21              : #include "ccu_res_batch_allocator.h"
      22              : #include "ccu_kernel_mgr.h"
      23              : 
      24              : // 支持ccu新老通信域混跑临时添加
      25              : #include "unified_platform/ccu/ccu_device/ccu_res_specs_legacy.h"
      26              : #include "unified_platform/ccu/ccu_device/ccu_component/ccu_component.h"
      27              : #include "unified_platform/ccu/ccu_device/ccu_res_batch_allocator_legacy.h"
      28              : #include "unified_platform/ccu/ccu_context/ccu_context_mgr_imp.h"
      29              : #include "hccp_tlv_hdc_manager.h"
      30              : 
      31              : #include "exception_handler.h"
      32              : 
      33              : namespace hcomm {
      34              : 
      35            0 : inline bool CheckCcuOpenSourceEnable()
      36              : {
      37              :     // A6 不支持legacy ccu mc2,可以完全切换至开源流程
      38            0 :     auto devType = DevType::DEV_TYPE_COUNT;
      39            0 :     (void)hrtGetDeviceType(devType);
      40            0 :     return devType == DevType::DEV_TYPE_960;
      41              : }
      42              : 
      43            0 : static HcclResult HccpRaTlvRequest(const TlvHandle tlvHandle, const u32 tlvModuleType, const u32 tlvCcuMsgType)
      44              : {
      45            0 :     CHK_PTR_NULL(tlvHandle);
      46            0 :     struct TlvMsg sendMsg {};
      47            0 :     struct TlvMsg recvMsg {};
      48            0 :     sendMsg.type = tlvCcuMsgType;
      49              : 
      50            0 :     HCCL_INFO("[%s] tlvHandle[%p].", __func__, tlvHandle);
      51            0 :     constexpr u32 RA_TLV_REQUEST_UNAVAIL = 128308;
      52            0 :     int32_t ret = RaTlvRequest(tlvHandle, tlvModuleType, &sendMsg, &recvMsg);
      53            0 :     if (ret == RA_TLV_REQUEST_UNAVAIL || ret == OTHERS_ENOTSUPP) {
      54            0 :         HCCL_RUN_WARNING(
      55              :             "[%s] ra tlv request UNAVAIL, tlvHandle[%p], tlvModeulType[%u], tlvCcuMsgType[%u], ret[%d].", __func__,
      56              :             tlvHandle, tlvModuleType, tlvCcuMsgType, ret);
      57            0 :         return HCCL_E_AGAIN; // 代表CCU驱动已被拉起,需要等待其他进程退出
      58              :     }
      59              : 
      60            0 :     if (ret != 0) {
      61            0 :         HCCL_ERROR(
      62              :             "[Request][RaTlv]errNo[0x%016llx] ra tlv request fail. "
      63              :             "return: ret[%d], module type[%u], message type[%u]",
      64              :             HCCL_ERROR_CODE(HcclResult::HCCL_E_NETWORK), tlvModuleType, tlvCcuMsgType);
      65            0 :         return HcclResult::HCCL_E_NETWORK;
      66              :     }
      67              : 
      68            0 :     HCCL_INFO(
      69              :         "tlv request success, tlv module type[%u], "
      70              :         "message type[%u]",
      71              :         tlvModuleType, tlvCcuMsgType);
      72            0 :     return HcclResult::HCCL_SUCCESS;
      73              : }
      74              : 
      75            0 : CcuResult CcuDrvHandle::Init()
      76              : {
      77            0 :     HCCL_RUN_INFO("[CcuDrvHandle][%s], deviceLogicId: %d", __func__, devLogicId_);
      78            0 :     CCU_CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<uint32_t>(devLogicId_), devPhyId_));
      79              :     // 支持ccu新老通信域混跑
      80              :     CCU_EXCEPTION_HANDLE_BEGIN
      81              :     // 初始化CCU平台层能力,有时序要求
      82              :     // 当前走进A5通信域,暂时不需要主动拉起HDC通道
      83              :     /* 为了支持ccu新老通信域混跑,暂时复用原有的tlv mgr,避免重复申请资源
      84              :      * auto &tlvHdcMgr = HccpTlvHdcMgr::GetInstance(devPhyId_);
      85              :      * CHK_RET(tlvHdcMgr.Init());
      86              :      * tlvHandle_ = tlvHdcMgr.GetHandle();
      87              :      */
      88              : 
      89            0 :     tlvHandle_ = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(devLogicId_);
      90            0 :     CCU_CHK_PTR_NULL(tlvHandle_);
      91              :     // 拉起CCU驱动如果因其他进程占用重复拉起时,返回EAGAIN,日志检查返回值打印warning
      92            0 :     auto ret = HccpRaTlvRequest(tlvHandle_, TLV_MODULE_TYPE_CCU, MSG_TYPE_CCU_INIT);
      93            0 :     if (ret == HcclResult::HCCL_E_AGAIN) {
      94            0 :         HCCL_RUN_WARNING(
      95              :             "[%s] HccpRaTlvRequest ret[%d], repeat init ccu, deviceLogicId[%d].", __func__, ret, devLogicId_);
      96            0 :         return CcuResult::CCU_E_DRV_BUSY;
      97              :     }
      98            0 :     if (ret != HcclResult::HCCL_SUCCESS) {
      99            0 :         HCCL_ERROR("[%s] failed to init ccu driver, ret[%d] is unexpected.", __func__, ret);
     100            0 :         return CcuResult::CCU_E_DRV_INIT_FAILED;
     101              :     }
     102              : 
     103            0 :     if (!CheckCcuOpenSourceEnable()) {
     104            0 :         Hccl::CcuResSpecifications::GetInstance(devLogicId_).Init();
     105            0 :         Hccl::CcuComponent::GetInstance(devLogicId_).Init();
     106            0 :         Hccl::CcuResBatchAllocator::GetInstance(devLogicId_).Init();
     107            0 :         Hccl::CtxMgrImp::GetInstance(devLogicId_).Init();
     108              :     } else {
     109            0 :         CCU_CHK_RET(CcuResSpecifications::GetInstance(devLogicId_).Init());
     110            0 :         CCU_CHK_RET(CcuPfeCfgMgr::GetInstance(devLogicId_).Init());
     111            0 :         CCU_CHK_RET(CcuComponent::GetInstance(devLogicId_).Init());
     112            0 :         CCU_CHK_RET(CcuResBatchAllocator::GetInstance(devLogicId_).Init());
     113              :     }
     114              : 
     115            0 :     CCU_CHK_RET(CcuKernelMgr::GetInstance(devLogicId_).Init());
     116              : 
     117            0 :     CCU_EXCEPTION_HANDLE_END
     118              : 
     119            0 :     return CcuResult::CCU_SUCCESS;
     120              : }
     121              : 
     122            0 : static HcclResult CcuLegacyMgrDeinit(int32_t devLogicId)
     123              : {
     124              :     // 释放有时序要求
     125              :     EXCEPTION_HANDLE_BEGIN
     126            0 :     Hccl::CtxMgrImp::GetInstance(devLogicId).Deinit();
     127            0 :     Hccl::CcuResBatchAllocator::GetInstance(devLogicId).Deinit();
     128            0 :     Hccl::CcuComponent::GetInstance(devLogicId).Deinit();
     129            0 :     Hccl::CcuResSpecifications::GetInstance(devLogicId).Deinit();
     130            0 :     EXCEPTION_HANDLE_END
     131              : 
     132            0 :     return HcclResult::HCCL_SUCCESS;
     133              : }
     134              : 
     135            0 : CcuResult CcuDrvHandle::Deinit()
     136              : {
     137              :     // 释放流程不打断,不抛异常,尽量尝试释放所有资源
     138              :     // 释放有时序要求
     139            0 :     HCCL_RUN_INFO("[CcuDrvHandle] start to deinit ccu driver, deviceLogicId[%d].", devLogicId_);
     140            0 :     (void)CcuKernelMgr::GetInstance(devLogicId_).Deinit();
     141              : 
     142            0 :     if (!CheckCcuOpenSourceEnable()) {
     143            0 :         (void)CcuLegacyMgrDeinit(devLogicId_);
     144              :     } else {
     145            0 :         (void)CcuResBatchAllocator::GetInstance(devLogicId_).Deinit();
     146            0 :         (void)CcuComponent::GetInstance(devLogicId_).Deinit();
     147            0 :         (void)CcuPfeCfgMgr::GetInstance(devLogicId_).Deinit();
     148            0 :         (void)CcuResSpecifications::GetInstance(devLogicId_).Deinit();
     149              :     }
     150              : 
     151            0 :     if (tlvHandle_ != 0) {
     152            0 :         (void)HccpRaTlvRequest(tlvHandle_, TLV_MODULE_TYPE_CCU, MSG_TYPE_CCU_UNINIT);
     153            0 :         tlvHandle_ = 0;
     154              :     }
     155              : 
     156            0 :     return CcuResult::CCU_SUCCESS;
     157              : }
     158              : 
     159           69 : CcuDrvHandle::~CcuDrvHandle() { (void)Deinit(); }
     160              : 
     161              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1