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