File: boot_decode.h

package info (click to toggle)
amdsmi 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,316 kB
  • sloc: cpp: 41,766; python: 22,219; ansic: 12,789; sh: 754; makefile: 20
file content (219 lines) | stat: -rw-r--r-- 7,012 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
 * Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef BOOT_DECODE_H
#define BOOT_DECODE_H

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "json_util.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Boot message structure representing OAM boot message
 */
typedef struct {
    uint64_t value;  ///< 64-bit boot message value
} OamBootMsg;

/**
 * @brief Decoder function pointer type
 * @param msg Boot message to decode
 * @return JsonValue containing decoded information or NULL on failure
 */
typedef JsonValue* (*boot_decoder_func_t)(OamBootMsg *msg);

/**
 * @brief Decoder mapping entry
 */
typedef struct {
    uint8_t encoding;           ///< Error encoding value
    boot_decoder_func_t decoder; ///< Decoder function
} boot_decoder_entry_t;

/**
 * @brief Boot message constants
 */
#define BOOT_ERROR_PRESENT_MARKER   0xA4
#define BOOT_IN_BOOT_MARKER        0xBA
#define BOOT_SUCCESS_ENCODING      0xBA

/**
 * @brief Error encoding constants
 */
#define BOOT_ENCODING_HBM_TRAINING      0x01
#define BOOT_ENCODING_FW_LOAD           0x04
#define BOOT_ENCODING_WAFL_LINK         0x05
#define BOOT_ENCODING_XGMI_LINK         0x06
#define BOOT_ENCODING_USR_CP_LINK       0x07
#define BOOT_ENCODING_USR_DP_LINK       0x08
#define BOOT_ENCODING_HBM_MEM_TEST      0x09
#define BOOT_ENCODING_HBM_BIST_TEST     0x0A
#define BOOT_ENCODING_BOOT_CTRL_GEN_V0  0x0B
#define BOOT_ENCODING_BOOT_CTRL_GEN_V1  0x0C
#define BOOT_ENCODING_DATA_ABORT        0x0D

/**
 * @brief HBM stack decoder constants
 */
#define HBM_STACK_0     0x01
#define HBM_STACK_1     0x02
#define HBM_STACK_UNKNOWN  -1

/**
 * @brief Extract specific byte from 64-bit value
 * @param value 64-bit value
 * @param byte_index Byte index (0-7)
 * @return Extracted byte value
 */
static inline uint8_t extract_byte(uint64_t value, int byte_index) {
    return (uint8_t)((value >> (byte_index * 8)) & 0xFF);
}

/**
 * @brief Extract specific bits mask
 * @param num_bits Number of bits to extract
 * @return Bit mask
 */
static inline uint32_t extract_bits(int num_bits) {
    return (1U << num_bits) - 1;
}

/**
 * @brief Get boot version from boot message
 * @param msg Boot message
 * @return Boot version (0 or 1)
 */
int get_boot_version(OamBootMsg *msg);

/**
 * @brief Get error encoding from boot message
 * @param msg Boot message
 * @return Error encoding value
 */
int get_error_encoding(OamBootMsg *msg);

/**
 * @brief Check if error is present in boot message
 * @param msg Boot message
 * @return true if error present, false otherwise
 */
bool error_present(OamBootMsg *msg);

/**
 * @brief Check if in boot mode
 * @param msg Boot message
 * @return true if in boot mode, false otherwise
 */
bool in_boot(OamBootMsg *msg);

/**
 * @brief Get socket number from boot message
 * @param msg Boot message
 * @param version Boot version
 * @return Socket number
 */
int get_socket(OamBootMsg *msg, int version);

/**
 * @brief Get AID number from boot message
 * @param msg Boot message
 * @param version Boot version
 * @return AID number
 */
int get_aid(OamBootMsg *msg, int version);

/**
 * @brief Decode HBM stack value
 * @param stack Stack value
 * @return Decoded stack number or HBM_STACK_UNKNOWN
 */
int decode_hbm_stack(uint8_t stack);

/**
 * @brief Create JSON array of failed links
 * @param byte_value Byte containing link status bits
 * @param max_links Maximum number of links to check
 * @return JsonValue array or NULL on failure
 */
JsonValue* create_failed_links_array(uint8_t byte_value, int max_links);

/**
 * @brief Create hex string representation
 * @param value Value to convert
 * @param width Width of hex string (with padding)
 * @return Dynamically allocated hex string or NULL on failure
 */
char* create_hex_string(uint64_t value, int width);

// Decoder functions for Version 0
JsonValue* decode_hbm_training_v0(OamBootMsg *msg);
JsonValue* decode_fw_load_v0(OamBootMsg *msg);
JsonValue* decode_wafl_link_training_v0(OamBootMsg *msg);
JsonValue* decode_xgmi_link_training_v0(OamBootMsg *msg);
JsonValue* decode_usr_cp_link_training_v0(OamBootMsg *msg);
JsonValue* decode_usr_dp_link_training_v0(OamBootMsg *msg);
JsonValue* decode_hbm_mem_test_v0(OamBootMsg *msg);
JsonValue* decode_hbm_bist_test_v0(OamBootMsg *msg);
JsonValue* decode_boot_controller_generic_v0(OamBootMsg *msg);

// Decoder functions for Version 1
JsonValue* decode_hbm_training_v1(OamBootMsg *msg);
JsonValue* decode_fw_load_v1(OamBootMsg *msg);
JsonValue* decode_wafl_link_training_v1(OamBootMsg *msg);
JsonValue* decode_xgmi_link_training_v1(OamBootMsg *msg);
JsonValue* decode_usr_cp_link_training_v1(OamBootMsg *msg);
JsonValue* decode_usr_dp_link_training_v1(OamBootMsg *msg);
JsonValue* decode_hbm_mem_test_v1(OamBootMsg *msg);
JsonValue* decode_hbm_bist_test_v1(OamBootMsg *msg);
JsonValue* decode_boot_controller_generic_v1(OamBootMsg *msg);
JsonValue* decode_data_abort_v1(OamBootMsg *msg);
JsonValue* decode_boot_success_v1(OamBootMsg *msg);

// Unhandled error decoders
JsonValue* decode_unhandled_error_v0(OamBootMsg *msg);
JsonValue* decode_unhandled_error_v1(OamBootMsg *msg);

/**
 * @brief Get appropriate decoder function for boot message
 * @param msg Boot message
 * @return Decoder function pointer or NULL if no decoder found
 */
boot_decoder_func_t get_decoder_function(OamBootMsg *msg);

/**
 * @brief Orchestrate decoding of multiple boot messages
 * @param oam_boot_msgs Array of boot message values
 * @param count Number of boot messages
 * @return JsonValue object containing decoded results or NULL on failure
 */
JsonValue* boot_decode_orchestrator(uint64_t *oam_boot_msgs, size_t count);

#ifdef __cplusplus
}
#endif

#endif /* BOOT_DECODE_H */