blob: cd92aa8ed0fce3d1ef8aa8f51243d050c20f5b30 [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>
Yatharth Kochar736a3bf2015-10-11 14:14:55 +01008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000010#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011
12#include <bl1/tbbr/tbbr_img_desc.h>
13#include <common/bl_common.h>
14#include <common/debug.h>
15#include <lib/utils.h>
16#include <plat/common/platform.h>
17
18#include <plat_arm.h>
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010019
20/* Struct to keep track of usable memory */
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000021typedef struct bl1_mem_info {
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010022 uintptr_t mem_base;
23 unsigned int mem_size;
24} bl1_mem_info_t;
25
Roberto Vargas52f707f2018-02-12 12:36:17 +000026static bl1_mem_info_t fwu_addr_map_secure[] = {
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010027 {
28 .mem_base = ARM_SHARED_RAM_BASE,
29 .mem_size = ARM_SHARED_RAM_SIZE
30 },
31 {
32 .mem_size = 0
33 }
34};
35
Roberto Vargas52f707f2018-02-12 12:36:17 +000036static bl1_mem_info_t fwu_addr_map_non_secure[] = {
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010037 {
38 .mem_base = ARM_NS_DRAM1_BASE,
39 .mem_size = ARM_NS_DRAM1_SIZE
40 },
41 {
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000042 .mem_base = PLAT_ARM_NVM_BASE,
43 .mem_size = PLAT_ARM_NVM_SIZE
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010044 },
45 {
46 .mem_size = 0
47 }
48};
49
50int bl1_plat_mem_check(uintptr_t mem_base,
51 unsigned int mem_size,
52 unsigned int flags)
53{
54 unsigned int index = 0;
55 bl1_mem_info_t *mmap;
56
57 assert(mem_base);
58 assert(mem_size);
Sandrine Bailleuxb39d75f2016-11-11 16:44:37 +000059 /*
60 * The caller of this function is responsible for checking upfront that
61 * the end address doesn't overflow. We double-check this in debug
62 * builds.
63 */
64 assert(!check_uptr_overflow(mem_base, mem_size - 1));
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010065
66 /*
67 * Check the given image source and size.
68 */
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000069 if (GET_SECURITY_STATE(flags) == SECURE)
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010070 mmap = fwu_addr_map_secure;
71 else
72 mmap = fwu_addr_map_non_secure;
73
74 while (mmap[index].mem_size) {
75 if ((mem_base >= mmap[index].mem_base) &&
76 ((mem_base + mem_size)
77 <= (mmap[index].mem_base +
78 mmap[index].mem_size)))
79 return 0;
80
81 index++;
82 }
83
84 return -ENOMEM;
85}
86
87/*******************************************************************************
88 * This function does linear search for image_id and returns image_desc.
89 ******************************************************************************/
90image_desc_t *bl1_plat_get_image_desc(unsigned int image_id)
91{
92 unsigned int index = 0;
93
94 while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) {
95 if (bl1_tbbr_image_descs[index].image_id == image_id)
96 return &bl1_tbbr_image_descs[index];
97 index++;
98 }
99
100 return NULL;
101}