Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 1 | /* |
| 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> |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 11 | |
| 12 | #include "common/uuid/uuid.h" |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 13 | |
| 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
| 18 | /** |
| 19 | * Export tf-a version with C++ linkage support. |
| 20 | */ |
| 21 | #include <drivers/io/io_driver.h> |
| 22 | #include <drivers/io/io_storage.h> |
| 23 | |
| 24 | /** |
| 25 | * A volume can be used to access storage as a single seekable volume |
| 26 | * that may be accessed using file io type operations. The base volume |
| 27 | * extends the TF-A io_dev to add an erase operation to enable the entire |
| 28 | * volume to be erased prior to performing write operations. This is useful |
| 29 | * when doing things like installing firmware into a raw disk partition. |
| 30 | * Alternative concrete volume implementations are possible to suite different |
| 31 | * classes of storage. If a concrete volume does not support erase, the |
| 32 | * erase function pointer may be set to NULL; |
| 33 | */ |
| 34 | struct volume { |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 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 */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 51 | int (*get_storage_ids)(uintptr_t context, struct uuid_octets *partition_guid, |
| 52 | struct uuid_octets *parent_guid); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * @brief Initialize the base volume structure |
| 57 | * |
| 58 | * Called by a concrete volume to initialize the base volume and io_dev. |
| 59 | * |
| 60 | * @param[in] this_volume The subject volume |
| 61 | * @param[in] io_dev_funcs io_dev function struct for concrete handlers |
| 62 | * @param[in] concrete_volume Pointer to the concrete volume instance |
| 63 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 64 | void volume_init(struct volume *this_volume, const io_dev_funcs_t *io_dev_funcs, |
| 65 | uintptr_t concrete_volume); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * @brief Open the volume for IO operations |
| 69 | * |
| 70 | * @param[in] this_volume The subject volume |
| 71 | * |
| 72 | * @return 0 on success |
| 73 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 74 | int volume_open(struct volume *this_volume); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * @brief Close the volume when done with IO operations |
| 78 | * |
| 79 | * @param[in] this_volume The subject volume |
| 80 | * |
| 81 | * @return 0 on success |
| 82 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 83 | int volume_close(struct volume *this_volume); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * @brief Seek to the specified position |
| 87 | * |
| 88 | * @param[in] this_volume The subject volume |
| 89 | * @param[in] mode See io_storage.h for options |
| 90 | * @param[in] offset Seek offset |
| 91 | * |
| 92 | * @return 0 on success |
| 93 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 94 | int volume_seek(struct volume *this_volume, io_seek_mode_t mode, signed long long offset); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * @brief Get the size of the volume |
| 98 | * |
| 99 | * @param[in] this_volume The subject volume |
| 100 | * @param[out] size Size in bytes of the volume |
| 101 | * |
| 102 | * @return 0 on success |
| 103 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 104 | int volume_size(struct volume *this_volume, size_t *size); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * @brief Read from the volume |
| 108 | * |
| 109 | * Reads from the current seek position. |
| 110 | * |
| 111 | * @param[in] this_volume The subject volume |
| 112 | * @param[in] buffer Buffer to put read data |
| 113 | * @param[in] length Requested read length |
| 114 | * @param[out] length_read Actual length read |
| 115 | * |
| 116 | * @return 0 on success |
| 117 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 118 | int volume_read(struct volume *this_volume, uintptr_t buffer, size_t length, size_t *length_read); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * @brief Write the volume |
| 122 | * |
| 123 | * Write from the current seek position. |
| 124 | * |
| 125 | * @param[in] this_volume The subject volume |
| 126 | * @param[in] buffer Buffer containing data to write |
| 127 | * @param[in] length Requested write length |
| 128 | * @param[out] length_read Actual write read |
| 129 | * |
| 130 | * @return 0 on success |
| 131 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 132 | int volume_write(struct volume *this_volume, const uintptr_t buffer, size_t length, |
| 133 | size_t *length_written); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * @brief Erase the entire volume |
| 137 | * |
| 138 | * @param[in] this_volume The subject volume |
| 139 | * |
| 140 | * @return 0 on success |
| 141 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 142 | int volume_erase(struct volume *this_volume); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * @brief Get GUIDs to identify the storage associated with the volume |
| 146 | * |
| 147 | * If supported by a concrete volume |
| 148 | * |
| 149 | * @param[in] this_volume The subject volume |
| 150 | * @param[out] partition_guid GUID for the logical partition |
| 151 | * @param[out] parent_guid GUID for a parent device e.g. a disk GUID |
| 152 | * |
| 153 | * @return 0 on success, ENOSYS if not supported |
| 154 | */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 155 | int volume_get_storage_ids(struct volume *this_volume, struct uuid_octets *partition_guid, |
| 156 | struct uuid_octets *parent_guid); |
Julian Hall | 4a658ac | 2022-10-20 10:44:49 +0100 | [diff] [blame] | 157 | |
| 158 | #ifdef __cplusplus |
| 159 | } |
| 160 | #endif |
| 161 | |
| 162 | #endif /* MEDIA_VOLUME_H */ |