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 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <assert.h> |
| 32 | #include <bl_common.h> |
| 33 | #include <debug.h> |
| 34 | #include <errno.h> |
| 35 | #include <plat_arm.h> |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 36 | #include <platform_def.h> |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 37 | #include <tbbr_img_desc.h> |
| 38 | |
| 39 | |
| 40 | /* Struct to keep track of usable memory */ |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 41 | typedef struct bl1_mem_info { |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 42 | uintptr_t mem_base; |
| 43 | unsigned int mem_size; |
| 44 | } bl1_mem_info_t; |
| 45 | |
| 46 | bl1_mem_info_t fwu_addr_map_secure[] = { |
| 47 | { |
| 48 | .mem_base = ARM_SHARED_RAM_BASE, |
| 49 | .mem_size = ARM_SHARED_RAM_SIZE |
| 50 | }, |
| 51 | { |
| 52 | .mem_size = 0 |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | bl1_mem_info_t fwu_addr_map_non_secure[] = { |
| 57 | { |
| 58 | .mem_base = ARM_NS_DRAM1_BASE, |
| 59 | .mem_size = ARM_NS_DRAM1_SIZE |
| 60 | }, |
| 61 | { |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 62 | .mem_base = PLAT_ARM_NVM_BASE, |
| 63 | .mem_size = PLAT_ARM_NVM_SIZE |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 64 | }, |
| 65 | { |
| 66 | .mem_size = 0 |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | int bl1_plat_mem_check(uintptr_t mem_base, |
| 71 | unsigned int mem_size, |
| 72 | unsigned int flags) |
| 73 | { |
| 74 | unsigned int index = 0; |
| 75 | bl1_mem_info_t *mmap; |
| 76 | |
| 77 | assert(mem_base); |
| 78 | assert(mem_size); |
| 79 | |
| 80 | /* |
| 81 | * Check the given image source and size. |
| 82 | */ |
Yatharth Kochar | f11b29a | 2016-02-01 11:04:46 +0000 | [diff] [blame] | 83 | if (GET_SECURITY_STATE(flags) == SECURE) |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 84 | mmap = fwu_addr_map_secure; |
| 85 | else |
| 86 | mmap = fwu_addr_map_non_secure; |
| 87 | |
| 88 | while (mmap[index].mem_size) { |
| 89 | if ((mem_base >= mmap[index].mem_base) && |
| 90 | ((mem_base + mem_size) |
| 91 | <= (mmap[index].mem_base + |
| 92 | mmap[index].mem_size))) |
| 93 | return 0; |
| 94 | |
| 95 | index++; |
| 96 | } |
| 97 | |
| 98 | return -ENOMEM; |
| 99 | } |
| 100 | |
| 101 | /******************************************************************************* |
| 102 | * This function does linear search for image_id and returns image_desc. |
| 103 | ******************************************************************************/ |
| 104 | image_desc_t *bl1_plat_get_image_desc(unsigned int image_id) |
| 105 | { |
| 106 | unsigned int index = 0; |
| 107 | |
| 108 | while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) { |
| 109 | if (bl1_tbbr_image_descs[index].image_id == image_id) |
| 110 | return &bl1_tbbr_image_descs[index]; |
| 111 | index++; |
| 112 | } |
| 113 | |
| 114 | return NULL; |
| 115 | } |