Julian Hall | cfe2f5b | 2022-09-22 11:26:35 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | #include <string.h> |
| 11 | #include <plat/common/platform.h> |
| 12 | #include "volume_index.h" |
| 13 | |
| 14 | #ifndef VOLUME_INDEX_MAX_ENTRIES |
| 15 | #define VOLUME_INDEX_MAX_ENTRIES (4) |
| 16 | #endif |
| 17 | |
| 18 | /** |
| 19 | * Singleton index of volume IDs to IO devices. |
| 20 | */ |
| 21 | static struct |
| 22 | { |
| 23 | size_t size; |
| 24 | struct |
| 25 | { |
| 26 | unsigned int volume_id; |
| 27 | uintptr_t dev_handle; |
| 28 | uintptr_t volume_spec; |
| 29 | } entries[VOLUME_INDEX_MAX_ENTRIES]; |
| 30 | |
| 31 | } volume_index; |
| 32 | |
| 33 | /** |
| 34 | * @brief Gets a device for volume IO operations |
| 35 | * |
| 36 | * @param[in] volume_id Identifies the image |
| 37 | * @param[out] dev_handle Handle for IO operations |
| 38 | * @param[out] volume_spec Opaque configuration data |
| 39 | * |
| 40 | * This function realizes the interface expected by tf-a components to |
| 41 | * provide a concrete IO device for the specified volume ID. When used in |
| 42 | * TS deployments, the set of IO devices required for a deployment |
| 43 | * are registered during service configuration. |
| 44 | */ |
| 45 | int plat_get_image_source( |
| 46 | unsigned int volume_id, |
| 47 | uintptr_t *dev_handle, |
| 48 | uintptr_t *volume_spec) |
| 49 | { |
| 50 | int result = -1; |
| 51 | |
| 52 | for (size_t i = 0; i < volume_index.size; i++) { |
| 53 | |
| 54 | if (volume_index.entries[i].volume_id == volume_id) { |
| 55 | |
| 56 | *dev_handle = volume_index.entries[i].dev_handle; |
| 57 | *volume_spec = volume_index.entries[i].volume_spec; |
| 58 | |
| 59 | result = 0; |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | void volume_index_init(void) |
| 68 | { |
| 69 | volume_index_clear(); |
| 70 | } |
| 71 | |
| 72 | void volume_index_clear(void) |
| 73 | { |
| 74 | memset(&volume_index, 0, sizeof(volume_index)); |
| 75 | } |
| 76 | |
| 77 | int volume_index_add( |
| 78 | unsigned int volume_id, |
| 79 | uintptr_t dev_handle, |
| 80 | uintptr_t volume_spec) |
| 81 | { |
| 82 | int result = -1; |
| 83 | |
| 84 | if (volume_index.size < VOLUME_INDEX_MAX_ENTRIES) |
| 85 | { |
| 86 | size_t i = volume_index.size; |
| 87 | |
| 88 | ++volume_index.size; |
| 89 | volume_index.entries[i].volume_id = volume_id; |
| 90 | volume_index.entries[i].dev_handle = dev_handle; |
| 91 | volume_index.entries[i].volume_spec = volume_spec; |
| 92 | |
| 93 | result = 0; |
| 94 | } |
| 95 | |
| 96 | return result; |
| 97 | } |