This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdr.h
334 lines (297 loc) · 11.9 KB
/
pdr.h
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#ifndef PDR_H
#define PDR_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/** @struct pldm_pdr
* opaque structure that acts as a handle to a PDR repository
*/
typedef struct pldm_pdr pldm_pdr;
/** @struct pldm_pdr_record
* opaque structure that acts as a handle to a PDR record
*/
typedef struct pldm_pdr_record pldm_pdr_record;
/* ====================== */
/* Common PDR access APIs */
/* ====================== */
/** @brief Make a new PDR repository
*
* @return opaque pointer that acts as a handle to the repository; NULL if no
* repository could be created
*
* @note Caller may make multiple repositories (for its own PDRs, as well as
* for PDRs received by other entities) and can associate the returned handle
* to a PLDM terminus id.
*/
pldm_pdr *pldm_pdr_init();
/** @brief Destroy a PDR repository (and free up associated resources)
*
* @param[in/out] repo - pointer to opaque pointer acting as a PDR repo handle
*/
void pldm_pdr_destroy(pldm_pdr *repo);
/** @brief Get number of records in a PDR repository
*
* @param[in] repo - opaque pointer acting as a PDR repo handle
*
* @return uint32_t - number of records
*/
uint32_t pldm_pdr_get_record_count(const pldm_pdr *repo);
/** @brief Get size of a PDR repository, in bytes
*
* @param[in] repo - opaque pointer acting as a PDR repo handle
*
* @return uint32_t - size in bytes
*/
uint32_t pldm_pdr_get_repo_size(const pldm_pdr *repo);
/** @brief Add a PDR record to a PDR repository
*
* @param[in/out] repo - opaque pointer acting as a PDR repo handle
* @param[in] data - pointer to a PDR record, pointing to a PDR definition as
* per DSP0248. This data is memcpy'd.
* @param[in] size - size of input PDR record in bytes
* @param[in] record_handle - record handle of input PDR record; if this is set
* to 0, then a record handle is computed and assigned to this PDR record
* @param[in] is_remote - if true, then the PDR is not from this terminus
*
* @return uint32_t - record handle assigned to PDR record
*/
uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size,
uint32_t record_handle, bool is_remote);
/** @brief Get record handle of a PDR record
*
* @param[in] repo - opaque pointer acting as a PDR repo handle
* @param[in] record - opaque pointer acting as a PDR record handle
*
* @return uint32_t - record handle assigned to PDR record; 0 if record is not
* found
*/
uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo,
const pldm_pdr_record *record);
/** @brief Find PDR record by record handle
*
* @param[in] repo - opaque pointer acting as a PDR repo handle
* @param[in] record_handle - input record handle
* @param[in/out] data - will point to PDR record data (as per DSP0248) on
* return
* @param[out] size - *size will be size of PDR record
* @param[out] next_record_handle - *next_record_handle will be the record
* handle of record next to the returned PDR record
*
* @return opaque pointer acting as PDR record handle, will be NULL if record
* was not found
*/
const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo,
uint32_t record_handle,
uint8_t **data, uint32_t *size,
uint32_t *next_record_handle);
/** @brief Get PDR record next to input PDR record
*
* @param[in] repo - opaque pointer acting as a PDR repo handle
* @param[in] curr_record - opaque pointer acting as a PDR record handle
* @param[in/out] data - will point to PDR record data (as per DSP0248) on
* return
* @param[out] size - *size will be size of PDR record
* @param[out] next_record_handle - *next_record_handle will be the record
* handle of record nect to the returned PDR record
*
* @return opaque pointer acting as PDR record handle, will be NULL if record
* was not found
*/
const pldm_pdr_record *
pldm_pdr_get_next_record(const pldm_pdr *repo,
const pldm_pdr_record *curr_record, uint8_t **data,
uint32_t *size, uint32_t *next_record_handle);
/** @brief Find (first) PDR record by PDR type
*
* @param[in] repo - opaque pointer acting as a PDR repo handle
* @param[in] pdr_type - PDR type number as per DSP0248
* @param[in] curr_record - opaque pointer acting as a PDR record handle; if
* not NULL, then search will begin from this record's next record
* @param[in/out] data - will point to PDR record data (as per DSP0248) on
* return, if input is not NULL
* @param[out] size - *size will be size of PDR record, if input is not NULL
*
* @return opaque pointer acting as PDR record handle, will be NULL if record
* was not found
*/
const pldm_pdr_record *
pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type,
const pldm_pdr_record *curr_record, uint8_t **data,
uint32_t *size);
bool pldm_pdr_record_is_remote(const pldm_pdr_record *record);
/** @brief Remove all PDR records that belong to a remote terminus
*
* @param[in] repo - opaque pointer acting as a PDR repo handle
*/
void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo);
/* ======================= */
/* FRU Record Set PDR APIs */
/* ======================= */
/** @brief Add a FRU record set PDR record to a PDR repository
*
* @param[in/out] repo - opaque pointer acting as a PDR repo handle
* @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR
* record
* @param[in] fru_rsi - FRU record set identifier
* @param[in] entity_type - entity type of FRU
* @param[in] entity_instance_num - entity instance number of FRU
* @param[in] container_id - container id of FRU
*
* @return uint32_t - record handle assigned to PDR record
*/
uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle,
uint16_t fru_rsi, uint16_t entity_type,
uint16_t entity_instance_num,
uint16_t container_id);
/** @brief Find a FRU record set PDR by FRU record set identifier
*
* @param[in] repo - opaque pointer acting as a PDR repo handle
* @param[in] fru_rsi - FRU record set identifier
* @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of
* found PDR, or 0 if not found
* @param[in] entity_type - *entity_type will be FRU entity type of found PDR,
* or 0 if not found
* @param[in] entity_instance_num - *entity_instance_num will be FRU entity
* instance number of found PDR, or 0 if not found
* @param[in] container_id - *cintainer_id will be FRU container id of found
* PDR, or 0 if not found
*
* @return uint32_t - record handle assigned to PDR record
*/
const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi(
const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle,
uint16_t *entity_type, uint16_t *entity_instance_num,
uint16_t *container_id);
/* =========================== */
/* Entity Association PDR APIs */
/* =========================== */
typedef struct pldm_entity {
uint16_t entity_type;
uint16_t entity_instance_num;
uint16_t entity_container_id;
} __attribute__((packed)) pldm_entity;
enum entity_association_containment_type {
PLDM_ENTITY_ASSOCIAION_PHYSICAL = 0x0,
PLDM_ENTITY_ASSOCIAION_LOGICAL = 0x1,
};
/** @struct pldm_entity_association_tree
* opaque structure that represents the entity association hierarchy
*/
typedef struct pldm_entity_association_tree pldm_entity_association_tree;
/** @struct pldm_entity_node
* opaque structure that represents a node in the entity association hierarchy
*/
typedef struct pldm_entity_node pldm_entity_node;
/** @brief Make a new entity association tree
*
* @return opaque pointer that acts as a handle to the tree; NULL if no
* tree could be created
*/
pldm_entity_association_tree *pldm_entity_association_tree_init();
/** @brief Add an entity into the entity association tree
*
* @param[in/out] tree - opaque pointer acting as a handle to the tree
* @param[in/out] entity - pointer to the entity to be added. Input has the
* entity type. On output, instance number and the
* container id are populated.
* @param[in] parent - pointer to the node that should be the parent of input
* entity. If this is NULL, then the entity is the root
* @param[in] association_type - relation with the parent : logical or physical
*
* @return pldm_entity_node* - opaque pointer to added entity
*/
pldm_entity_node *
pldm_entity_association_tree_add(pldm_entity_association_tree *tree,
pldm_entity *entity, pldm_entity_node *parent,
uint8_t association_type);
/** @brief Visit and note each entity in the entity association tree
*
* @param[in] tree - opaque pointer acting as a handle to the tree
* @param[out] entities - pointer to list of pldm_entity's. To be free()'d by
* the caller
* @param[out] size - number of pldm_entity's
*/
void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree,
pldm_entity **entities, size_t *size);
/** @brief Destroy entity association tree
*
* @param[in] tree - opaque pointer acting as a handle to the tree
*/
void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree);
/** @brief Check if input enity node is a parent
*
* @param[in] node - opaque pointer acting as a handle to an entity node
*
* @return bool true if node is a parent, false otherwise
*/
bool pldm_entity_is_node_parent(pldm_entity_node *node);
/** @brief Convert entity association tree to PDR
*
* @param[in] tree - opaque pointer to entity association tree
* @param[in] repo - PDR repo where entity association records should be added
* @param[in] is_remote - if true, then the PDR is not from this terminus
*/
void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree,
pldm_pdr *repo, bool is_remote);
/** @brief Get number of children of entity
*
* @param[in] node - opaque pointer acting as a handle to an entity node
* @param[in] association_type - relation type filter : logical or physical
*
* @return uint8_t number of children
*/
uint8_t pldm_entity_get_num_children(pldm_entity_node *node,
uint8_t association_type);
/** @brief Find an entity in the entity association tree
*
* @param[in] tree - pointer to entity association tree
* @param[in/out] entity - entity type and instance id set on input, container
* id set on output
*
* @return pldm_entity_node* pointer to entity if found, NULL otherwise
*/
pldm_entity_node *
pldm_entity_association_tree_find(pldm_entity_association_tree *tree,
pldm_entity *entity);
/** @brief Extract entities from entity association PDR
*
* @param[in] pdr - entity association PDR
* @param[in] pdr_len - size of entity association PDR in bytes
* @param[out] num_entities - number of entities found, including the container
* @param[out] entities - extracted entities, container is *entities[0]. Caller
* must free *entities
*/
void pldm_entity_association_pdr_extract(const uint8_t *pdr, uint16_t pdr_len,
size_t *num_entities,
pldm_entity **entities);
/** @brief Parse Numeric Sensor PDR
*
* @param[in] pdr - Numeric Sensor PDR
* @param[in] pdr_len - size of Numeric Sensor PDR in bytes
* @param[out] numeric_sensor_pdr - parsed PDR will be writted to this
*
* @return bool true if the parsing success
* @note caller is responsible for alloc/dealloc of *pdr and
* *numeric_sensor_pdr
*/
bool pldm_numeric_sensor_pdr_parse(const uint8_t *pdr, const uint16_t pdr_len,
uint8_t *numeric_sensor_pdr);
/** @brief Parse Numeric Effecter PDR
*
* @param[in] pdr - Numeric Effecter PDR
* @param[in] pdr_len - size of Numeric Effecter PDR in bytes
* @param[out] numeric_effecter_pdr - parsed PDR will be writted to this
*
* @return bool true if the parsing success
* @note caller is responsible for alloc/dealloc of *pdr and
* *numeric_effecter_pdr
*/
bool pldm_numeric_effecter_pdr_parse(const uint8_t *pdr, const uint16_t pdr_len,
uint8_t *numeric_effecter_pdr);
#ifdef __cplusplus
}
#endif
#endif /* PDR_H */