Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1 | #ifndef PDR_H |
| 2 | #define PDR_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "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 | */ |
| 15 | typedef struct pldm_pdr pldm_pdr; |
| 16 | |
| 17 | /** @struct pldm_pdr_record |
| 18 | * opaque structure that acts as a handle to a PDR record |
| 19 | */ |
| 20 | typedef 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 Jeffery | 319304f | 2023-04-05 13:53:18 +0930 | [diff] [blame] | 35 | pldm_pdr *pldm_pdr_init(void); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 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 | */ |
| 41 | void 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 | */ |
| 49 | uint32_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 | */ |
| 57 | uint32_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 | */ |
| 72 | uint32_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 | */ |
| 84 | uint32_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 | */ |
| 100 | const 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 | */ |
| 118 | const pldm_pdr_record * |
| 119 | pldm_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 | */ |
| 136 | const pldm_pdr_record * |
| 137 | pldm_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 | |
| 141 | bool 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 | */ |
| 147 | void 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 | */ |
| 154 | void 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 Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 161 | * @param[in] terminus_handle - PLDM terminus handle |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 162 | * @param[in] tid - Terminus ID |
Andrew Jeffery | 2a38ab5 | 2023-04-06 15:09:08 +0930 | [diff] [blame] | 163 | * @param[in] tl_eid - MCTP endpoint EID |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 164 | * @param[in] valid - validity bit of TLPDR |
| 165 | */ |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 166 | /* NOLINTNEXTLINE(readability-identifier-naming) */ |
| 167 | void pldm_pdr_update_TL_pdr(const pldm_pdr *repo, uint16_t terminus_handle, |
| 168 | uint8_t tid, uint8_t tl_eid, bool valid); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 169 | |
Pavithra Barithaya | 4d69434 | 2023-05-19 08:04:41 -0500 | [diff] [blame] | 170 | /** @brief Find the last record within the particular range |
| 171 | * of record handles |
| 172 | * |
| 173 | * @param[in] repo - pointer acting as a PDR repo handle |
| 174 | * @param[in] first - first record handle value of the records in the range |
| 175 | * @param[in] last - last record handle value of the records in the range |
| 176 | * |
| 177 | * @return pointer to the PDR record,will be NULL if record was not |
| 178 | * found |
| 179 | */ |
| 180 | pldm_pdr_record *pldm_pdr_find_last_in_range(const pldm_pdr *repo, |
| 181 | uint32_t first, uint32_t last); |
| 182 | |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 183 | /** @brief find the container ID of the contained entity which is not in the |
| 184 | * particular range of record handles given |
| 185 | * |
| 186 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 187 | * @param[in] entity_type - entity type |
| 188 | * @param[in] entity_instance - instance of the entity |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame^] | 189 | * @param[in] child_index - index of the child entity whose container id needs to be found |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 190 | * @param[in] range_exclude_start_handle - first record handle in the range of the remote endpoint |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame^] | 191 | * which is ignored |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 192 | * @param[in] range_exclude_end_handle - last record handle in the range of the remote endpoint |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame^] | 193 | * which is ignored |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 194 | * @param[out] container_id - container id of the contained entity |
| 195 | * |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame^] | 196 | * @return container id of the PDR record found on success,-EINVAL when repo is NULL |
| 197 | * or -ENOKEY if the container id is not found. |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 198 | */ |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame^] | 199 | int pldm_pdr_find_child_container_id_index_range_exclude( |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 200 | const pldm_pdr *repo, uint16_t entity_type, uint16_t entity_instance, |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame^] | 201 | uint8_t child_index, uint32_t range_exclude_start_handle, |
| 202 | uint32_t range_exclude_end_handle, uint16_t *container_id); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 203 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 204 | /* ======================= */ |
| 205 | /* FRU Record Set PDR APIs */ |
| 206 | /* ======================= */ |
| 207 | |
| 208 | /** @brief Add a FRU record set PDR record to a PDR repository |
| 209 | * |
| 210 | * @param[in/out] repo - opaque pointer acting as a PDR repo handle |
| 211 | * @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR |
| 212 | * record |
| 213 | * @param[in] fru_rsi - FRU record set identifier |
| 214 | * @param[in] entity_type - entity type of FRU |
| 215 | * @param[in] entity_instance_num - entity instance number of FRU |
| 216 | * @param[in] container_id - container id of FRU |
| 217 | * @param[in] bmc_record_handle - handle used to construct the next record |
| 218 | * |
| 219 | * @return uint32_t - record handle assigned to PDR record |
| 220 | */ |
| 221 | uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle, |
| 222 | uint16_t fru_rsi, uint16_t entity_type, |
| 223 | uint16_t entity_instance_num, |
| 224 | uint16_t container_id, |
| 225 | uint32_t bmc_record_handle); |
| 226 | |
| 227 | /** @brief Find a FRU record set PDR by FRU record set identifier |
| 228 | * |
| 229 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 230 | * @param[in] fru_rsi - FRU record set identifier |
| 231 | * @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of |
| 232 | * found PDR, or 0 if not found |
| 233 | * @param[in] entity_type - *entity_type will be FRU entity type of found PDR, |
| 234 | * or 0 if not found |
| 235 | * @param[in] entity_instance_num - *entity_instance_num will be FRU entity |
| 236 | * instance number of found PDR, or 0 if not found |
| 237 | * @param[in] container_id - *cintainer_id will be FRU container id of found |
| 238 | * PDR, or 0 if not found |
| 239 | * |
| 240 | * @return uint32_t - record handle assigned to PDR record |
| 241 | */ |
| 242 | const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 243 | const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle, |
| 244 | uint16_t *entity_type, uint16_t *entity_instance_num, |
| 245 | uint16_t *container_id); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 246 | |
| 247 | /* =========================== */ |
| 248 | /* Entity Association PDR APIs */ |
| 249 | /* =========================== */ |
| 250 | |
| 251 | typedef struct pldm_entity { |
| 252 | uint16_t entity_type; |
| 253 | uint16_t entity_instance_num; |
| 254 | uint16_t entity_container_id; |
| 255 | } __attribute__((packed)) pldm_entity; |
| 256 | |
| 257 | enum entity_association_containment_type { |
| 258 | PLDM_ENTITY_ASSOCIAION_PHYSICAL = 0x0, |
| 259 | PLDM_ENTITY_ASSOCIAION_LOGICAL = 0x1, |
| 260 | }; |
| 261 | |
| 262 | /** @struct pldm_entity_association_tree |
| 263 | * opaque structure that represents the entity association hierarchy |
| 264 | */ |
| 265 | typedef struct pldm_entity_association_tree pldm_entity_association_tree; |
| 266 | |
| 267 | /** @struct pldm_entity_node |
| 268 | * opaque structure that represents a node in the entity association hierarchy |
| 269 | */ |
| 270 | typedef struct pldm_entity_node pldm_entity_node; |
| 271 | |
| 272 | /** @brief Make a new entity association tree |
| 273 | * |
| 274 | * @return opaque pointer that acts as a handle to the tree; NULL if no |
| 275 | * tree could be created |
| 276 | */ |
Andrew Jeffery | 319304f | 2023-04-05 13:53:18 +0930 | [diff] [blame] | 277 | pldm_entity_association_tree *pldm_entity_association_tree_init(void); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 278 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 279 | /** @brief Add a local entity into the entity association tree |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 280 | * |
| 281 | * @param[in/out] tree - opaque pointer acting as a handle to the tree |
| 282 | * @param[in/out] entity - pointer to the entity to be added. Input has the |
| 283 | * entity type. On output, instance number and the |
| 284 | * container id are populated. |
| 285 | * @param[in] entity_instance_number - entity instance number, we can use the |
| 286 | * entity instance number of the entity by |
| 287 | * default if its value is equal 0xFFFF. |
| 288 | * @param[in] parent - pointer to the node that should be the parent of input |
| 289 | * entity. If this is NULL, then the entity is the root |
| 290 | * @param[in] association_type - relation with the parent : logical or physical |
| 291 | * |
| 292 | * @return pldm_entity_node* - opaque pointer to added entity |
| 293 | */ |
| 294 | pldm_entity_node *pldm_entity_association_tree_add( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 295 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 296 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 297 | uint8_t association_type); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 298 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 299 | /** @brief Add an entity into the entity association tree based on remote field |
| 300 | * set or unset. |
| 301 | * |
| 302 | * @param[in/out] tree - opaque pointer acting as a handle to the tree |
| 303 | * @param[in/out] entity - pointer to the entity to be added. Input has the |
| 304 | * entity type. On output, instance number and the |
| 305 | * container id are populated. |
| 306 | * @param[in] entity_instance_number - entity instance number, we can use the |
| 307 | * entity instance number of the entity by |
| 308 | * default if its value is equal 0xFFFF. |
| 309 | * @param[in] parent - pointer to the node that should be the parent of input |
| 310 | * entity. If this is NULL, then the entity is the root |
| 311 | * @param[in] association_type - relation with the parent : logical or physical |
| 312 | * @param[in] is_remote - used to denote whether we are adding a BMC entity to |
| 313 | * the tree or a host entity |
| 314 | * @param[in] is_update_contanier_id - Used to determine whether need to update |
| 315 | * contanier id. |
| 316 | * true: should be changed |
| 317 | * false: should not be changed |
| 318 | * @param[in] container_id - container id of the entity added. |
| 319 | * |
| 320 | * @return pldm_entity_node* - opaque pointer to added entity |
| 321 | */ |
| 322 | pldm_entity_node *pldm_entity_association_tree_add_entity( |
| 323 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 324 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 325 | uint8_t association_type, bool is_remote, bool is_update_container_id, |
| 326 | uint16_t container_id); |
| 327 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 328 | /** @brief Visit and note each entity in the entity association tree |
| 329 | * |
| 330 | * @param[in] tree - opaque pointer acting as a handle to the tree |
| 331 | * @param[out] entities - pointer to list of pldm_entity's. To be free()'d by |
| 332 | * the caller |
| 333 | * @param[out] size - number of pldm_entity's |
| 334 | */ |
| 335 | void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree, |
| 336 | pldm_entity **entities, size_t *size); |
| 337 | |
| 338 | /** @brief Extract pldm entity by the pldm_entity_node |
| 339 | * |
| 340 | * @param[in] node - opaque pointer to added entity |
| 341 | * |
| 342 | * @return pldm_entity - pldm entity |
| 343 | */ |
| 344 | pldm_entity pldm_entity_extract(pldm_entity_node *node); |
| 345 | |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 346 | /** @brief Extract remote container id from the pldm_entity_node |
| 347 | * |
| 348 | * @param[in] entity - pointer to existing entity |
| 349 | * |
| 350 | * @param[out] cid - remote container id |
| 351 | */ |
| 352 | int pldm_entity_node_get_remote_container_id(const pldm_entity_node *entity, |
| 353 | uint16_t *cid); |
| 354 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 355 | /** @brief Destroy entity association tree |
| 356 | * |
| 357 | * @param[in] tree - opaque pointer acting as a handle to the tree |
| 358 | */ |
| 359 | void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree); |
| 360 | |
| 361 | /** @brief Check if input enity node is a parent |
| 362 | * |
| 363 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 364 | * |
| 365 | * @return bool true if node is a parent, false otherwise |
| 366 | */ |
| 367 | bool pldm_entity_is_node_parent(pldm_entity_node *node); |
| 368 | |
| 369 | /** @brief Get parent of entity |
| 370 | * |
| 371 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 372 | * |
| 373 | * @return pldm_entity - pldm entity |
| 374 | */ |
| 375 | pldm_entity pldm_entity_get_parent(pldm_entity_node *node); |
| 376 | |
| 377 | /** @brief Check the current pldm entity is exist parent |
| 378 | * |
| 379 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 380 | * |
| 381 | * @return bool true if exist parent, false otherwise |
| 382 | */ |
| 383 | bool pldm_entity_is_exist_parent(pldm_entity_node *node); |
| 384 | |
| 385 | /** @brief Convert entity association tree to PDR |
| 386 | * |
| 387 | * @param[in] tree - opaque pointer to entity association tree |
| 388 | * @param[in] repo - PDR repo where entity association records should be added |
| 389 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 390 | * @param[in] terminus_handle - terminus handle of the terminus |
| 391 | */ |
| 392 | void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree, |
| 393 | pldm_pdr *repo, bool is_remote, |
| 394 | uint16_t terminus_handle); |
| 395 | /** @brief Add entity association pdr from node |
| 396 | * |
| 397 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 398 | * @param[in] repo - PDR repo where entity association records should be added |
| 399 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 400 | * @param[in] terminus_handle - terminus handle of the terminus |
| 401 | */ |
| 402 | void pldm_entity_association_pdr_add_from_node( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 403 | pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities, |
| 404 | size_t num_entities, bool is_remote, uint16_t terminus_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 405 | |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame] | 406 | /** @brief Add entity association pdr record based on record handle |
| 407 | * earlier the records where added in a sequential way alone, with |
| 408 | * this change the entity association PDR records gets the new record |
| 409 | * handle based on the input value given. |
| 410 | * |
| 411 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 412 | * @param[in] repo - PDR repo where entity association records should be added |
| 413 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 414 | * @param[in] terminus_handle - terminus handle of the terminus |
| 415 | * @param[in] record_handle - record handle of the PDR |
| 416 | * |
| 417 | * @return 0 on succes, -EINVAL if the provided arguments are invalid. |
| 418 | */ |
| 419 | int pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 420 | pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities, |
| 421 | size_t num_entities, bool is_remote, uint16_t terminus_handle, |
| 422 | uint32_t record_handle); |
| 423 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 424 | /** @brief Find entity reference in tree |
| 425 | * |
| 426 | * @param[in] tree - opaque pointer to entity association tree |
| 427 | * @param[in] entity - PLDM entity |
| 428 | * @param[in] node - node to the entity |
| 429 | */ |
| 430 | void pldm_find_entity_ref_in_tree(pldm_entity_association_tree *tree, |
| 431 | pldm_entity entity, pldm_entity_node **node); |
| 432 | |
| 433 | /** @brief Get number of children of entity |
| 434 | * |
| 435 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 436 | * @param[in] association_type - relation type filter : logical or physical |
| 437 | * |
| 438 | * @return uint8_t number of children |
| 439 | */ |
| 440 | uint8_t pldm_entity_get_num_children(pldm_entity_node *node, |
| 441 | uint8_t association_type); |
| 442 | |
| 443 | /** @brief Verify that the current node is a child of the current parent |
| 444 | * |
| 445 | * @param[in] parent - opaque pointer acting as a handle to an entity parent |
| 446 | * @param[in] node - pointer to the node of the pldm entity |
| 447 | */ |
| 448 | bool pldm_is_current_parent_child(pldm_entity_node *parent, pldm_entity *node); |
| 449 | |
| 450 | /** @brief Find an entity in the entity association tree |
| 451 | * |
| 452 | * @param[in] tree - pointer to entity association tree |
| 453 | * @param[in/out] entity - entity type and instance id set on input, container |
| 454 | * id set on output |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 455 | * @return pldm_entity_node* pointer to entity if found, NULL otherwise |
| 456 | */ |
| 457 | pldm_entity_node * |
| 458 | pldm_entity_association_tree_find(pldm_entity_association_tree *tree, |
| 459 | pldm_entity *entity); |
| 460 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 461 | /** @brief Find an entity in the entity association tree if remote |
| 462 | * |
| 463 | * @param[in] tree - pointer to entity association tree |
| 464 | * @param[in/out] entity - entity type and instance id set on input, container |
| 465 | * id set on output |
| 466 | * @param[in] is_remote - variable to denote whether we are finding a host |
| 467 | * entity or a BMC entity |
| 468 | * |
| 469 | * @return pldm_entity_node* pointer to entity if found, NULL otherwise |
| 470 | */ |
| 471 | pldm_entity_node * |
| 472 | pldm_entity_association_tree_find_if_remote(pldm_entity_association_tree *tree, |
| 473 | pldm_entity *entity, |
| 474 | bool is_remote); |
| 475 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 476 | /** @brief Create a copy of an existing entity association tree |
| 477 | * |
| 478 | * @param[in] org_tree - pointer to source tree |
| 479 | * @param[in/out] new_tree - pointer to destination tree |
| 480 | */ |
| 481 | void pldm_entity_association_tree_copy_root( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 482 | pldm_entity_association_tree *org_tree, |
| 483 | pldm_entity_association_tree *new_tree); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 484 | |
| 485 | /** @brief Destroy all the nodes of the entity association tree |
| 486 | * |
| 487 | * @param[in] tree - pointer to entity association tree |
| 488 | */ |
| 489 | void pldm_entity_association_tree_destroy_root( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 490 | pldm_entity_association_tree *tree); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 491 | |
| 492 | /** @brief Check whether the entity association tree is empty |
| 493 | * |
| 494 | * @param[in] tree - pointer to entity association tree |
| 495 | * @return bool, true if tree is empty |
| 496 | */ |
| 497 | bool pldm_is_empty_entity_assoc_tree(pldm_entity_association_tree *tree); |
| 498 | |
| 499 | /** @brief Extract entities from entity association PDR |
| 500 | * |
| 501 | * @param[in] pdr - entity association PDR |
| 502 | * @param[in] pdr_len - size of entity association PDR in bytes |
| 503 | * @param[out] num_entities - number of entities found, including the container |
| 504 | * @param[out] entities - extracted entities, container is *entities[0]. Caller |
| 505 | * must free *entities |
| 506 | */ |
| 507 | void pldm_entity_association_pdr_extract(const uint8_t *pdr, uint16_t pdr_len, |
| 508 | size_t *num_entities, |
| 509 | pldm_entity **entities); |
| 510 | |
| 511 | #ifdef __cplusplus |
| 512 | } |
| 513 | #endif |
| 514 | |
| 515 | #endif /* PDR_H */ |