xref: /openbmc/hiomapd/vpnor/backend.h (revision f4bc335b4fc899509c92c230f746fe90a5aa43d2)
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /* Copyright (C) 2018 IBM Corp. */
3 #pragma once
4 
5 #include <limits.h>
6 #include "pnor_partition_defs.h"
7 #include "backend.h"
8 
9 struct mbox_context;
10 struct vpnor_partition_table;
11 
12 struct vpnor_partition_paths
13 {
14     char ro_loc[PATH_MAX];
15     char rw_loc[PATH_MAX];
16     char prsv_loc[PATH_MAX];
17     char patch_loc[PATH_MAX];
18 };
19 
20 struct vpnor_data {
21 	struct vpnor_partition_table *vpnor;
22 	struct vpnor_partition_paths paths;
23 };
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /** @brief Populate the path object with the default partition paths
30  *
31  *  @param[in/out] paths - A paths object in which to store the defaults
32  *
33  *  Returns 0 if the call succeeds, else a negative error code.
34  */
35 #ifdef VIRTUAL_PNOR_ENABLED
36 void vpnor_default_paths(struct vpnor_partition_paths *paths);
37 #else
38 static inline void vpnor_default_paths(struct vpnor_partition_paths *paths)
39 {
40     memset(paths, 0, sizeof(*paths));
41 }
42 #endif
43 
44 #ifdef VIRTUAL_PNOR_ENABLED
45 /** @brief Create a virtual PNOR partition table.
46  *
47  *  @param[in] backend - The backend context pointer
48  *  @param[in] paths - A paths object pointer to initialise vpnor
49  *
50  *  This API should be called before calling any other APIs below. If a table
51  *  already exists, this function will not do anything further. This function
52  *  will not do anything if the context is NULL.
53  *
54  *  The content of the paths object is copied out, ownership is retained by the
55  *  caller.
56  *
57  *  Returns 0 if the call succeeds, else a negative error code.
58  */
59 
60 int vpnor_init(struct backend *backend,
61 	       const struct vpnor_partition_paths *paths);
62 
63 /** @brief Copy bootloader partition (alongwith TOC) to LPC memory
64  *
65  *  @param[in] backend - The backend context pointer
66  *
67  *  @returns 0 on success, negative error code on failure
68  */
69 int vpnor_copy_bootloader_partition(const struct backend *backend, void *buf,
70 				    uint32_t count);
71 
72 /** @brief Destroy partition table, if it exists.
73  *
74  *  @param[in] backend - The backend context pointer
75  */
76 void vpnor_destroy(struct backend *backend);
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif
83