blob: c08dc5999fcdf79479e5c6ff47bdf94fd549f460 [file] [log] [blame]
Deepak Kodihalli3b02ed82020-02-06 01:18:25 -06001#ifndef PDR_H
2#define PDR_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Deepak Kodihalli05787052020-03-10 01:54:08 -05008#include <stdbool.h>
9#include <stddef.h>
Deepak Kodihalli3b02ed82020-02-06 01:18:25 -060010#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 */
35pldm_pdr *pldm_pdr_init();
36
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 *
68 * @return uint32_t - record handle assigned to PDR record
69 */
70uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size,
71 uint32_t record_handle);
72
73/** @brief Get record handle of a PDR record
74 *
75 * @param[in] repo - opaque pointer acting as a PDR repo handle
76 * @param[in] record - opaque pointer acting as a PDR record handle
77 *
78 * @return uint32_t - record handle assigned to PDR record; 0 if record is not
79 * found
80 */
81uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo,
82 const pldm_pdr_record *record);
83
84/** @brief Find PDR record by record handle
85 *
86 * @param[in] repo - opaque pointer acting as a PDR repo handle
87 * @param[in] record_handle - input record handle
88 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
89 * return
90 * @param[out] size - *size will be size of PDR record
91 * @param[out] next_record_handle - *next_record_handle will be the record
92 * handle of record next to the returned PDR record
93 *
94 * @return opaque pointer acting as PDR record handle, will be NULL if record
95 * was not found
96 */
97const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo,
98 uint32_t record_handle,
99 uint8_t **data, uint32_t *size,
100 uint32_t *next_record_handle);
101
102/** @brief Get PDR record next to input PDR record
103 *
104 * @param[in] repo - opaque pointer acting as a PDR repo handle
105 * @param[in] curr_record - opaque pointer acting as a PDR record handle
106 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
107 * return
108 * @param[out] size - *size will be size of PDR record
109 * @param[out] next_record_handle - *next_record_handle will be the record
110 * handle of record nect to the returned PDR record
111 *
112 * @return opaque pointer acting as PDR record handle, will be NULL if record
113 * was not found
114 */
115const pldm_pdr_record *
116pldm_pdr_get_next_record(const pldm_pdr *repo,
117 const pldm_pdr_record *curr_record, uint8_t **data,
118 uint32_t *size, uint32_t *next_record_handle);
119
120/** @brief Find (first) PDR record by PDR type
121 *
122 * @param[in] repo - opaque pointer acting as a PDR repo handle
123 * @param[in] pdr_type - PDR type number as per DSP0248
124 * @param[in] curr_record - opaque pointer acting as a PDR record handle; if
125 * not NULL, then search will begin from this record's next record
126 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
127 * return
128 * @param[out] size - *size will be size of PDR record
129 *
130 * @return opaque pointer acting as PDR record handle, will be NULL if record
131 * was not found
132 */
133const pldm_pdr_record *
134pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type,
135 const pldm_pdr_record *curr_record, uint8_t **data,
136 uint32_t *size);
137
Deepak Kodihallidb914672020-02-07 02:47:45 -0600138/* ======================= */
139/* FRU Record Set PDR APIs */
140/* ======================= */
141
142/** @brief Add a FRU record set PDR record to a PDR repository
143 *
144 * @param[in/out] repo - opaque pointer acting as a PDR repo handle
145 * @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR
146 * record
147 * @param[in] fru_rsi - FRU record set identifier
148 * @param[in] entity_type - entity type of FRU
149 * @param[in] entity_instance_num - entity instance number of FRU
150 * @param[in] container_id - container id of FRU
151 *
152 * @return uint32_t - record handle assigned to PDR record
153 */
154uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle,
155 uint16_t fru_rsi, uint16_t entity_type,
156 uint16_t entity_instance_num,
157 uint16_t container_id);
158
159/** @brief Find a FRU record set PDR by FRU record set identifier
160 *
161 * @param[in] repo - opaque pointer acting as a PDR repo handle
162 * @param[in] fru_rsi - FRU record set identifier
163 * @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of
164 * found PDR, or 0 if not found
165 * @param[in] entity_type - *entity_type will be FRU entity type of found PDR,
166 * or 0 if not found
167 * @param[in] entity_instance_num - *entity_instance_num will be FRU entity
168 * instance number of found PDR, or 0 if not found
169 * @param[in] container_id - *cintainer_id will be FRU container id of found
170 * PDR, or 0 if not found
171 *
172 * @return uint32_t - record handle assigned to PDR record
173 */
174const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi(
175 const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle,
176 uint16_t *entity_type, uint16_t *entity_instance_num,
177 uint16_t *container_id);
178
Deepak Kodihalli05787052020-03-10 01:54:08 -0500179/* =========================== */
180/* Entity Association PDR APIs */
181/* =========================== */
182
183typedef struct pldm_entity {
184 uint16_t entity_type;
185 uint16_t entity_instance_num;
186 uint16_t entity_container_id;
187} __attribute__((packed)) pldm_entity;
188
189enum entity_association_containment_type {
190 PLDM_ENTITY_ASSOCIAION_PHYSICAL = 0x0,
Deepak Kodihalli0a738f02020-03-10 01:56:21 -0500191 PLDM_ENTITY_ASSOCIAION_LOGICAL = 0x1,
Deepak Kodihalli05787052020-03-10 01:54:08 -0500192};
193
194/** @struct pldm_entity_association_tree
195 * opaque structure that represents the entity association hierarchy
196 */
197typedef struct pldm_entity_association_tree pldm_entity_association_tree;
198
199/** @struct pldm_entity_node
200 * opaque structure that represents a node in the entity association hierarchy
201 */
202typedef struct pldm_entity_node pldm_entity_node;
203
204/** @brief Make a new entity association tree
205 *
206 * @return opaque pointer that acts as a handle to the tree; NULL if no
207 * tree could be created
208 */
209pldm_entity_association_tree *pldm_entity_association_tree_init();
210
211/** @brief Add an entity into the entity association tree
212 *
213 * @param[in/out] tree - opaque pointer acting as a handle to the tree
214 * @param[in/out] entity - pointer to the entity to be added. Input has the
215 * entity type. On output, instance number and the
216 * container id are populated.
217 * @param[in] parent - pointer to the node that should be the parent of input
218 * entity. If this is NULL, then the entity is the root
219 * @param[in] association_type - relation with the parent : logical or physical
220 *
221 * @return pldm_entity_node* - opaque pointer to added entity
222 */
223pldm_entity_node *
224pldm_entity_association_tree_add(pldm_entity_association_tree *tree,
225 pldm_entity *entity, pldm_entity_node *parent,
226 uint8_t association_type);
227
228/** @brief Visit and note each entity in the entity association tree
229 *
230 * @param[in] tree - opaque pointer acting as a handle to the tree
231 * @param[out] entities - pointer to list of pldm_entity's. To be free()'d by
232 * the caller
233 * @param[out] size - number of pldm_entity's
234 */
235void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree,
236 pldm_entity **entities, size_t *size);
237
238/** @brief Destroy entity association tree
239 *
240 * @param[in] tree - opaque pointer acting as a handle to the tree
241 */
242void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree);
243
244/** @brief Check if input enity node is a parent
245 *
246 * @param[in] node - opaque pointer acting as a handle to an entity node
247 *
248 * @return bool true if node is a parent, false otherwise
249 */
250bool pldm_entity_is_node_parent(pldm_entity_node *node);
251
Deepak Kodihalli0a738f02020-03-10 01:56:21 -0500252/** @brief Convert entity association tree to PDR
253 *
254 * @param[in] tree - opaque pointer to entity association tree
255 * @param[in] repo - PDR repo where entity association records should be added
256 */
257void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree,
258 pldm_pdr *repo);
259
260/** @brief Get number of children of entity
261 *
262 * @param[in] node - opaque pointer acting as a handle to an entity node
263 * @param[in] association_type - relation type filter : logical or physical
264 *
265 * @return uint8_t number of children
266 */
267uint8_t pldm_entity_get_num_children(pldm_entity_node *node,
268 uint8_t association_type);
269
Deepak Kodihalli3b02ed82020-02-06 01:18:25 -0600270#ifdef __cplusplus
271}
272#endif
273
274#endif /* PDR_H */