blob: 1db8593fbde74784b5530f77544b88dadbceb347 [file] [log] [blame]
Patrick Williams691668f2023-11-01 08:19:10 -05001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
Rashmica Gupta36af84c2023-04-12 16:16:28 +10002#ifndef INSTANCE_ID_H
3#define INSTANCE_ID_H
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
Andrew Jefferyefb40062023-11-10 13:48:39 +10309#include <libpldm/base.h>
10
Rashmica Gupta36af84c2023-04-12 16:16:28 +100011#include <stdint.h>
12
13typedef uint8_t pldm_instance_id_t;
14struct pldm_instance_db;
15
16#ifdef __STDC_HOSTED__
17/**
18 * @brief Instantiates an instance ID database object for a given database path
19 *
20 * @param[out] ctx - *ctx must be NULL, and will point to a PLDM instance ID
21 * database object on success.
22 * @param[in] dbpath - the path to the instance ID database file to use
23 *
24 * @return int - Returns 0 on success. Returns -EINVAL if ctx is NULL or *ctx
25 * is not NULL. Returns -ENOMEM if memory couldn't be allocated.
26 * Returns the errno if the database couldn't be opened.
27 * */
28int pldm_instance_db_init(struct pldm_instance_db **ctx, const char *dbpath);
29
30/**
31 * @brief Instantiates an instance ID database object for the default database
32 * path
33 *
34 * @param[out] ctx - *ctx will point to a PLDM instance ID database object on
35 * success.
36 *
37 * @return int - Returns 0 on success. Returns -EINVAL if ctx is NULL or *ctx
38 * is not NULL. Returns -ENOMEM if memory couldn't be allocated.
39 * Returns the errno if the database couldn't be opened.
40 * */
41int pldm_instance_db_init_default(struct pldm_instance_db **ctx);
42
43/**
44 * @brief Destroys an instance ID database object
45 *
46 * @param[in] ctx - PLDM instance ID database object
47 *
48 * @return int - Returns 0 on success or if *ctx is NULL. No specific errors are
49 * specified.
50 * */
51int pldm_instance_db_destroy(struct pldm_instance_db *ctx);
52
53/**
54 * @brief Allocates an instance ID for a destination TID from the instance ID
55 * database
56 *
57 * @param[in] ctx - PLDM instance ID database object
58 * @param[in] tid - PLDM TID
59 * @param[in] iid - caller owned pointer to a PLDM instance ID object. On
60 * success, this points to an instance ID to use for a PLDM request
61 * message.
62 *
63 * @return int - Returns 0 on success if we were able to allocate an instance
64 * ID. Returns -EINVAL if the iid pointer is NULL. Returns -EAGAIN
65 * if a successive call may succeed. Returns -EPROTO if the
66 * operation has entered an undefined state.
67 */
68int pldm_instance_id_alloc(struct pldm_instance_db *ctx, pldm_tid_t tid,
69 pldm_instance_id_t *iid);
70
71/**
72 * @brief Frees an instance ID previously allocated by pldm_instance_id_alloc
73 *
74 * @param[in] ctx - PLDM instance ID database object
75 * @param[in] tid - PLDM TID
76 * @param[in] iid - If this instance ID was not previously allocated by
77 * pldm_instance_id_alloc then EINVAL is returned.
78 *
79 * @return int - Returns 0 on success. Returns -EINVAL if the iid supplied was
80 * not previously allocated by pldm_instance_id_alloc or it has
81 * previously been freed. Returns -EAGAIN if a successive call may
82 * succeed. Returns -EPROTO if the operation has entered an
83 * undefined state.
84 */
85int pldm_instance_id_free(struct pldm_instance_db *ctx, pldm_tid_t tid,
86 pldm_instance_id_t iid);
87
88#endif /* __STDC_HOSTED__*/
89
90#ifdef __cplusplus
91}
92#endif
93
94#endif /* INSTANCE_ID_H */