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