blob: 2a18d34130aabb60e90d1b7e905a39918b8b2c42 [file] [log] [blame]
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01001/*
Yatharth Kocharf11b29a2016-02-01 11:04:46 +00002 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01003 *
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 Kocharf11b29a2016-02-01 11:04:46 +000036#include <platform_def.h>
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010037#include <tbbr_img_desc.h>
38
39
40/* Struct to keep track of usable memory */
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000041typedef struct bl1_mem_info {
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010042 uintptr_t mem_base;
43 unsigned int mem_size;
44} bl1_mem_info_t;
45
46bl1_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
56bl1_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 Kocharf11b29a2016-02-01 11:04:46 +000062 .mem_base = PLAT_ARM_NVM_BASE,
63 .mem_size = PLAT_ARM_NVM_SIZE
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010064 },
65 {
66 .mem_size = 0
67 }
68};
69
70int 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 Kocharf11b29a2016-02-01 11:04:46 +000083 if (GET_SECURITY_STATE(flags) == SECURE)
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010084 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 ******************************************************************************/
104image_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}