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 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 45 | * @pre repo must point to a valid object |
| 46 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 47 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 48 | * |
| 49 | * @return uint32_t - number of records |
| 50 | */ |
| 51 | uint32_t pldm_pdr_get_record_count(const pldm_pdr *repo); |
| 52 | |
| 53 | /** @brief Get size of a PDR repository, in bytes |
| 54 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 55 | * @pre repo must point to a valid object |
| 56 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 57 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 58 | * |
| 59 | * @return uint32_t - size in bytes |
| 60 | */ |
| 61 | uint32_t pldm_pdr_get_repo_size(const pldm_pdr *repo); |
| 62 | |
| 63 | /** @brief Add a PDR record to a PDR repository |
| 64 | * |
| 65 | * @param[in/out] repo - opaque pointer acting as a PDR repo handle |
| 66 | * @param[in] data - pointer to a PDR record, pointing to a PDR definition as |
| 67 | * per DSP0248. This data is memcpy'd. |
| 68 | * @param[in] size - size of input PDR record in bytes |
| 69 | * @param[in] record_handle - record handle of input PDR record; if this is set |
| 70 | * to 0, then a record handle is computed and assigned to this PDR record |
| 71 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 72 | * @param[in] terminus_handle - terminus handle of the input PDR record |
| 73 | * |
| 74 | * @return uint32_t - record handle assigned to PDR record |
| 75 | */ |
| 76 | uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size, |
| 77 | uint32_t record_handle, bool is_remote, |
| 78 | uint16_t terminus_handle); |
| 79 | |
| 80 | /** @brief Get record handle of a PDR record |
| 81 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 82 | * @pre repo must point to a valid object |
| 83 | * @pre record must point to a valid object |
| 84 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 85 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 86 | * @param[in] record - opaque pointer acting as a PDR record handle |
| 87 | * |
| 88 | * @return uint32_t - record handle assigned to PDR record; 0 if record is not |
| 89 | * found |
| 90 | */ |
| 91 | uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo, |
| 92 | const pldm_pdr_record *record); |
| 93 | |
| 94 | /** @brief Find PDR record by record handle |
| 95 | * |
| 96 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 97 | * @param[in] record_handle - input record handle |
| 98 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
| 99 | * return |
| 100 | * @param[out] size - *size will be size of PDR record |
| 101 | * @param[out] next_record_handle - *next_record_handle will be the record |
| 102 | * handle of record next to the returned PDR record |
| 103 | * |
| 104 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 105 | * was not found |
| 106 | */ |
| 107 | const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo, |
| 108 | uint32_t record_handle, |
| 109 | uint8_t **data, uint32_t *size, |
| 110 | uint32_t *next_record_handle); |
| 111 | |
| 112 | /** @brief Get PDR record next to input PDR record |
| 113 | * |
| 114 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 115 | * @param[in] curr_record - opaque pointer acting as a PDR record handle |
| 116 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
| 117 | * return |
| 118 | * @param[out] size - *size will be size of PDR record |
| 119 | * @param[out] next_record_handle - *next_record_handle will be the record |
| 120 | * handle of record nect to the returned PDR record |
| 121 | * |
| 122 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 123 | * was not found |
| 124 | */ |
| 125 | const pldm_pdr_record * |
| 126 | pldm_pdr_get_next_record(const pldm_pdr *repo, |
| 127 | const pldm_pdr_record *curr_record, uint8_t **data, |
| 128 | uint32_t *size, uint32_t *next_record_handle); |
| 129 | |
| 130 | /** @brief Find (first) PDR record by PDR type |
| 131 | * |
| 132 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 133 | * @param[in] pdr_type - PDR type number as per DSP0248 |
| 134 | * @param[in] curr_record - opaque pointer acting as a PDR record handle; if |
| 135 | * not NULL, then search will begin from this record's next record |
| 136 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
| 137 | * return, if input is not NULL |
| 138 | * @param[out] size - *size will be size of PDR record, if input is not NULL |
| 139 | * |
| 140 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 141 | * was not found |
| 142 | */ |
| 143 | const pldm_pdr_record * |
| 144 | pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type, |
| 145 | const pldm_pdr_record *curr_record, uint8_t **data, |
| 146 | uint32_t *size); |
| 147 | |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 148 | /** @brief Determine if a record is a remote record |
| 149 | * |
| 150 | * @pre record must point to a valid object |
| 151 | * |
| 152 | * @return true if the record is a remote record, false otherwise. |
| 153 | */ |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 154 | bool pldm_pdr_record_is_remote(const pldm_pdr_record *record); |
| 155 | |
| 156 | /** @brief Remove all PDR records that belong to a remote terminus |
| 157 | * |
| 158 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
Andrew Jeffery | 3e1d659 | 2023-07-03 11:57:16 +0930 | [diff] [blame] | 159 | * |
| 160 | * If repo is NULL then there are no PDRs that can be removed. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 161 | */ |
| 162 | void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo); |
| 163 | |
| 164 | /** @brief Remove all remote PDR's that beling to a specific terminus |
| 165 | * handle |
| 166 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 167 | * @param[in] terminus_handle - Terminus Handle of the remove PLDM terminus |
Andrew Jeffery | 438dd49 | 2023-07-03 11:51:43 +0930 | [diff] [blame] | 168 | * |
| 169 | * If repo is NULL there are no PDRs that can be removed. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 170 | */ |
| 171 | void pldm_pdr_remove_pdrs_by_terminus_handle(pldm_pdr *repo, |
| 172 | uint16_t terminus_handle); |
| 173 | |
| 174 | /** @brief Update the validity of TL PDR - the validity is decided based on |
| 175 | * whether the valid bit is set or not as per the spec DSP0248 |
| 176 | * |
| 177 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 178 | * @param[in] terminus_handle - PLDM terminus handle |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 179 | * @param[in] tid - Terminus ID |
Andrew Jeffery | 2a38ab5 | 2023-04-06 15:09:08 +0930 | [diff] [blame] | 180 | * @param[in] tl_eid - MCTP endpoint EID |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 181 | * @param[in] valid - validity bit of TLPDR |
| 182 | */ |
Andrew Jeffery | 6005f1c | 2023-04-05 20:02:52 +0930 | [diff] [blame] | 183 | /* NOLINTNEXTLINE(readability-identifier-naming) */ |
| 184 | void pldm_pdr_update_TL_pdr(const pldm_pdr *repo, uint16_t terminus_handle, |
| 185 | uint8_t tid, uint8_t tl_eid, bool valid); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 186 | |
Pavithra Barithaya | 4d69434 | 2023-05-19 08:04:41 -0500 | [diff] [blame] | 187 | /** @brief Find the last record within the particular range |
| 188 | * of record handles |
| 189 | * |
| 190 | * @param[in] repo - pointer acting as a PDR repo handle |
| 191 | * @param[in] first - first record handle value of the records in the range |
| 192 | * @param[in] last - last record handle value of the records in the range |
| 193 | * |
| 194 | * @return pointer to the PDR record,will be NULL if record was not |
| 195 | * found |
| 196 | */ |
| 197 | pldm_pdr_record *pldm_pdr_find_last_in_range(const pldm_pdr *repo, |
| 198 | uint32_t first, uint32_t last); |
| 199 | |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 200 | /** @brief find the container ID of the contained entity which is not in the |
| 201 | * particular range of record handles given |
| 202 | * |
| 203 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 204 | * @param[in] entity_type - entity type |
| 205 | * @param[in] entity_instance - instance of the entity |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 206 | * @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] | 207 | * @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] | 208 | * which is ignored |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 209 | * @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] | 210 | * which is ignored |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 211 | * @param[out] container_id - container id of the contained entity |
| 212 | * |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 213 | * @return container id of the PDR record found on success,-EINVAL when repo is NULL |
| 214 | * or -ENOKEY if the container id is not found. |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 215 | */ |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 216 | int pldm_pdr_find_child_container_id_index_range_exclude( |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 217 | const pldm_pdr *repo, uint16_t entity_type, uint16_t entity_instance, |
Pavithra Barithaya | 8cf7045 | 2023-06-22 04:36:19 -0500 | [diff] [blame] | 218 | uint8_t child_index, uint32_t range_exclude_start_handle, |
| 219 | uint32_t range_exclude_end_handle, uint16_t *container_id); |
Pavithra Barithaya | 5dc0257 | 2023-05-19 09:24:36 -0500 | [diff] [blame] | 220 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 221 | /* ======================= */ |
| 222 | /* FRU Record Set PDR APIs */ |
| 223 | /* ======================= */ |
| 224 | |
| 225 | /** @brief Add a FRU record set PDR record to a PDR repository |
| 226 | * |
| 227 | * @param[in/out] repo - opaque pointer acting as a PDR repo handle |
| 228 | * @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR |
| 229 | * record |
| 230 | * @param[in] fru_rsi - FRU record set identifier |
| 231 | * @param[in] entity_type - entity type of FRU |
| 232 | * @param[in] entity_instance_num - entity instance number of FRU |
| 233 | * @param[in] container_id - container id of FRU |
| 234 | * @param[in] bmc_record_handle - handle used to construct the next record |
| 235 | * |
| 236 | * @return uint32_t - record handle assigned to PDR record |
| 237 | */ |
| 238 | uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle, |
| 239 | uint16_t fru_rsi, uint16_t entity_type, |
| 240 | uint16_t entity_instance_num, |
| 241 | uint16_t container_id, |
| 242 | uint32_t bmc_record_handle); |
| 243 | |
| 244 | /** @brief Find a FRU record set PDR by FRU record set identifier |
| 245 | * |
| 246 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 247 | * @param[in] fru_rsi - FRU record set identifier |
| 248 | * @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of |
| 249 | * found PDR, or 0 if not found |
| 250 | * @param[in] entity_type - *entity_type will be FRU entity type of found PDR, |
| 251 | * or 0 if not found |
| 252 | * @param[in] entity_instance_num - *entity_instance_num will be FRU entity |
| 253 | * instance number of found PDR, or 0 if not found |
| 254 | * @param[in] container_id - *cintainer_id will be FRU container id of found |
| 255 | * PDR, or 0 if not found |
| 256 | * |
Andrew Jeffery | af7a4d8 | 2023-06-30 13:46:32 +0930 | [diff] [blame] | 257 | * @return An opaque pointer to the PDR record on success, or NULL on failure |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 258 | */ |
| 259 | const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 260 | const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle, |
| 261 | uint16_t *entity_type, uint16_t *entity_instance_num, |
| 262 | uint16_t *container_id); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 263 | |
| 264 | /* =========================== */ |
| 265 | /* Entity Association PDR APIs */ |
| 266 | /* =========================== */ |
| 267 | |
| 268 | typedef struct pldm_entity { |
| 269 | uint16_t entity_type; |
| 270 | uint16_t entity_instance_num; |
| 271 | uint16_t entity_container_id; |
| 272 | } __attribute__((packed)) pldm_entity; |
| 273 | |
| 274 | enum entity_association_containment_type { |
| 275 | PLDM_ENTITY_ASSOCIAION_PHYSICAL = 0x0, |
| 276 | PLDM_ENTITY_ASSOCIAION_LOGICAL = 0x1, |
| 277 | }; |
| 278 | |
| 279 | /** @struct pldm_entity_association_tree |
| 280 | * opaque structure that represents the entity association hierarchy |
| 281 | */ |
| 282 | typedef struct pldm_entity_association_tree pldm_entity_association_tree; |
| 283 | |
| 284 | /** @struct pldm_entity_node |
| 285 | * opaque structure that represents a node in the entity association hierarchy |
| 286 | */ |
| 287 | typedef struct pldm_entity_node pldm_entity_node; |
| 288 | |
| 289 | /** @brief Make a new entity association tree |
| 290 | * |
| 291 | * @return opaque pointer that acts as a handle to the tree; NULL if no |
| 292 | * tree could be created |
| 293 | */ |
Andrew Jeffery | 319304f | 2023-04-05 13:53:18 +0930 | [diff] [blame] | 294 | pldm_entity_association_tree *pldm_entity_association_tree_init(void); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 295 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 296 | /** @brief Add a local entity into the entity association tree |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 297 | * |
| 298 | * @param[in/out] tree - opaque pointer acting as a handle to the tree |
| 299 | * @param[in/out] entity - pointer to the entity to be added. Input has the |
| 300 | * entity type. On output, instance number and the |
| 301 | * container id are populated. |
| 302 | * @param[in] entity_instance_number - entity instance number, we can use the |
| 303 | * entity instance number of the entity by |
| 304 | * default if its value is equal 0xFFFF. |
| 305 | * @param[in] parent - pointer to the node that should be the parent of input |
| 306 | * entity. If this is NULL, then the entity is the root |
| 307 | * @param[in] association_type - relation with the parent : logical or physical |
| 308 | * |
| 309 | * @return pldm_entity_node* - opaque pointer to added entity |
| 310 | */ |
| 311 | pldm_entity_node *pldm_entity_association_tree_add( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 312 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 313 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 314 | uint8_t association_type); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 315 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 316 | /** @brief Add an entity into the entity association tree based on remote field |
| 317 | * set or unset. |
| 318 | * |
| 319 | * @param[in/out] tree - opaque pointer acting as a handle to the tree |
| 320 | * @param[in/out] entity - pointer to the entity to be added. Input has the |
| 321 | * entity type. On output, instance number and the |
| 322 | * container id are populated. |
| 323 | * @param[in] entity_instance_number - entity instance number, we can use the |
| 324 | * entity instance number of the entity by |
| 325 | * default if its value is equal 0xFFFF. |
| 326 | * @param[in] parent - pointer to the node that should be the parent of input |
| 327 | * entity. If this is NULL, then the entity is the root |
| 328 | * @param[in] association_type - relation with the parent : logical or physical |
| 329 | * @param[in] is_remote - used to denote whether we are adding a BMC entity to |
| 330 | * the tree or a host entity |
| 331 | * @param[in] is_update_contanier_id - Used to determine whether need to update |
| 332 | * contanier id. |
| 333 | * true: should be changed |
| 334 | * false: should not be changed |
| 335 | * @param[in] container_id - container id of the entity added. |
| 336 | * |
| 337 | * @return pldm_entity_node* - opaque pointer to added entity |
| 338 | */ |
| 339 | pldm_entity_node *pldm_entity_association_tree_add_entity( |
| 340 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 341 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 342 | uint8_t association_type, bool is_remote, bool is_update_container_id, |
| 343 | uint16_t container_id); |
| 344 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 345 | /** @brief Visit and note each entity in the entity association tree |
| 346 | * |
Andrew Jeffery | 8e9b0de | 2023-06-30 14:05:04 +0930 | [diff] [blame] | 347 | * @pre `*entities == NULL` and `*size == 0` must hold at the time of invocation. |
| 348 | * |
| 349 | * Callers must inspect the values of `*entities` and `*size` post-invocation to determine if the |
| 350 | * invocation was a success or failure. |
| 351 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 352 | * @param[in] tree - opaque pointer acting as a handle to the tree |
| 353 | * @param[out] entities - pointer to list of pldm_entity's. To be free()'d by |
| 354 | * the caller |
| 355 | * @param[out] size - number of pldm_entity's |
| 356 | */ |
| 357 | void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree, |
| 358 | pldm_entity **entities, size_t *size); |
| 359 | |
| 360 | /** @brief Extract pldm entity by the pldm_entity_node |
| 361 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 362 | * @pre node must point to a valid object |
| 363 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 364 | * @param[in] node - opaque pointer to added entity |
| 365 | * |
| 366 | * @return pldm_entity - pldm entity |
| 367 | */ |
| 368 | pldm_entity pldm_entity_extract(pldm_entity_node *node); |
| 369 | |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 370 | /** @brief Extract remote container id from the pldm_entity_node |
| 371 | * |
Andrew Jeffery | 15b8818 | 2023-06-30 13:29:17 +0930 | [diff] [blame] | 372 | * @pre entity must point to a valid object |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 373 | * |
Andrew Jeffery | 15b8818 | 2023-06-30 13:29:17 +0930 | [diff] [blame] | 374 | * @param[in] entity - pointer to existing entity |
| 375 | * |
| 376 | * @return The remote container id |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 377 | */ |
Andrew Jeffery | 15b8818 | 2023-06-30 13:29:17 +0930 | [diff] [blame] | 378 | uint16_t |
| 379 | pldm_entity_node_get_remote_container_id(const pldm_entity_node *entity); |
ArchanaKakani | 39bd2ea | 2023-02-02 02:39:18 -0600 | [diff] [blame] | 380 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 381 | /** @brief Destroy entity association tree |
| 382 | * |
| 383 | * @param[in] tree - opaque pointer acting as a handle to the tree |
| 384 | */ |
| 385 | void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree); |
| 386 | |
| 387 | /** @brief Check if input enity node is a parent |
| 388 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 389 | * @pre node must point to a valid object |
| 390 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 391 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 392 | * |
| 393 | * @return bool true if node is a parent, false otherwise |
| 394 | */ |
| 395 | bool pldm_entity_is_node_parent(pldm_entity_node *node); |
| 396 | |
| 397 | /** @brief Get parent of entity |
| 398 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 399 | * @pre node must point to a valid object |
| 400 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 401 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 402 | * |
| 403 | * @return pldm_entity - pldm entity |
| 404 | */ |
| 405 | pldm_entity pldm_entity_get_parent(pldm_entity_node *node); |
| 406 | |
| 407 | /** @brief Check the current pldm entity is exist parent |
| 408 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 409 | * @pre node must point to a valid object |
| 410 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 411 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 412 | * |
| 413 | * @return bool true if exist parent, false otherwise |
| 414 | */ |
| 415 | bool pldm_entity_is_exist_parent(pldm_entity_node *node); |
| 416 | |
| 417 | /** @brief Convert entity association tree to PDR |
| 418 | * |
Andrew Jeffery | c788348 | 2023-06-30 15:52:04 +0930 | [diff] [blame] | 419 | * No conversion takes place if one or both of tree or repo are NULL. |
| 420 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 421 | * @param[in] tree - opaque pointer to entity association tree |
| 422 | * @param[in] repo - PDR repo where entity association records should be added |
| 423 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 424 | * @param[in] terminus_handle - terminus handle of the terminus |
| 425 | */ |
| 426 | void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree, |
| 427 | pldm_pdr *repo, bool is_remote, |
| 428 | uint16_t terminus_handle); |
| 429 | /** @brief Add entity association pdr from node |
| 430 | * |
| 431 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 432 | * @param[in] repo - PDR repo where entity association records should be added |
| 433 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 434 | * @param[in] terminus_handle - terminus handle of the terminus |
| 435 | */ |
| 436 | void pldm_entity_association_pdr_add_from_node( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 437 | pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities, |
| 438 | size_t num_entities, bool is_remote, uint16_t terminus_handle); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 439 | |
Pavithra Barithaya | 25ddbcc | 2023-05-19 08:28:59 -0500 | [diff] [blame] | 440 | /** @brief Add entity association pdr record based on record handle |
| 441 | * earlier the records where added in a sequential way alone, with |
| 442 | * this change the entity association PDR records gets the new record |
| 443 | * handle based on the input value given. |
| 444 | * |
| 445 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 446 | * @param[in] repo - PDR repo where entity association records should be added |
| 447 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 448 | * @param[in] terminus_handle - terminus handle of the terminus |
| 449 | * @param[in] record_handle - record handle of the PDR |
| 450 | * |
| 451 | * @return 0 on succes, -EINVAL if the provided arguments are invalid. |
| 452 | */ |
| 453 | int pldm_entity_association_pdr_add_from_node_with_record_handle( |
| 454 | pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities, |
| 455 | size_t num_entities, bool is_remote, uint16_t terminus_handle, |
| 456 | uint32_t record_handle); |
| 457 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 458 | /** @brief Find entity reference in tree |
| 459 | * |
| 460 | * @param[in] tree - opaque pointer to entity association tree |
| 461 | * @param[in] entity - PLDM entity |
| 462 | * @param[in] node - node to the entity |
| 463 | */ |
| 464 | void pldm_find_entity_ref_in_tree(pldm_entity_association_tree *tree, |
| 465 | pldm_entity entity, pldm_entity_node **node); |
| 466 | |
| 467 | /** @brief Get number of children of entity |
| 468 | * |
| 469 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 470 | * @param[in] association_type - relation type filter : logical or physical |
| 471 | * |
Andrew Jeffery | 6e8a261 | 2023-06-30 15:36:48 +0930 | [diff] [blame] | 472 | * @return uint8_t number of children. The returned value is zero if node is NULL or |
| 473 | * association_type is not one of PLDM_ENTITY_ASSOCIAION_PHYSICAL or |
| 474 | * PLDM_ENTITY_ASSOCIAION_LOGICAL. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 475 | */ |
| 476 | uint8_t pldm_entity_get_num_children(pldm_entity_node *node, |
| 477 | uint8_t association_type); |
| 478 | |
| 479 | /** @brief Verify that the current node is a child of the current parent |
| 480 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 481 | * @pre parent must point to a valid object |
| 482 | * @pre node must point to a valid object |
| 483 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 484 | * @param[in] parent - opaque pointer acting as a handle to an entity parent |
| 485 | * @param[in] node - pointer to the node of the pldm entity |
Andrew Jeffery | 375d9fc | 2023-06-30 15:45:54 +0930 | [diff] [blame] | 486 | * |
| 487 | * @return True if the node is a child of parent, false otherwise, including if one or both of |
| 488 | * parent or node are NULL. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 489 | */ |
| 490 | bool pldm_is_current_parent_child(pldm_entity_node *parent, pldm_entity *node); |
| 491 | |
| 492 | /** @brief Find an entity in the entity association tree |
| 493 | * |
| 494 | * @param[in] tree - pointer to entity association tree |
| 495 | * @param[in/out] entity - entity type and instance id set on input, container |
| 496 | * id set on output |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 497 | * @return pldm_entity_node* pointer to entity if found, NULL otherwise |
Andrew Jeffery | 94e364d | 2023-07-03 12:26:59 +0930 | [diff] [blame] | 498 | * |
| 499 | * There are no entity nodes to search if tree is NULL, nor are there entity nodes to find if the |
| 500 | * search criteria are unspecified when entity is NULL. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 501 | */ |
| 502 | pldm_entity_node * |
| 503 | pldm_entity_association_tree_find(pldm_entity_association_tree *tree, |
| 504 | pldm_entity *entity); |
| 505 | |
Pavithra Barithaya | 9947f9d | 2023-05-18 05:20:24 -0500 | [diff] [blame] | 506 | /** @brief Find an entity in the entity association tree if remote |
| 507 | * |
| 508 | * @param[in] tree - pointer to entity association tree |
| 509 | * @param[in/out] entity - entity type and instance id set on input, container |
| 510 | * id set on output |
| 511 | * @param[in] is_remote - variable to denote whether we are finding a host |
| 512 | * entity or a BMC entity |
| 513 | * |
| 514 | * @return pldm_entity_node* pointer to entity if found, NULL otherwise |
| 515 | */ |
| 516 | pldm_entity_node * |
| 517 | pldm_entity_association_tree_find_if_remote(pldm_entity_association_tree *tree, |
| 518 | pldm_entity *entity, |
| 519 | bool is_remote); |
| 520 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 521 | /** @brief Create a copy of an existing entity association tree |
| 522 | * |
| 523 | * @param[in] org_tree - pointer to source tree |
| 524 | * @param[in/out] new_tree - pointer to destination tree |
| 525 | */ |
| 526 | void pldm_entity_association_tree_copy_root( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 527 | pldm_entity_association_tree *org_tree, |
| 528 | pldm_entity_association_tree *new_tree); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 529 | |
| 530 | /** @brief Destroy all the nodes of the entity association tree |
| 531 | * |
| 532 | * @param[in] tree - pointer to entity association tree |
Andrew Jeffery | 85d7a05 | 2023-07-03 12:29:24 +0930 | [diff] [blame] | 533 | * |
| 534 | * There is no tree to destroy if tree is NULL. |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 535 | */ |
| 536 | void pldm_entity_association_tree_destroy_root( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 537 | pldm_entity_association_tree *tree); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 538 | |
| 539 | /** @brief Check whether the entity association tree is empty |
| 540 | * |
Andrew Jeffery | 5565fcd | 2023-06-30 13:21:32 +0930 | [diff] [blame] | 541 | * @pre tree must point to a valid object |
| 542 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 543 | * @param[in] tree - pointer to entity association tree |
| 544 | * @return bool, true if tree is empty |
| 545 | */ |
| 546 | bool pldm_is_empty_entity_assoc_tree(pldm_entity_association_tree *tree); |
| 547 | |
| 548 | /** @brief Extract entities from entity association PDR |
| 549 | * |
Andrew Jeffery | 3a5c46b | 2023-07-03 12:39:59 +0930 | [diff] [blame^] | 550 | * @pre `*entities == NULL` and `*num_entities == 0` must hold at the time of invocation. |
| 551 | * |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 552 | * @param[in] pdr - entity association PDR |
| 553 | * @param[in] pdr_len - size of entity association PDR in bytes |
| 554 | * @param[out] num_entities - number of entities found, including the container |
| 555 | * @param[out] entities - extracted entities, container is *entities[0]. Caller |
| 556 | * must free *entities |
| 557 | */ |
| 558 | void pldm_entity_association_pdr_extract(const uint8_t *pdr, uint16_t pdr_len, |
| 559 | size_t *num_entities, |
| 560 | pldm_entity **entities); |
| 561 | |
| 562 | #ifdef __cplusplus |
| 563 | } |
| 564 | #endif |
| 565 | |
| 566 | #endif /* PDR_H */ |