blob: 1305934c8bb7bed5c22fd5f40eb7d1d9159d5bb4 [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 *
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>
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000012#include <platform_def.h>
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010013#include <tbbr_img_desc.h>
Sandrine Bailleuxb39d75f2016-11-11 16:44:37 +000014#include <utils.h>
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010015
16/* Struct to keep track of usable memory */
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000017typedef struct bl1_mem_info {
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010018 uintptr_t mem_base;
19 unsigned int mem_size;
20} bl1_mem_info_t;
21
22bl1_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
32bl1_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 Kocharf11b29a2016-02-01 11:04:46 +000038 .mem_base = PLAT_ARM_NVM_BASE,
39 .mem_size = PLAT_ARM_NVM_SIZE
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010040 },
41 {
42 .mem_size = 0
43 }
44};
45
46int 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 Bailleuxb39d75f2016-11-11 16:44:37 +000055 /*
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 Kochar736a3bf2015-10-11 14:14:55 +010061
62 /*
63 * Check the given image source and size.
64 */
Yatharth Kocharf11b29a2016-02-01 11:04:46 +000065 if (GET_SECURITY_STATE(flags) == SECURE)
Yatharth Kochar736a3bf2015-10-11 14:14:55 +010066 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 ******************************************************************************/
86image_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}