LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/common - dl_hal_function.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 50.0 % 4 2
Test Date: 2026-07-28 12:11:00 Functions: 50.0 % 2 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              : #ifndef __DL_HAL_FUNCTION_H__
      12              : #define __DL_HAL_FUNCTION_H__
      13              : 
      14              : #include <stdio.h>
      15              : #include <dlfcn.h>
      16              : #include <stdint.h>
      17              : #include "user_log.h"
      18              : #include "ascend_hal.h"
      19              : #include "ascend_hal_error.h"
      20              : #include "ascend_hal_define.h"
      21              : 
      22              : // device info, see hardware_version
      23              : #define VER_BIN5            5
      24              : #define VER_BIN8            8
      25              : #define GET_CHIP_OFFSET     8
      26              : #define CHIP_TYPE_910A      1
      27              : #define CHIP_TYPE_310P      4
      28              : #define CHIP_TYPE_910B_910_93 5
      29              : 
      30              : #define RDMA_CQE_ERR_SENSOR_TYPE 0xC3
      31              : #define RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE 0x8
      32              : /* bit position is 1:event enable; bit position is 0:event disable */
      33              : #define RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_MASK (1U << RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE)
      34              : /* bit position is 1:fault event;  bit position is 0:notify event(one time) */
      35              : #define RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE_MASK (0U << RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE)
      36              : 
      37              : struct DlHalOps {
      38              :     int (*dlDrvGetDevNum)(unsigned int *numDev);
      39              :     int (*dlDrvGetLocalDevIdByHostDevId)(unsigned int devId, unsigned int* chipId);
      40              :     int (*dlDrvGetDevIdByLocalDevId)(unsigned int localDevId, unsigned int *devId);
      41              :     int (*dlDrvDeviceGetIndexByPhyId)(uint32_t phyId, uint32_t *devIndex);
      42              :     int (*dlDrvDeviceGetPhyIdByIndex)(unsigned int devIndex, unsigned int *phyId);
      43              :     int (*dlHalGetPhyDevIdByudevId)(unsigned int udevId, unsigned int *phyDevId);
      44              :     drvError_t (*dlHalQueryDevPid)(struct halQueryDevpidInfo info, pid_t *devPid);
      45              :     drvError_t (*dlHalMemBindSibling)(int hostPid, int aicpuPid, unsigned int vfid, unsigned int devId,
      46              :         unsigned int flag);
      47              :     drvError_t (*dlDrvQueryProcessHostPid)(int pid, unsigned int *chipId, unsigned int *vfid,
      48              :         unsigned int *hostPid, unsigned int *cpType);
      49              :     drvError_t (*dlHalMemGetInfoEx)(unsigned int devId, unsigned int type, struct MemInfo *info);
      50              :     int (*dlHalGrpQuery)(GroupQueryCmdType cmd, void *inBuff, unsigned int inLen, void *outBuff,
      51              :         unsigned int *outLen);
      52              :     // HDC
      53              :     int (*dlHalHdcGetSessionAttr)(HDC_SESSION session, int attr, int *value);
      54              :     hdcError_t (*dlDrvHdcGetCapacity)(struct drvHdcCapacity *capacity);
      55              :     hdcError_t (*dlDrvHdcClientCreate)(HDC_CLIENT *client, int maxSessionNum, int serviceType, int flag);
      56              :     hdcError_t (*dlDrvHdcClientDestroy)(HDC_CLIENT client);
      57              :     hdcError_t (*dlDrvHdcSessionConnect)(int peerNode, int peerDevid, HDC_CLIENT client, HDC_SESSION *session);
      58              :     hdcError_t (*dlHalHdcSessionConnectEx)(int peerNode, int peerDevid, int peerPid, HDC_CLIENT client,
      59              :         HDC_SESSION *session);
      60              :     hdcError_t (*dlDrvHdcServerCreate)(int devid, int serviceType, HDC_SERVER *pServer);
      61              :     hdcError_t (*dlDrvHdcServerDestroy)(HDC_SERVER server);
      62              :     hdcError_t (*dlDrvHdcSessionAccept)(HDC_SERVER server, HDC_SESSION *session);
      63              :     hdcError_t (*dlDrvHdcSessionClose)(HDC_SESSION session);
      64              :     hdcError_t (*dlDrvHdcFreeMsg)(struct drvHdcMsg *msg);
      65              :     hdcError_t (*dlDrvHdcReuseMsg)(struct drvHdcMsg *msg);
      66              :     hdcError_t (*dlDrvHdcAddMsgBuffer)(struct drvHdcMsg *msg, char *pBuf, int len);
      67              :     hdcError_t (*dlDrvHdcGetMsgBuffer)(struct drvHdcMsg *msg, int index, char **pBuf, int *pLen);
      68              :     hdcError_t (*dlHalHdcRecv)(HDC_SESSION session, struct drvHdcMsg *pMsg, int bufLen, UINT64 flag,
      69              :         int *recvBufCount, UINT32 timeout);
      70              :     hdcError_t (*dlHalHdcSend)(HDC_SESSION session, struct drvHdcMsg *pMsg, UINT64 flag, UINT32 timeout);
      71              :     hdcError_t (*dlDrvHdcAllocMsg)(HDC_SESSION session, struct drvHdcMsg **ppMsg, int count);
      72              :     hdcError_t (*dlDrvHdcSetSessionReference)(HDC_SESSION session);
      73              : 
      74              :     int (*dlDrvGetProcessSign)(struct process_sign *sign);
      75              : 
      76              :     pid_t (*dlDrvDeviceGetBareTgid)(void);
      77              : 
      78              :     int (*dlHalNotifyGetInfo)(uint32_t devId, uint32_t tsId, uint32_t type, uint32_t *val);
      79              :     int (*dlHalMemAlloc)(void **pp, unsigned long long size, unsigned long long flag);
      80              :     int (*dlHalMemFree)(void *pp);
      81              :     int (*dlHalEschedSubmitEvent)(uint32_t devId, struct event_summary *event);
      82              : 
      83              :     int (*dlHalGetDeviceInfo)(uint32_t devId, int32_t moduleType, int32_t infoType, int64_t *value);
      84              : 
      85              :     int (*dlHalMemCtl)(int type, void *paramValue, size_t paramValueSize, void *outValue, size_t *outSizeRet);
      86              : 
      87              :     int (*dlHalBindCgroup)(BIND_CGROUP_TYPE bindType);
      88              :     int (*dlDrvGetPlatformInfo)(uint32_t* info);
      89              : 
      90              :     int (*dlHalGetChipInfo)(unsigned int devId, halChipInfo *chipInfo);
      91              : 
      92              :     drvError_t (*dlHalSensorNodeRegister)(uint32_t devid, struct halSensorNodeCfg *cfg, uint64_t *handle);
      93              :     drvError_t (*dlHalSensorNodeUnregister)(uint32_t devid, uint64_t handle);
      94              :     drvError_t (*dlHalSensorNodeUpdateState)(uint32_t devid, uint64_t handle, int val,
      95              :         halGeneralEventType_t assertion);
      96              : 
      97              :     int (*dlHalBuffAllocAlignEx)(uint64_t size, unsigned int align, unsigned long flag, int grpId, void **buff);
      98              :     int (*dlHalBuffFree)(void *buff);
      99              : 
     100              :     int (*dlHalEschedAttachDevice)(uint32_t devId);
     101              :     int (*dlHalEschedCreateGrp)(uint32_t devId, uint32_t grpId, GROUP_TYPE type);
     102              :     int (*dlHalEschedSubscribeEvent)(uint32_t devId, uint32_t grpId, uint32_t threadId, uint64_t eventBitmap);
     103              :     int (*dlHalEschedWaitEvent)(uint32_t devId, uint32_t grpId,uint32_t threadId, int32_t timeout,
     104              :         struct event_info *event);
     105              :     drvError_t (*dlHalResAddrMapV2)(unsigned int devId, struct res_map_info_in *resInfoIn,
     106              :         struct res_map_info_out *resInfoOut);
     107              :     drvError_t (*dlHalResAddrUnmapV2)(unsigned int devId, struct res_map_info_in *resInfoIn);
     108              :     drvError_t (*dlHalMemRegUbSegment)(uint32_t devId, uint64_t va, uint64_t size);
     109              :     drvError_t (*dlHalMemUnRegUbSegment)(uint32_t devid, uint64_t va);
     110              :     DVresult (*dlDrvMemGetAttribute)(DVdeviceptr vptr, struct DVattribute *attr);
     111              :     drvError_t (*dlHalHostRegister)(void *srcPtr, uint64_t size, uint32_t flag, uint32_t devId, void **dstPtr);
     112              :         drvError_t (*dlHalHostUnregister)(void *src_ptr, uint32_t devid);
     113              :         drvError_t (*dlHalHostUnregisterEx)(void *src_ptr, uint32_t devid, uint32_t flag);
     114              : };
     115              : 
     116              : int DlHalInit(void);
     117              : void DlHalDeinit(void);
     118              : 
     119              : int DlDrvGetDevNum(unsigned int *numDev);
     120              : int DlDrvGetLocalDevIdByHostDevId(unsigned int devId, unsigned int* chipId);
     121              : int DlDrvGetDevIdByLocalDevId(unsigned int localDevId, unsigned int *devId);
     122              : int DlDrvDeviceGetIndexByPhyId(uint32_t phyId, uint32_t *devIndex);
     123              : int DlDrvDeviceGetPhyIdByIndex(unsigned int devIndex, unsigned int *phyId);
     124              : int DlHalGetPhyDevIdByudevId(unsigned int udevId, unsigned int *phyDevId);
     125              : drvError_t DlHalQueryDevPid(struct halQueryDevpidInfo info, pid_t *devPid);
     126              : drvError_t DlHalMemBindSibling(int hostPid, int aicpuPid, unsigned int vfid, unsigned int devId,
     127              :     unsigned int flag);
     128              : drvError_t DlDrvQueryProcessHostPid(int pid, unsigned int *chipId, unsigned int *vfid, unsigned int *hostPid,
     129              :     unsigned int *cpType);
     130              : drvError_t DlHalMemGetInfoEx(unsigned int devId, unsigned int type, struct MemInfo *info);
     131              : int DlHalGrpQuery(GroupQueryCmdType cmd, void *inBuff, unsigned int inLen, void *outBuff, unsigned int *outLen);
     132              : // HDC
     133              : int DlHalHdcGetSessionAttr(HDC_SESSION session, int attr, int *value);
     134              : hdcError_t DlDrvHdcGetCapacity(struct drvHdcCapacity *capacity);
     135              : hdcError_t DlDrvHdcClientCreate(HDC_CLIENT *client, int maxSessionNum, int serviceType, int flag);
     136              : hdcError_t DlDrvHdcClientDestroy(HDC_CLIENT client);
     137              : hdcError_t DlDrvHdcSessionConnect(int peerNode, int peerDevid, HDC_CLIENT client, HDC_SESSION *session);
     138              : hdcError_t DlHalHdcSessionConnectEx(int peerNode, int peerDevid, int peerPid, HDC_CLIENT client,
     139              :     HDC_SESSION *pSession);
     140              : hdcError_t DlDrvHdcServerCreate(int devid, int serviceType, HDC_SERVER *pServer);
     141              : hdcError_t DlDrvHdcServerDestroy(HDC_SERVER server);
     142              : hdcError_t DlDrvHdcSessionAccept(HDC_SERVER server, HDC_SESSION *session);
     143              : hdcError_t DlDrvHdcSessionClose(HDC_SESSION session);
     144              : hdcError_t DlDrvHdcFreeMsg(struct drvHdcMsg *msg);
     145              : hdcError_t DlDrvHdcReuseMsg(struct drvHdcMsg *msg);
     146              : hdcError_t DlDrvHdcAddMsgBuffer(struct drvHdcMsg *msg, char *pBuf, int len);
     147              : hdcError_t DlDrvHdcGetMsgBuffer(struct drvHdcMsg *msg, int index, char **pBuf, int *pLen);
     148              : hdcError_t DlHalHdcRecv(HDC_SESSION session, struct drvHdcMsg *pMsg, int bufLen, UINT64 flag,
     149              :     int *recvBufCount, UINT32 timeout);
     150              : hdcError_t DlHalHdcSend(HDC_SESSION session, struct drvHdcMsg *pMsg, UINT64 flag, UINT32 timeout);
     151              : hdcError_t DlDrvHdcAllocMsg(HDC_SESSION session, struct drvHdcMsg **ppMsg, int count);
     152              : hdcError_t DlDrvHdcSetSessionReference(HDC_SESSION session);
     153              : 
     154              : int DlDrvGetProcessSign(struct process_sign *sign);
     155              : 
     156              : pid_t DlDrvDeviceGetBareTgid(void);
     157              : 
     158              : int DlHalNotifyGetInfo(uint32_t devId, uint32_t tsId, uint32_t type, uint32_t *val);
     159              : int DlHalMemAlloc(void **pp, unsigned long long size, unsigned long long flag);
     160              : int DlHalMemFree(void *pp);
     161              : int DlHalEschedSubmitEvent(uint32_t devId, struct event_summary *event);
     162              : 
     163              : // device info, see hardware_version
     164              : int DlHalGetDeviceInfo(uint32_t devId, int32_t moduleType, int32_t infoType, int64_t *value);
     165              : 
     166            0 : static inline uint32_t DlHalPlatGetVer(uint64_t deviceInfo)
     167              : {
     168            0 :     return (uint32_t)(deviceInfo & 0xff);
     169              : }
     170              : 
     171           68 : static inline uint32_t DlHalPlatGetChip(uint64_t deviceInfo)
     172              : {
     173           68 :     return (uint32_t)((deviceInfo >> GET_CHIP_OFFSET) & 0xff);
     174              : }
     175              : 
     176              : int DlHalBindCgroup(BIND_CGROUP_TYPE bindType);
     177              : int DlDrvGetPlatformInfo(uint32_t* info);
     178              : 
     179              : int DlHalMemCtl(int type, void *paramValue, size_t paramValueSize, void *outValue, size_t *outSizeRet);
     180              : int DlHalBuffAllocAlignEx(uint64_t size, unsigned int align, unsigned long flag, int grpId, void **buff);
     181              : int DlHalBuffFree(void *buff);
     182              : 
     183              : int DlHalGetChipInfo(unsigned int devId, halChipInfo *chipInfo);
     184              : 
     185              : int DlHalSensorNodeRegister(uint32_t devid, struct halSensorNodeCfg *cfg, uint64_t *handle);
     186              : int DlHalSensorNodeUnregister(uint32_t devid, uint64_t handle);
     187              : int DlHalSensorNodeUpdateState(uint32_t devid, uint64_t handle, int val, halGeneralEventType_t assertion);
     188              : 
     189              : int DlHalEschedAttachDevice(uint32_t devId);
     190              : int DlHalEschedCreateGrp(uint32_t devId, uint32_t grpId, GROUP_TYPE type);
     191              : int DlHalEschedSubscribeEvent(uint32_t devId, uint32_t grpId, uint32_t threadId, uint64_t eventBitmap);
     192              : int DlHalEschedWaitEvent(uint32_t devId, uint32_t grpId,uint32_t threadId, int32_t timeout,
     193              :     struct event_info *event);
     194              : int DlHalResAddrMapV2(unsigned int devId, struct res_map_info_in *resInfoIn, struct res_map_info_out *resInfoOut);
     195              : int DlHalResAddrUnmapV2(unsigned int devId, struct res_map_info_in *resInfoIn);
     196              : int DlHalMemRegUbSegment(uint32_t devId, uint64_t va, uint64_t size);
     197              : int DlHalMemUnRegUbSegment(uint32_t devId, uint64_t va);
     198              : int DlDrvMemGetAttribute(DVdeviceptr vptr, struct DVattribute *attr);
     199              : int DlHalHostRegister(void *srcPtr, uint64_t size, uint32_t flag, uint32_t devId, void **dstPtr);
     200              : int DlHalHostUnRegister(void *srcPtr, uint32_t devId);
     201              : int DlHalHostUnRegisterEx(void *srcPtr, uint32_t devId, uint32_t flag);
     202              : 
     203              : #endif  // __DL_HAL_FUNCTION_H__
        

Generated by: LCOV version 2.0-1