blob: 3395e5bec47b6a0fb6898a3e55575bb2b0b1d191 [file] [log] [blame]
Julian Hall4a658ac2022-10-20 10:44:49 +01001/*
2 * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef MEDIA_VOLUME_H
8#define MEDIA_VOLUME_H
9
10#include <stddef.h>
11#include <common/uuid/uuid.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/**
18 * Export tf-a version with C++ linkage support.
19 */
20#include <drivers/io/io_driver.h>
21#include <drivers/io/io_storage.h>
22
23/**
24 * A volume can be used to access storage as a single seekable volume
25 * that may be accessed using file io type operations. The base volume
26 * extends the TF-A io_dev to add an erase operation to enable the entire
27 * volume to be erased prior to performing write operations. This is useful
28 * when doing things like installing firmware into a raw disk partition.
29 * Alternative concrete volume implementations are possible to suite different
30 * classes of storage. If a concrete volume does not support erase, the
31 * erase function pointer may be set to NULL;
32 */
33struct volume {
34
35 /* IO device handle for volume access */
36 uintptr_t dev_handle;
37
38 /* Opaque IO spec */
39 uintptr_t io_spec;
40
41 /* Base IO device */
42 io_dev_info_t dev_info;
43
44 /* Handle for IO operations */
45 uintptr_t io_handle;
46
47 /* Optional function to erase the volume */
48 int (*erase)(uintptr_t context);
49
50 /* Optional function to get storage IDs for the volume */
51 int (*get_storage_ids)(uintptr_t context,
52 struct uuid_octets *partition_guid,
53 struct uuid_octets *parent_guid);
54};
55
56/**
57 * @brief Initialize the base volume structure
58 *
59 * Called by a concrete volume to initialize the base volume and io_dev.
60 *
61 * @param[in] this_volume The subject volume
62 * @param[in] io_dev_funcs io_dev function struct for concrete handlers
63 * @param[in] concrete_volume Pointer to the concrete volume instance
64 */
65void volume_init(
66 struct volume *this_volume,
67 const io_dev_funcs_t *io_dev_funcs,
68 uintptr_t concrete_volume);
69
70/**
71 * @brief Open the volume for IO operations
72 *
73 * @param[in] this_volume The subject volume
74 *
75 * @return 0 on success
76 */
77int volume_open(
78 struct volume *this_volume);
79
80/**
81 * @brief Close the volume when done with IO operations
82 *
83 * @param[in] this_volume The subject volume
84 *
85 * @return 0 on success
86 */
87int volume_close(
88 struct volume *this_volume);
89
90/**
91 * @brief Seek to the specified position
92 *
93 * @param[in] this_volume The subject volume
94 * @param[in] mode See io_storage.h for options
95 * @param[in] offset Seek offset
96 *
97 * @return 0 on success
98 */
99int volume_seek(
100 struct volume *this_volume,
101 io_seek_mode_t mode,
102 signed long long offset);
103
104/**
105 * @brief Get the size of the volume
106 *
107 * @param[in] this_volume The subject volume
108 * @param[out] size Size in bytes of the volume
109 *
110 * @return 0 on success
111 */
112int volume_size(
113 struct volume *this_volume,
114 size_t *size);
115
116/**
117 * @brief Read from the volume
118 *
119 * Reads from the current seek position.
120 *
121 * @param[in] this_volume The subject volume
122 * @param[in] buffer Buffer to put read data
123 * @param[in] length Requested read length
124 * @param[out] length_read Actual length read
125 *
126 * @return 0 on success
127 */
128int volume_read(
129 struct volume *this_volume,
130 uintptr_t buffer,
131 size_t length,
132 size_t *length_read);
133
134/**
135 * @brief Write the volume
136 *
137 * Write from the current seek position.
138 *
139 * @param[in] this_volume The subject volume
140 * @param[in] buffer Buffer containing data to write
141 * @param[in] length Requested write length
142 * @param[out] length_read Actual write read
143 *
144 * @return 0 on success
145 */
146int volume_write(
147 struct volume *this_volume,
148 const uintptr_t buffer,
149 size_t length,
150 size_t *length_written);
151
152/**
153 * @brief Erase the entire volume
154 *
155 * @param[in] this_volume The subject volume
156 *
157 * @return 0 on success
158 */
159int volume_erase(
160 struct volume *this_volume);
161
162/**
163 * @brief Get GUIDs to identify the storage associated with the volume
164 *
165 * If supported by a concrete volume
166 *
167 * @param[in] this_volume The subject volume
168 * @param[out] partition_guid GUID for the logical partition
169 * @param[out] parent_guid GUID for a parent device e.g. a disk GUID
170 *
171 * @return 0 on success, ENOSYS if not supported
172 */
173int volume_get_storage_ids(
174 struct volume *this_volume,
175 struct uuid_octets *partition_guid,
176 struct uuid_octets *parent_guid);
177
178#ifdef __cplusplus
179}
180#endif
181
182#endif /* MEDIA_VOLUME_H */