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 REGISTER_CONFIG_H
12 : #define REGISTER_CONFIG_H
13 :
14 : #include <cstdint>
15 : #include <vector>
16 : #include <memory>
17 : #include <map>
18 : #include <string>
19 :
20 : namespace Adx {
21 :
22 : namespace {
23 : constexpr uint32_t HIGH_ADDR_SHIFT = 48U;
24 : constexpr uint32_t MOUDLE_TYPE_SHIFT = 52U;
25 : } // namespace
26 :
27 : struct RegisterTable {
28 5302 : RegisterTable(uint64_t regStartAddr, uint32_t regNum, uint8_t regByteWidth)
29 5302 : : startAddr(regStartAddr), num(regNum), byteWidth(regByteWidth)
30 5302 : {}
31 : uint64_t startAddr;
32 : uint32_t num;
33 : uint8_t byteWidth;
34 : };
35 :
36 : struct RegisterStepTable {
37 : uint64_t startAddr;
38 : uint32_t num;
39 : uint8_t byteWidth;
40 : uint8_t step;
41 : };
42 :
43 : struct ErrorRegisterTable {
44 726 : ErrorRegisterTable(uint8_t regErrIndex, uint64_t regOffsetAddr, uint8_t regByteWidth, std::string regName)
45 726 : : errIndex(regErrIndex), offsetAddr(regOffsetAddr), byteWidth(regByteWidth), name(regName)
46 726 : {}
47 : uint8_t errIndex;
48 : uint64_t offsetAddr;
49 : uint8_t byteWidth;
50 : std::string name;
51 : };
52 :
53 : enum class RegisterType { SU, VEC, MTE, CUBE, BIU, VEC_RB, BIF, L1, MTE_AIV, AIC, AIV, AIC_DBG, AIV_DBG };
54 :
55 : class RegisterInterface {
56 : public:
57 26 : RegisterInterface() = default;
58 26 : virtual ~RegisterInterface() = default;
59 : const std::vector<RegisterTable>& GetRegisterTable(RegisterType type) const;
60 : const std::vector<RegisterType>& GetRegisterTypes(uint8_t coreType) const;
61 : const std::vector<ErrorRegisterTable>& GetErrorRegisterTable() const;
62 :
63 : protected:
64 : std::map<RegisterType, std::vector<RegisterTable>> registerTableMap_;
65 : std::map<uint8_t, std::vector<RegisterType>> registerTypeMap_;
66 : std::vector<ErrorRegisterTable> ErrorRegisterMap_;
67 : };
68 :
69 : class CloudV2Register : public RegisterInterface {
70 : public:
71 : CloudV2Register();
72 10 : ~CloudV2Register() override{};
73 :
74 : private:
75 : uint64_t GetAddr(uint64_t regAddrHigh, uint64_t regAddrLow) const;
76 : };
77 :
78 : class CloudBaseRegister : public RegisterInterface {
79 : public:
80 : CloudBaseRegister();
81 16 : ~CloudBaseRegister() override{};
82 :
83 : protected:
84 : uint64_t GetAddr(uint64_t type, uint64_t regAddrHigh, uint64_t regAddrLow) const;
85 : void GenAddrByStep(RegisterType regType, const std::vector<RegisterStepTable>& regStepTab);
86 : void GenAICDbgAddr();
87 : void GenAIVDbgAddr();
88 : void GenAICOffsetAddr();
89 : void GenAIVOffsetAddr();
90 : std::vector<RegisterTable> GenAIVDbgSUAddr();
91 : std::vector<RegisterTable> GenAIVDbgMTEAddr();
92 : std::vector<RegisterTable> GenAIVDbgVECRBAddr();
93 : std::vector<RegisterTable> GenAIVDbgOthersAddr();
94 : };
95 :
96 : class CloudV4Register : public CloudBaseRegister {
97 : public:
98 : CloudV4Register();
99 12 : ~CloudV4Register() override{};
100 :
101 : private:
102 : void InitErrorRegisterMap();
103 : };
104 :
105 : class CloudV5Register : public CloudBaseRegister {
106 : public:
107 : CloudV5Register();
108 4 : ~CloudV5Register() override{};
109 :
110 : private:
111 : void InitErrorRegisterMap();
112 : };
113 :
114 : class RegisterManager {
115 : public:
116 : RegisterManager();
117 23 : ~RegisterManager() {}
118 : static RegisterManager& GetInstance();
119 : const std::shared_ptr<RegisterInterface> GetRegister();
120 :
121 : private:
122 : void CreateRegister();
123 :
124 : std::shared_ptr<RegisterInterface> register_;
125 : };
126 : } // namespace Adx
127 : #endif
|