blob: 75426244e76e372581fbc25ce055a0fa103de163 [file] [log] [blame]
Andrew Jeffery9c766792022-08-10 23:12:49 +09301#ifndef PDR_H
2#define PDR_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stdbool.h>
9#include <stddef.h>
10#include <stdint.h>
11
12/** @struct pldm_pdr
13 * opaque structure that acts as a handle to a PDR repository
14 */
15typedef struct pldm_pdr pldm_pdr;
16
17/** @struct pldm_pdr_record
18 * opaque structure that acts as a handle to a PDR record
19 */
20typedef struct pldm_pdr_record pldm_pdr_record;
21
22/* ====================== */
23/* Common PDR access APIs */
24/* ====================== */
25
26/** @brief Make a new PDR repository
27 *
28 * @return opaque pointer that acts as a handle to the repository; NULL if no
29 * repository could be created
30 *
31 * @note Caller may make multiple repositories (for its own PDRs, as well as
32 * for PDRs received by other entities) and can associate the returned handle
33 * to a PLDM terminus id.
34 */
Andrew Jeffery319304f2023-04-05 13:53:18 +093035pldm_pdr *pldm_pdr_init(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +093036
37/** @brief Destroy a PDR repository (and free up associated resources)
38 *
39 * @param[in/out] repo - pointer to opaque pointer acting as a PDR repo handle
40 */
41void pldm_pdr_destroy(pldm_pdr *repo);
42
43/** @brief Get number of records in a PDR repository
44 *
45 * @param[in] repo - opaque pointer acting as a PDR repo handle
46 *
47 * @return uint32_t - number of records
48 */
49uint32_t pldm_pdr_get_record_count(const pldm_pdr *repo);
50
51/** @brief Get size of a PDR repository, in bytes
52 *
53 * @param[in] repo - opaque pointer acting as a PDR repo handle
54 *
55 * @return uint32_t - size in bytes
56 */
57uint32_t pldm_pdr_get_repo_size(const pldm_pdr *repo);
58
59/** @brief Add a PDR record to a PDR repository
60 *
61 * @param[in/out] repo - opaque pointer acting as a PDR repo handle
62 * @param[in] data - pointer to a PDR record, pointing to a PDR definition as
63 * per DSP0248. This data is memcpy'd.
64 * @param[in] size - size of input PDR record in bytes
65 * @param[in] record_handle - record handle of input PDR record; if this is set
66 * to 0, then a record handle is computed and assigned to this PDR record
67 * @param[in] is_remote - if true, then the PDR is not from this terminus
68 * @param[in] terminus_handle - terminus handle of the input PDR record
69 *
70 * @return uint32_t - record handle assigned to PDR record
71 */
72uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size,
73 uint32_t record_handle, bool is_remote,
74 uint16_t terminus_handle);
75
76/** @brief Get record handle of a PDR record
77 *
78 * @param[in] repo - opaque pointer acting as a PDR repo handle
79 * @param[in] record - opaque pointer acting as a PDR record handle
80 *
81 * @return uint32_t - record handle assigned to PDR record; 0 if record is not
82 * found
83 */
84uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo,
85 const pldm_pdr_record *record);
86
87/** @brief Find PDR record by record handle
88 *
89 * @param[in] repo - opaque pointer acting as a PDR repo handle
90 * @param[in] record_handle - input record handle
91 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
92 * return
93 * @param[out] size - *size will be size of PDR record
94 * @param[out] next_record_handle - *next_record_handle will be the record
95 * handle of record next to the returned PDR record
96 *
97 * @return opaque pointer acting as PDR record handle, will be NULL if record
98 * was not found
99 */
100const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo,
101 uint32_t record_handle,
102 uint8_t **data, uint32_t *size,
103 uint32_t *next_record_handle);
104
105/** @brief Get PDR record next to input PDR record
106 *
107 * @param[in] repo - opaque pointer acting as a PDR repo handle
108 * @param[in] curr_record - opaque pointer acting as a PDR record handle
109 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
110 * return
111 * @param[out] size - *size will be size of PDR record
112 * @param[out] next_record_handle - *next_record_handle will be the record
113 * handle of record nect to the returned PDR record
114 *
115 * @return opaque pointer acting as PDR record handle, will be NULL if record
116 * was not found
117 */
118const pldm_pdr_record *
119pldm_pdr_get_next_record(const pldm_pdr *repo,
120 const pldm_pdr_record *curr_record, uint8_t **data,
121 uint32_t *size, uint32_t *next_record_handle);
122
123/** @brief Find (first) PDR record by PDR type
124 *
125 * @param[in] repo - opaque pointer acting as a PDR repo handle
126 * @param[in] pdr_type - PDR type number as per DSP0248
127 * @param[in] curr_record - opaque pointer acting as a PDR record handle; if
128 * not NULL, then search will begin from this record's next record
129 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
130 * return, if input is not NULL
131 * @param[out] size - *size will be size of PDR record, if input is not NULL
132 *
133 * @return opaque pointer acting as PDR record handle, will be NULL if record
134 * was not found
135 */
136const pldm_pdr_record *
137pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type,
138 const pldm_pdr_record *curr_record, uint8_t **data,
139 uint32_t *size);
140
141bool pldm_pdr_record_is_remote(const pldm_pdr_record *record);
142
143/** @brief Remove all PDR records that belong to a remote terminus
144 *
145 * @param[in] repo - opaque pointer acting as a PDR repo handle
146 */
147void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo);
148
149/** @brief Remove all remote PDR's that beling to a specific terminus
150 * handle
151 * @param[in] repo - opaque pointer acting as a PDR repo handle
152 * @param[in] terminus_handle - Terminus Handle of the remove PLDM terminus
153 */
154void pldm_pdr_remove_pdrs_by_terminus_handle(pldm_pdr *repo,
155 uint16_t terminus_handle);
156
157/** @brief Update the validity of TL PDR - the validity is decided based on
158 * whether the valid bit is set or not as per the spec DSP0248
159 *
160 * @param[in] repo - opaque pointer acting as a PDR repo handle
Andrew Jeffery6005f1c2023-04-05 20:02:52 +0930161 * @param[in] terminus_handle - PLDM terminus handle
Andrew Jeffery9c766792022-08-10 23:12:49 +0930162 * @param[in] tid - Terminus ID
Andrew Jeffery2a38ab52023-04-06 15:09:08 +0930163 * @param[in] tl_eid - MCTP endpoint EID
Andrew Jeffery9c766792022-08-10 23:12:49 +0930164 * @param[in] valid - validity bit of TLPDR
165 */
Andrew Jeffery6005f1c2023-04-05 20:02:52 +0930166/* NOLINTNEXTLINE(readability-identifier-naming) */
167void pldm_pdr_update_TL_pdr(const pldm_pdr *repo, uint16_t terminus_handle,
168 uint8_t tid, uint8_t tl_eid, bool valid);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930169
170/* ======================= */
171/* FRU Record Set PDR APIs */
172/* ======================= */
173
174/** @brief Add a FRU record set PDR record to a PDR repository
175 *
176 * @param[in/out] repo - opaque pointer acting as a PDR repo handle
177 * @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR
178 * record
179 * @param[in] fru_rsi - FRU record set identifier
180 * @param[in] entity_type - entity type of FRU
181 * @param[in] entity_instance_num - entity instance number of FRU
182 * @param[in] container_id - container id of FRU
183 * @param[in] bmc_record_handle - handle used to construct the next record
184 *
185 * @return uint32_t - record handle assigned to PDR record
186 */
187uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle,
188 uint16_t fru_rsi, uint16_t entity_type,
189 uint16_t entity_instance_num,
190 uint16_t container_id,
191 uint32_t bmc_record_handle);
192
193/** @brief Find a FRU record set PDR by FRU record set identifier
194 *
195 * @param[in] repo - opaque pointer acting as a PDR repo handle
196 * @param[in] fru_rsi - FRU record set identifier
197 * @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of
198 * found PDR, or 0 if not found
199 * @param[in] entity_type - *entity_type will be FRU entity type of found PDR,
200 * or 0 if not found
201 * @param[in] entity_instance_num - *entity_instance_num will be FRU entity
202 * instance number of found PDR, or 0 if not found
203 * @param[in] container_id - *cintainer_id will be FRU container id of found
204 * PDR, or 0 if not found
205 *
206 * @return uint32_t - record handle assigned to PDR record
207 */
208const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930209 const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle,
210 uint16_t *entity_type, uint16_t *entity_instance_num,
211 uint16_t *container_id);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930212
213/* =========================== */
214/* Entity Association PDR APIs */
215/* =========================== */
216
217typedef struct pldm_entity {
218 uint16_t entity_type;
219 uint16_t entity_instance_num;
220 uint16_t entity_container_id;
221} __attribute__((packed)) pldm_entity;
222
223enum entity_association_containment_type {
224 PLDM_ENTITY_ASSOCIAION_PHYSICAL = 0x0,
225 PLDM_ENTITY_ASSOCIAION_LOGICAL = 0x1,
226};
227
228/** @struct pldm_entity_association_tree
229 * opaque structure that represents the entity association hierarchy
230 */
231typedef struct pldm_entity_association_tree pldm_entity_association_tree;
232
233/** @struct pldm_entity_node
234 * opaque structure that represents a node in the entity association hierarchy
235 */
236typedef struct pldm_entity_node pldm_entity_node;
237
238/** @brief Make a new entity association tree
239 *
240 * @return opaque pointer that acts as a handle to the tree; NULL if no
241 * tree could be created
242 */
Andrew Jeffery319304f2023-04-05 13:53:18 +0930243pldm_entity_association_tree *pldm_entity_association_tree_init(void);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930244
Pavithra Barithaya9947f9d2023-05-18 05:20:24 -0500245/** @brief Add a local entity into the entity association tree
Andrew Jeffery9c766792022-08-10 23:12:49 +0930246 *
247 * @param[in/out] tree - opaque pointer acting as a handle to the tree
248 * @param[in/out] entity - pointer to the entity to be added. Input has the
249 * entity type. On output, instance number and the
250 * container id are populated.
251 * @param[in] entity_instance_number - entity instance number, we can use the
252 * entity instance number of the entity by
253 * default if its value is equal 0xFFFF.
254 * @param[in] parent - pointer to the node that should be the parent of input
255 * entity. If this is NULL, then the entity is the root
256 * @param[in] association_type - relation with the parent : logical or physical
257 *
258 * @return pldm_entity_node* - opaque pointer to added entity
259 */
260pldm_entity_node *pldm_entity_association_tree_add(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930261 pldm_entity_association_tree *tree, pldm_entity *entity,
262 uint16_t entity_instance_number, pldm_entity_node *parent,
263 uint8_t association_type);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930264
Pavithra Barithaya9947f9d2023-05-18 05:20:24 -0500265/** @brief Add an entity into the entity association tree based on remote field
266 * set or unset.
267 *
268 * @param[in/out] tree - opaque pointer acting as a handle to the tree
269 * @param[in/out] entity - pointer to the entity to be added. Input has the
270 * entity type. On output, instance number and the
271 * container id are populated.
272 * @param[in] entity_instance_number - entity instance number, we can use the
273 * entity instance number of the entity by
274 * default if its value is equal 0xFFFF.
275 * @param[in] parent - pointer to the node that should be the parent of input
276 * entity. If this is NULL, then the entity is the root
277 * @param[in] association_type - relation with the parent : logical or physical
278 * @param[in] is_remote - used to denote whether we are adding a BMC entity to
279 * the tree or a host entity
280 * @param[in] is_update_contanier_id - Used to determine whether need to update
281 * contanier id.
282 * true: should be changed
283 * false: should not be changed
284 * @param[in] container_id - container id of the entity added.
285 *
286 * @return pldm_entity_node* - opaque pointer to added entity
287 */
288pldm_entity_node *pldm_entity_association_tree_add_entity(
289 pldm_entity_association_tree *tree, pldm_entity *entity,
290 uint16_t entity_instance_number, pldm_entity_node *parent,
291 uint8_t association_type, bool is_remote, bool is_update_container_id,
292 uint16_t container_id);
293
Andrew Jeffery9c766792022-08-10 23:12:49 +0930294/** @brief Visit and note each entity in the entity association tree
295 *
296 * @param[in] tree - opaque pointer acting as a handle to the tree
297 * @param[out] entities - pointer to list of pldm_entity's. To be free()'d by
298 * the caller
299 * @param[out] size - number of pldm_entity's
300 */
301void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree,
302 pldm_entity **entities, size_t *size);
303
304/** @brief Extract pldm entity by the pldm_entity_node
305 *
306 * @param[in] node - opaque pointer to added entity
307 *
308 * @return pldm_entity - pldm entity
309 */
310pldm_entity pldm_entity_extract(pldm_entity_node *node);
311
ArchanaKakani39bd2ea2023-02-02 02:39:18 -0600312/** @brief Extract remote container id from the pldm_entity_node
313 *
314 * @param[in] entity - pointer to existing entity
315 *
316 * @param[out] cid - remote container id
317 */
318int pldm_entity_node_get_remote_container_id(const pldm_entity_node *entity,
319 uint16_t *cid);
320
Andrew Jeffery9c766792022-08-10 23:12:49 +0930321/** @brief Destroy entity association tree
322 *
323 * @param[in] tree - opaque pointer acting as a handle to the tree
324 */
325void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree);
326
327/** @brief Check if input enity node is a parent
328 *
329 * @param[in] node - opaque pointer acting as a handle to an entity node
330 *
331 * @return bool true if node is a parent, false otherwise
332 */
333bool pldm_entity_is_node_parent(pldm_entity_node *node);
334
335/** @brief Get parent of entity
336 *
337 * @param[in] node - opaque pointer acting as a handle to an entity node
338 *
339 * @return pldm_entity - pldm entity
340 */
341pldm_entity pldm_entity_get_parent(pldm_entity_node *node);
342
343/** @brief Check the current pldm entity is exist parent
344 *
345 * @param[in] node - opaque pointer acting as a handle to an entity node
346 *
347 * @return bool true if exist parent, false otherwise
348 */
349bool pldm_entity_is_exist_parent(pldm_entity_node *node);
350
351/** @brief Convert entity association tree to PDR
352 *
353 * @param[in] tree - opaque pointer to entity association tree
354 * @param[in] repo - PDR repo where entity association records should be added
355 * @param[in] is_remote - if true, then the PDR is not from this terminus
356 * @param[in] terminus_handle - terminus handle of the terminus
357 */
358void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree,
359 pldm_pdr *repo, bool is_remote,
360 uint16_t terminus_handle);
361/** @brief Add entity association pdr from node
362 *
363 * @param[in] node - opaque pointer acting as a handle to an entity node
364 * @param[in] repo - PDR repo where entity association records should be added
365 * @param[in] is_remote - if true, then the PDR is not from this terminus
366 * @param[in] terminus_handle - terminus handle of the terminus
367 */
368void pldm_entity_association_pdr_add_from_node(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930369 pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities,
370 size_t num_entities, bool is_remote, uint16_t terminus_handle);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930371
372/** @brief Find entity reference in tree
373 *
374 * @param[in] tree - opaque pointer to entity association tree
375 * @param[in] entity - PLDM entity
376 * @param[in] node - node to the entity
377 */
378void pldm_find_entity_ref_in_tree(pldm_entity_association_tree *tree,
379 pldm_entity entity, pldm_entity_node **node);
380
381/** @brief Get number of children of entity
382 *
383 * @param[in] node - opaque pointer acting as a handle to an entity node
384 * @param[in] association_type - relation type filter : logical or physical
385 *
386 * @return uint8_t number of children
387 */
388uint8_t pldm_entity_get_num_children(pldm_entity_node *node,
389 uint8_t association_type);
390
391/** @brief Verify that the current node is a child of the current parent
392 *
393 * @param[in] parent - opaque pointer acting as a handle to an entity parent
394 * @param[in] node - pointer to the node of the pldm entity
395 */
396bool pldm_is_current_parent_child(pldm_entity_node *parent, pldm_entity *node);
397
398/** @brief Find an entity in the entity association tree
399 *
400 * @param[in] tree - pointer to entity association tree
401 * @param[in/out] entity - entity type and instance id set on input, container
402 * id set on output
Andrew Jeffery9c766792022-08-10 23:12:49 +0930403 * @return pldm_entity_node* pointer to entity if found, NULL otherwise
404 */
405pldm_entity_node *
406pldm_entity_association_tree_find(pldm_entity_association_tree *tree,
407 pldm_entity *entity);
408
Pavithra Barithaya9947f9d2023-05-18 05:20:24 -0500409/** @brief Find an entity in the entity association tree if remote
410 *
411 * @param[in] tree - pointer to entity association tree
412 * @param[in/out] entity - entity type and instance id set on input, container
413 * id set on output
414 * @param[in] is_remote - variable to denote whether we are finding a host
415 * entity or a BMC entity
416 *
417 * @return pldm_entity_node* pointer to entity if found, NULL otherwise
418 */
419pldm_entity_node *
420pldm_entity_association_tree_find_if_remote(pldm_entity_association_tree *tree,
421 pldm_entity *entity,
422 bool is_remote);
423
Andrew Jeffery9c766792022-08-10 23:12:49 +0930424/** @brief Create a copy of an existing entity association tree
425 *
426 * @param[in] org_tree - pointer to source tree
427 * @param[in/out] new_tree - pointer to destination tree
428 */
429void pldm_entity_association_tree_copy_root(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930430 pldm_entity_association_tree *org_tree,
431 pldm_entity_association_tree *new_tree);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930432
433/** @brief Destroy all the nodes of the entity association tree
434 *
435 * @param[in] tree - pointer to entity association tree
436 */
437void pldm_entity_association_tree_destroy_root(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930438 pldm_entity_association_tree *tree);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930439
440/** @brief Check whether the entity association tree is empty
441 *
442 * @param[in] tree - pointer to entity association tree
443 * @return bool, true if tree is empty
444 */
445bool pldm_is_empty_entity_assoc_tree(pldm_entity_association_tree *tree);
446
447/** @brief Extract entities from entity association PDR
448 *
449 * @param[in] pdr - entity association PDR
450 * @param[in] pdr_len - size of entity association PDR in bytes
451 * @param[out] num_entities - number of entities found, including the container
452 * @param[out] entities - extracted entities, container is *entities[0]. Caller
453 * must free *entities
454 */
455void pldm_entity_association_pdr_extract(const uint8_t *pdr, uint16_t pdr_len,
456 size_t *num_entities,
457 pldm_entity **entities);
458
459#ifdef __cplusplus
460}
461#endif
462
463#endif /* PDR_H */