blob: f2be47792b2130324a9d9efe4016604d1d0b4140 [file] [log] [blame]
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01001/*
Roberto Vargas52f707f2018-02-12 12:36:17 +00002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01005 */
6
7#include <assert.h>
8#include <bl_common.h>
9#include <debug.h>
10#include <errno.h>
11#include <plat_arm.h>
Roberto Vargas52f707f2018-02-12 12:36:17 +000012#include <platform.h>
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000013#include <platform_def.h>
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010014#include <tbbr_img_desc.h>
Sandrine Bailleuxb39d75f2016-11-11 16:44:37 +000015#include <utils.h>
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010016
17/* Struct to keep track of usable memory */
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000018typedef struct bl1_mem_info {
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010019 uintptr_t mem_base;
20 unsigned int mem_size;
21} bl1_mem_info_t;
22
Roberto Vargas52f707f2018-02-12 12:36:17 +000023static bl1_mem_info_t fwu_addr_map_secure[] = {
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010024 {
25 .mem_base = ARM_SHARED_RAM_BASE,
26 .mem_size = ARM_SHARED_RAM_SIZE
27 },
28 {
29 .mem_size = 0
30 }
31};
32
Roberto Vargas52f707f2018-02-12 12:36:17 +000033static bl1_mem_info_t fwu_addr_map_non_secure[] = {
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010034 {
35 .mem_base = ARM_NS_DRAM1_BASE,
36 .mem_size = ARM_NS_DRAM1_SIZE
37 },
38 {
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000039 .mem_base = PLAT_ARM_NVM_BASE,
40 .mem_size = PLAT_ARM_NVM_SIZE
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010041 },
42 {
43 .mem_size = 0
44 }
45};
46
47int 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 Bailleuxb39d75f2016-11-11 16:44:37 +000056 /*
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 Kochar736a3bf2015-10-11 14:14:55 +010062
63 /*
64 * Check the given image source and size.
65 */
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000066 if (GET_SECURITY_STATE(flags) == SECURE)
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010067 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 ******************************************************************************/
87image_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}