blob: 7fe0f2368bee3da38817ff120f612cbe418c658b [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
8#include <stdint.h>
9
10/** @struct pldm_pdr
11 * opaque structure that acts as a handle to a PDR repository
12 */
13typedef struct pldm_pdr pldm_pdr;
14
15/** @struct pldm_pdr_record
16 * opaque structure that acts as a handle to a PDR record
17 */
18typedef struct pldm_pdr_record pldm_pdr_record;
19
20/* ====================== */
21/* Common PDR access APIs */
22/* ====================== */
23
24/** @brief Make a new PDR repository
25 *
26 * @return opaque pointer that acts as a handle to the repository; NULL if no
27 * repository could be created
28 *
29 * @note Caller may make multiple repositories (for its own PDRs, as well as
30 * for PDRs received by other entities) and can associate the returned handle
31 * to a PLDM terminus id.
32 */
33pldm_pdr *pldm_pdr_init();
34
35/** @brief Destroy a PDR repository (and free up associated resources)
36 *
37 * @param[in/out] repo - pointer to opaque pointer acting as a PDR repo handle
38 */
39void pldm_pdr_destroy(pldm_pdr *repo);
40
41/** @brief Get number of records in a PDR repository
42 *
43 * @param[in] repo - opaque pointer acting as a PDR repo handle
44 *
45 * @return uint32_t - number of records
46 */
47uint32_t pldm_pdr_get_record_count(const pldm_pdr *repo);
48
49/** @brief Get size of a PDR repository, in bytes
50 *
51 * @param[in] repo - opaque pointer acting as a PDR repo handle
52 *
53 * @return uint32_t - size in bytes
54 */
55uint32_t pldm_pdr_get_repo_size(const pldm_pdr *repo);
56
57/** @brief Add a PDR record to a PDR repository
58 *
59 * @param[in/out] repo - opaque pointer acting as a PDR repo handle
60 * @param[in] data - pointer to a PDR record, pointing to a PDR definition as
61 * per DSP0248. This data is memcpy'd.
62 * @param[in] size - size of input PDR record in bytes
63 * @param[in] record_handle - record handle of input PDR record; if this is set
64 * to 0, then a record handle is computed and assigned to this PDR record
65 *
66 * @return uint32_t - record handle assigned to PDR record
67 */
68uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size,
69 uint32_t record_handle);
70
71/** @brief Get record handle of a PDR record
72 *
73 * @param[in] repo - opaque pointer acting as a PDR repo handle
74 * @param[in] record - opaque pointer acting as a PDR record handle
75 *
76 * @return uint32_t - record handle assigned to PDR record; 0 if record is not
77 * found
78 */
79uint32_t pldm_pdr_get_record_handle(const pldm_pdr *repo,
80 const pldm_pdr_record *record);
81
82/** @brief Find PDR record by record handle
83 *
84 * @param[in] repo - opaque pointer acting as a PDR repo handle
85 * @param[in] record_handle - input record handle
86 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
87 * return
88 * @param[out] size - *size will be size of PDR record
89 * @param[out] next_record_handle - *next_record_handle will be the record
90 * handle of record next to the returned PDR record
91 *
92 * @return opaque pointer acting as PDR record handle, will be NULL if record
93 * was not found
94 */
95const pldm_pdr_record *pldm_pdr_find_record(const pldm_pdr *repo,
96 uint32_t record_handle,
97 uint8_t **data, uint32_t *size,
98 uint32_t *next_record_handle);
99
100/** @brief Get PDR record next to input PDR record
101 *
102 * @param[in] repo - opaque pointer acting as a PDR repo handle
103 * @param[in] curr_record - opaque pointer acting as a PDR record handle
104 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
105 * return
106 * @param[out] size - *size will be size of PDR record
107 * @param[out] next_record_handle - *next_record_handle will be the record
108 * handle of record nect to the returned PDR record
109 *
110 * @return opaque pointer acting as PDR record handle, will be NULL if record
111 * was not found
112 */
113const pldm_pdr_record *
114pldm_pdr_get_next_record(const pldm_pdr *repo,
115 const pldm_pdr_record *curr_record, uint8_t **data,
116 uint32_t *size, uint32_t *next_record_handle);
117
118/** @brief Find (first) PDR record by PDR type
119 *
120 * @param[in] repo - opaque pointer acting as a PDR repo handle
121 * @param[in] pdr_type - PDR type number as per DSP0248
122 * @param[in] curr_record - opaque pointer acting as a PDR record handle; if
123 * not NULL, then search will begin from this record's next record
124 * @param[in/out] data - will point to PDR record data (as per DSP0248) on
125 * return
126 * @param[out] size - *size will be size of PDR record
127 *
128 * @return opaque pointer acting as PDR record handle, will be NULL if record
129 * was not found
130 */
131const pldm_pdr_record *
132pldm_pdr_find_record_by_type(const pldm_pdr *repo, uint8_t pdr_type,
133 const pldm_pdr_record *curr_record, uint8_t **data,
134 uint32_t *size);
135
Deepak Kodihallidb914672020-02-07 02:47:45 -0600136/* ======================= */
137/* FRU Record Set PDR APIs */
138/* ======================= */
139
140/** @brief Add a FRU record set PDR record to a PDR repository
141 *
142 * @param[in/out] repo - opaque pointer acting as a PDR repo handle
143 * @param[in] terminus_handle - PLDM terminus handle of terminus owning the PDR
144 * record
145 * @param[in] fru_rsi - FRU record set identifier
146 * @param[in] entity_type - entity type of FRU
147 * @param[in] entity_instance_num - entity instance number of FRU
148 * @param[in] container_id - container id of FRU
149 *
150 * @return uint32_t - record handle assigned to PDR record
151 */
152uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle,
153 uint16_t fru_rsi, uint16_t entity_type,
154 uint16_t entity_instance_num,
155 uint16_t container_id);
156
157/** @brief Find a FRU record set PDR by FRU record set identifier
158 *
159 * @param[in] repo - opaque pointer acting as a PDR repo handle
160 * @param[in] fru_rsi - FRU record set identifier
161 * @param[in] terminus_handle - *terminus_handle will be FRU terminus handle of
162 * found PDR, or 0 if not found
163 * @param[in] entity_type - *entity_type will be FRU entity type of found PDR,
164 * or 0 if not found
165 * @param[in] entity_instance_num - *entity_instance_num will be FRU entity
166 * instance number of found PDR, or 0 if not found
167 * @param[in] container_id - *cintainer_id will be FRU container id of found
168 * PDR, or 0 if not found
169 *
170 * @return uint32_t - record handle assigned to PDR record
171 */
172const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi(
173 const pldm_pdr *repo, uint16_t fru_rsi, uint16_t *terminus_handle,
174 uint16_t *entity_type, uint16_t *entity_instance_num,
175 uint16_t *container_id);
176
Deepak Kodihalli3b02ed82020-02-06 01:18:25 -0600177#ifdef __cplusplus
178}
179#endif
180
181#endif /* PDR_H */