Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 1 | #ifndef PDR_H |
| 2 | #define PDR_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 8 | #include <stdbool.h> |
| 9 | #include <stddef.h> |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 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 | */ |
| 35 | pldm_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 | */ |
| 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 |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 67 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 68 | * |
| 69 | * @return uint32_t - record handle assigned to PDR record |
| 70 | */ |
| 71 | uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size, |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 72 | uint32_t record_handle, bool is_remote); |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 73 | |
| 74 | /** @brief Get record handle of a PDR record |
| 75 | * |
| 76 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 77 | * @param[in] record - opaque pointer acting as a PDR record handle |
| 78 | * |
| 79 | * @return uint32_t - record handle assigned to PDR record; 0 if record is not |
| 80 | * found |
| 81 | */ |
| 82 | uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo, |
| 83 | const pldm_pdr_record *record); |
| 84 | |
| 85 | /** @brief Find PDR record by record handle |
| 86 | * |
| 87 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 88 | * @param[in] record_handle - input record handle |
| 89 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
| 90 | * return |
| 91 | * @param[out] size - *size will be size of PDR record |
| 92 | * @param[out] next_record_handle - *next_record_handle will be the record |
| 93 | * handle of record next to the returned PDR record |
| 94 | * |
| 95 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 96 | * was not found |
| 97 | */ |
| 98 | const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo, |
| 99 | uint32_t record_handle, |
| 100 | uint8_t **data, uint32_t *size, |
| 101 | uint32_t *next_record_handle); |
| 102 | |
| 103 | /** @brief Get PDR record next to input PDR record |
| 104 | * |
| 105 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 106 | * @param[in] curr_record - opaque pointer acting as a PDR record handle |
| 107 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
| 108 | * return |
| 109 | * @param[out] size - *size will be size of PDR record |
| 110 | * @param[out] next_record_handle - *next_record_handle will be the record |
| 111 | * handle of record nect to the returned PDR record |
| 112 | * |
| 113 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 114 | * was not found |
| 115 | */ |
| 116 | const pldm_pdr_record * |
| 117 | pldm_pdr_get_next_record(const pldm_pdr *repo, |
| 118 | const pldm_pdr_record *curr_record, uint8_t **data, |
| 119 | uint32_t *size, uint32_t *next_record_handle); |
| 120 | |
| 121 | /** @brief Find (first) PDR record by PDR type |
| 122 | * |
| 123 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 124 | * @param[in] pdr_type - PDR type number as per DSP0248 |
| 125 | * @param[in] curr_record - opaque pointer acting as a PDR record handle; if |
| 126 | * not NULL, then search will begin from this record's next record |
| 127 | * @param[in/out] data - will point to PDR record data (as per DSP0248) on |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 128 | * return, if input is not NULL |
| 129 | * @param[out] size - *size will be size of PDR record, if input is not NULL |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 130 | * |
| 131 | * @return opaque pointer acting as PDR record handle, will be NULL if record |
| 132 | * was not found |
| 133 | */ |
| 134 | const pldm_pdr_record * |
| 135 | pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type, |
| 136 | const pldm_pdr_record *curr_record, uint8_t **data, |
| 137 | uint32_t *size); |
| 138 | |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 139 | bool pldm_pdr_record_is_remote(const pldm_pdr_record *record); |
| 140 | |
Deepak Kodihalli | 4a68093 | 2020-04-22 03:31:17 -0500 | [diff] [blame] | 141 | /** @brief Remove all PDR records that belong to a remote terminus |
| 142 | * |
| 143 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 144 | */ |
| 145 | void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo); |
| 146 | |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 147 | /** @brief Update the validity of TL PDR - the validity is decided based on |
| 148 | * whether the valid bit is set or not as per the spec DSP0248 |
| 149 | * |
| 150 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 151 | * @param[in] terminusHandle - PLDM terminus handle |
| 152 | * @param[in] tid - Terminus ID |
| 153 | * @param[in] tlEid - MCTP endpoint EID |
| 154 | * @param[in] valid - validity bit of TLPDR |
| 155 | */ |
| 156 | void pldm_pdr_update_TL_pdr(const pldm_pdr *repo, uint16_t terminusHandle, |
| 157 | uint8_t tid, uint8_t tlEid, bool valid); |
| 158 | |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 159 | /* ======================= */ |
| 160 | /* FRU Record Set PDR APIs */ |
| 161 | /* ======================= */ |
| 162 | |
| 163 | /** @brief Add a FRU record set PDR record to a PDR repository |
| 164 | * |
| 165 | * @param[in/out] repo - opaque pointer acting as a PDR repo handle |
| 166 | * @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR |
| 167 | * record |
| 168 | * @param[in] fru_rsi - FRU record set identifier |
| 169 | * @param[in] entity_type - entity type of FRU |
| 170 | * @param[in] entity_instance_num - entity instance number of FRU |
| 171 | * @param[in] container_id - container id of FRU |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 172 | * @param[in] bmc_record_handle - handle used to construct the next record |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 173 | * |
| 174 | * @return uint32_t - record handle assigned to PDR record |
| 175 | */ |
| 176 | uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle, |
| 177 | uint16_t fru_rsi, uint16_t entity_type, |
| 178 | uint16_t entity_instance_num, |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 179 | uint16_t container_id, |
| 180 | uint32_t bmc_record_handle); |
Deepak Kodihalli | db91467 | 2020-02-07 02:47:45 -0600 | [diff] [blame] | 181 | |
| 182 | /** @brief Find a FRU record set PDR by FRU record set identifier |
| 183 | * |
| 184 | * @param[in] repo - opaque pointer acting as a PDR repo handle |
| 185 | * @param[in] fru_rsi - FRU record set identifier |
| 186 | * @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of |
| 187 | * found PDR, or 0 if not found |
| 188 | * @param[in] entity_type - *entity_type will be FRU entity type of found PDR, |
| 189 | * or 0 if not found |
| 190 | * @param[in] entity_instance_num - *entity_instance_num will be FRU entity |
| 191 | * instance number of found PDR, or 0 if not found |
| 192 | * @param[in] container_id - *cintainer_id will be FRU container id of found |
| 193 | * PDR, or 0 if not found |
| 194 | * |
| 195 | * @return uint32_t - record handle assigned to PDR record |
| 196 | */ |
| 197 | const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi( |
| 198 | const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle, |
| 199 | uint16_t *entity_type, uint16_t *entity_instance_num, |
| 200 | uint16_t *container_id); |
| 201 | |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 202 | /* =========================== */ |
| 203 | /* Entity Association PDR APIs */ |
| 204 | /* =========================== */ |
| 205 | |
| 206 | typedef struct pldm_entity { |
| 207 | uint16_t entity_type; |
| 208 | uint16_t entity_instance_num; |
| 209 | uint16_t entity_container_id; |
| 210 | } __attribute__((packed)) pldm_entity; |
| 211 | |
| 212 | enum entity_association_containment_type { |
| 213 | PLDM_ENTITY_ASSOCIAION_PHYSICAL = 0x0, |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 214 | PLDM_ENTITY_ASSOCIAION_LOGICAL = 0x1, |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | /** @struct pldm_entity_association_tree |
| 218 | * opaque structure that represents the entity association hierarchy |
| 219 | */ |
| 220 | typedef struct pldm_entity_association_tree pldm_entity_association_tree; |
| 221 | |
| 222 | /** @struct pldm_entity_node |
| 223 | * opaque structure that represents a node in the entity association hierarchy |
| 224 | */ |
| 225 | typedef struct pldm_entity_node pldm_entity_node; |
| 226 | |
| 227 | /** @brief Make a new entity association tree |
| 228 | * |
| 229 | * @return opaque pointer that acts as a handle to the tree; NULL if no |
| 230 | * tree could be created |
| 231 | */ |
| 232 | pldm_entity_association_tree *pldm_entity_association_tree_init(); |
| 233 | |
| 234 | /** @brief Add an entity into the entity association tree |
| 235 | * |
| 236 | * @param[in/out] tree - opaque pointer acting as a handle to the tree |
| 237 | * @param[in/out] entity - pointer to the entity to be added. Input has the |
| 238 | * entity type. On output, instance number and the |
| 239 | * container id are populated. |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 240 | * @param[in] entity_instance_number - entity instance number, we can use the |
| 241 | * entity instance number of the entity by |
| 242 | * default if its value is equal 0xFFFF. |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 243 | * @param[in] parent - pointer to the node that should be the parent of input |
| 244 | * entity. If this is NULL, then the entity is the root |
| 245 | * @param[in] association_type - relation with the parent : logical or physical |
| 246 | * |
| 247 | * @return pldm_entity_node* - opaque pointer to added entity |
| 248 | */ |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 249 | pldm_entity_node *pldm_entity_association_tree_add( |
| 250 | pldm_entity_association_tree *tree, pldm_entity *entity, |
| 251 | uint16_t entity_instance_number, pldm_entity_node *parent, |
| 252 | uint8_t association_type); |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 253 | |
| 254 | /** @brief Visit and note each entity in the entity association tree |
| 255 | * |
| 256 | * @param[in] tree - opaque pointer acting as a handle to the tree |
| 257 | * @param[out] entities - pointer to list of pldm_entity's. To be free()'d by |
| 258 | * the caller |
| 259 | * @param[out] size - number of pldm_entity's |
| 260 | */ |
| 261 | void pldm_entity_association_tree_visit(pldm_entity_association_tree *tree, |
| 262 | pldm_entity **entities, size_t *size); |
| 263 | |
George Liu | d9855ab | 2021-05-13 09:41:31 +0800 | [diff] [blame] | 264 | /** @brief Extract pldm entity by the pldm_entity_node |
| 265 | * |
| 266 | * @param[in] node - opaque pointer to added entity |
| 267 | * |
| 268 | * @return pldm_entity - pldm entity |
| 269 | */ |
| 270 | pldm_entity pldm_entity_extract(pldm_entity_node *node); |
| 271 | |
Deepak Kodihalli | 0578705 | 2020-03-10 01:54:08 -0500 | [diff] [blame] | 272 | /** @brief Destroy entity association tree |
| 273 | * |
| 274 | * @param[in] tree - opaque pointer acting as a handle to the tree |
| 275 | */ |
| 276 | void pldm_entity_association_tree_destroy(pldm_entity_association_tree *tree); |
| 277 | |
| 278 | /** @brief Check if input enity node is a parent |
| 279 | * |
| 280 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 281 | * |
| 282 | * @return bool true if node is a parent, false otherwise |
| 283 | */ |
| 284 | bool pldm_entity_is_node_parent(pldm_entity_node *node); |
| 285 | |
George Liu | fe77eea | 2021-04-28 15:08:07 +0800 | [diff] [blame] | 286 | /** @brief Get parent of entity |
| 287 | * |
| 288 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 289 | * |
George Liu | b6b3cf3 | 2021-06-07 16:30:59 +0800 | [diff] [blame] | 290 | * @return pldm_entity - pldm entity |
George Liu | fe77eea | 2021-04-28 15:08:07 +0800 | [diff] [blame] | 291 | */ |
George Liu | b6b3cf3 | 2021-06-07 16:30:59 +0800 | [diff] [blame] | 292 | pldm_entity pldm_entity_get_parent(pldm_entity_node *node); |
| 293 | |
| 294 | /** @brief Check the current pldm entity is exist parent |
| 295 | * |
| 296 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 297 | * |
| 298 | * @return bool true if exist parent, false otherwise |
| 299 | */ |
| 300 | bool pldm_entity_is_exist_parent(pldm_entity_node *node); |
George Liu | fe77eea | 2021-04-28 15:08:07 +0800 | [diff] [blame] | 301 | |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 302 | /** @brief Convert entity association tree to PDR |
| 303 | * |
| 304 | * @param[in] tree - opaque pointer to entity association tree |
| 305 | * @param[in] repo - PDR repo where entity association records should be added |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 306 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 307 | */ |
| 308 | void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree, |
Deepak Kodihalli | 87514cc | 2020-04-16 09:08:38 -0500 | [diff] [blame] | 309 | pldm_pdr *repo, bool is_remote); |
Sampa Misra | 719ed39 | 2021-06-04 05:15:13 -0500 | [diff] [blame] | 310 | /** @brief Add entity association pdr from node |
| 311 | * |
| 312 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 313 | * @param[in] repo - PDR repo where entity association records should be added |
| 314 | * @param[in] is_remote - if true, then the PDR is not from this terminus |
| 315 | */ |
| 316 | void pldm_entity_association_pdr_add_from_node(pldm_entity_node *node, |
| 317 | pldm_pdr *repo, |
| 318 | pldm_entity **entities, |
| 319 | size_t num_entities, |
| 320 | bool is_remote); |
| 321 | |
| 322 | /** @brief Find entity reference in tree |
| 323 | * |
| 324 | * @param[in] tree - opaque pointer to entity association tree |
| 325 | * @param[in] entity - PLDM entity |
| 326 | * @param[in] node - node to the entity |
| 327 | */ |
| 328 | void pldm_find_entity_ref_in_tree(pldm_entity_association_tree *tree, |
| 329 | pldm_entity entity, pldm_entity_node **node); |
Deepak Kodihalli | 0a738f0 | 2020-03-10 01:56:21 -0500 | [diff] [blame] | 330 | |
| 331 | /** @brief Get number of children of entity |
| 332 | * |
| 333 | * @param[in] node - opaque pointer acting as a handle to an entity node |
| 334 | * @param[in] association_type - relation type filter : logical or physical |
| 335 | * |
| 336 | * @return uint8_t number of children |
| 337 | */ |
| 338 | uint8_t pldm_entity_get_num_children(pldm_entity_node *node, |
| 339 | uint8_t association_type); |
| 340 | |
George Liu | 6a6c3ab | 2021-06-22 16:12:42 +0800 | [diff] [blame] | 341 | /** @brief Verify that the current node is a child of the current parent |
| 342 | * |
| 343 | * @param[in] parent - opaque pointer acting as a handle to an entity parent |
| 344 | * @param[in] node - pointer to the node of the pldm entity |
| 345 | */ |
| 346 | bool pldm_is_current_parent_child(pldm_entity_node *parent, pldm_entity *node); |
| 347 | |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 348 | /** @brief Find an entity in the entity association tree |
| 349 | * |
| 350 | * @param[in] tree - pointer to entity association tree |
| 351 | * @param[in/out] entity - entity type and instance id set on input, container |
| 352 | * id set on output |
| 353 | * |
| 354 | * @return pldm_entity_node* pointer to entity if found, NULL otherwise |
| 355 | */ |
| 356 | pldm_entity_node * |
| 357 | pldm_entity_association_tree_find(pldm_entity_association_tree *tree, |
| 358 | pldm_entity *entity); |
| 359 | |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 360 | /** @brief Create a copy of an existing entity association tree |
| 361 | * |
| 362 | * @param[in] org_tree - pointer to source tree |
| 363 | * @param[in/out] new_tree - pointer to destination tree |
| 364 | */ |
| 365 | void pldm_entity_association_tree_copy_root( |
| 366 | pldm_entity_association_tree *org_tree, |
| 367 | pldm_entity_association_tree *new_tree); |
| 368 | |
| 369 | /** @brief Destroy all the nodes of the entity association tree |
| 370 | * |
| 371 | * @param[in] tree - pointer to entity association tree |
| 372 | */ |
| 373 | void pldm_entity_association_tree_destroy_root( |
| 374 | pldm_entity_association_tree *tree); |
| 375 | |
| 376 | /** @brief Check whether the entity association tree is empty |
| 377 | * |
| 378 | * @param[in] tree - pointer to entity association tree |
| 379 | * @return bool, true if tree is empty |
| 380 | */ |
| 381 | bool pldm_is_empty_entity_assoc_tree(pldm_entity_association_tree *tree); |
| 382 | |
Deepak Kodihalli | 3b28ba8 | 2020-03-30 07:39:47 -0500 | [diff] [blame] | 383 | /** @brief Extract entities from entity association PDR |
| 384 | * |
| 385 | * @param[in] pdr - entity association PDR |
| 386 | * @param[in] pdr_len - size of entity association PDR in bytes |
| 387 | * @param[out] num_entities - number of entities found, including the container |
| 388 | * @param[out] entities - extracted entities, container is *entities[0]. Caller |
| 389 | * must free *entities |
| 390 | */ |
| 391 | void pldm_entity_association_pdr_extract(const uint8_t *pdr, uint16_t pdr_len, |
| 392 | size_t *num_entities, |
| 393 | pldm_entity **entities); |
| 394 | |
Deepak Kodihalli | 3b02ed8 | 2020-02-06 01:18:25 -0600 | [diff] [blame] | 395 | #ifdef __cplusplus |
| 396 | } |
| 397 | #endif |
| 398 | |
| 399 | #endif /* PDR_H */ |