Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 1 | /* |
laurenw-arm | 56f1e3e | 2021-03-03 14:19:38 -0600 | [diff] [blame] | 2 | * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved. |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 8 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 10 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | |
| 12 | #include <bl1/tbbr/tbbr_img_desc.h> |
| 13 | #include <common/bl_common.h> |
| 14 | #include <common/debug.h> |
| 15 | #include <lib/utils.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 16 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | #include <plat/common/platform.h> |
| 18 | |
laurenw-arm | 56f1e3e | 2021-03-03 14:19:38 -0600 | [diff] [blame] | 19 | #pragma weak bl1_plat_get_image_desc |
| 20 | |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 21 | /* Struct to keep track of usable memory */ |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 22 | typedef struct bl1_mem_info { |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 23 | uintptr_t mem_base; |
| 24 | unsigned int mem_size; |
| 25 | } bl1_mem_info_t; |
| 26 | |
Roberto Vargas | 52f707f | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 27 | static bl1_mem_info_t fwu_addr_map_secure[] = { |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 28 | { |
| 29 | .mem_base = ARM_SHARED_RAM_BASE, |
| 30 | .mem_size = ARM_SHARED_RAM_SIZE |
| 31 | }, |
| 32 | { |
| 33 | .mem_size = 0 |
| 34 | } |
| 35 | }; |
| 36 | |
Roberto Vargas | 52f707f | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 37 | static bl1_mem_info_t fwu_addr_map_non_secure[] = { |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 38 | { |
| 39 | .mem_base = ARM_NS_DRAM1_BASE, |
| 40 | .mem_size = ARM_NS_DRAM1_SIZE |
| 41 | }, |
| 42 | { |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 43 | .mem_base = PLAT_ARM_NVM_BASE, |
| 44 | .mem_size = PLAT_ARM_NVM_SIZE |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 45 | }, |
| 46 | { |
| 47 | .mem_size = 0 |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | int bl1_plat_mem_check(uintptr_t mem_base, |
| 52 | unsigned int mem_size, |
| 53 | unsigned int flags) |
| 54 | { |
| 55 | unsigned int index = 0; |
| 56 | bl1_mem_info_t *mmap; |
| 57 | |
| 58 | assert(mem_base); |
| 59 | assert(mem_size); |
Sandrine Bailleux | b39d75f | 2016-11-11 16:44:37 +0000 | [diff] [blame] | 60 | /* |
| 61 | * The caller of this function is responsible for checking upfront that |
| 62 | * the end address doesn't overflow. We double-check this in debug |
| 63 | * builds. |
| 64 | */ |
| 65 | assert(!check_uptr_overflow(mem_base, mem_size - 1)); |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Check the given image source and size. |
| 69 | */ |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 70 | if (GET_SECURITY_STATE(flags) == SECURE) |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 71 | mmap = fwu_addr_map_secure; |
| 72 | else |
| 73 | mmap = fwu_addr_map_non_secure; |
| 74 | |
| 75 | while (mmap[index].mem_size) { |
| 76 | if ((mem_base >= mmap[index].mem_base) && |
| 77 | ((mem_base + mem_size) |
| 78 | <= (mmap[index].mem_base + |
| 79 | mmap[index].mem_size))) |
| 80 | return 0; |
| 81 | |
| 82 | index++; |
| 83 | } |
| 84 | |
| 85 | return -ENOMEM; |
| 86 | } |
| 87 | |
| 88 | /******************************************************************************* |
| 89 | * This function does linear search for image_id and returns image_desc. |
| 90 | ******************************************************************************/ |
| 91 | image_desc_t *bl1_plat_get_image_desc(unsigned int image_id) |
| 92 | { |
| 93 | unsigned int index = 0; |
| 94 | |
| 95 | while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) { |
| 96 | if (bl1_tbbr_image_descs[index].image_id == image_id) |
| 97 | return &bl1_tbbr_image_descs[index]; |
| 98 | index++; |
| 99 | } |
| 100 | |
| 101 | return NULL; |
| 102 | } |