blob: ab94cba3302c6b5a5ad028453d1191308eff976f [file] [log] [blame]
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <assert.h>
9#include <debug.h>
10#include <firmware_image_package.h>
11#include <io_block.h>
12#include <io_driver.h>
13#include <io_fip.h>
14#include <io_memmap.h>
15#include <io_storage.h>
16#include <mmio.h>
17#include <partition/partition.h>
18#include <semihosting.h>
19#include <string.h>
20#include <tbbr_img_def.h>
21#include <utils.h>
22#include "platform_def.h"
23
24static const io_dev_connector_t *mmap_dev_con;
25static const io_dev_connector_t *fip_dev_con;
26
27static uintptr_t mmap_dev_handle;
28static uintptr_t fip_dev_handle;
29
30static int open_mmap(const uintptr_t spec);
31static int open_fip(const uintptr_t spec);
32
33static const io_block_spec_t loader_fip_spec = {
34 .offset = FIP_BASE,
35 .length = FIP_SIZE
36};
37
38static const io_uuid_spec_t bl2_uuid_spec = {
39 .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
40};
41
42static const io_uuid_spec_t bl31_uuid_spec = {
43 .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
44};
45
Victor Chong662556a2017-10-28 01:59:41 +090046static const io_uuid_spec_t bl32_uuid_spec = {
47 .uuid = UUID_SECURE_PAYLOAD_BL32,
48};
49
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020050static const io_uuid_spec_t bl33_uuid_spec = {
51 .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
52};
53
54struct plat_io_policy {
55 uintptr_t *dev_handle;
56 uintptr_t image_spec;
57 int (*check)(const uintptr_t spec);
58};
59
60static const struct plat_io_policy policies[] = {
61 [FIP_IMAGE_ID] = {
62 &mmap_dev_handle,
63 (uintptr_t)&loader_fip_spec,
64 open_mmap
65 },
66 [BL2_IMAGE_ID] = {
67 &fip_dev_handle,
68 (uintptr_t)&bl2_uuid_spec,
69 open_fip
70 },
71 [BL31_IMAGE_ID] = {
72 &fip_dev_handle,
73 (uintptr_t)&bl31_uuid_spec,
74 open_fip
75 },
Victor Chong662556a2017-10-28 01:59:41 +090076 [BL32_IMAGE_ID] = {
77 &fip_dev_handle,
78 (uintptr_t)&bl32_uuid_spec,
79 open_fip
80 },
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020081 [BL33_IMAGE_ID] = {
82 &fip_dev_handle,
83 (uintptr_t)&bl33_uuid_spec,
84 open_fip
85 },
86};
87
88static int open_mmap(const uintptr_t spec)
89{
90 int result;
91 uintptr_t local_image_handle;
92
93 result = io_dev_init(mmap_dev_handle, (uintptr_t)NULL);
94 if (result == 0) {
95 result = io_open(mmap_dev_handle, spec, &local_image_handle);
96 if (result == 0) {
97 io_close(local_image_handle);
98 }
99 }
100 return result;
101}
102
103static int open_fip(const uintptr_t spec)
104{
105 uintptr_t local_image_handle;
106 int result;
107
108 result = io_dev_init(fip_dev_handle, (uintptr_t) FIP_IMAGE_ID);
109 if (result == 0) {
110 result = io_open(fip_dev_handle, spec, &local_image_handle);
111 if (result == 0) {
112 io_close(local_image_handle);
113 } else {
114 VERBOSE("error opening fip\n");
115 }
116 } else {
117 VERBOSE("error initializing fip\n");
118 }
119
120 return result;
121}
122
123int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
124 uintptr_t *image_spec)
125{
126 const struct plat_io_policy *policy;
127 int result;
128
129 assert(image_id < ARRAY_SIZE(policies));
130
131 policy = &policies[image_id];
132 result = policy->check(policy->image_spec);
133 assert(result == 0);
134
135 *image_spec = policy->image_spec;
136 *dev_handle = *(policy->dev_handle);
137
138 return result;
139}
140
141void plat_io_setup(void)
142{
143 int result;
144
145 result = register_io_dev_memmap(&mmap_dev_con);
146 assert(result == 0);
147
148 result = register_io_dev_fip(&fip_dev_con);
149 assert(result == 0);
150
151 result = io_dev_open(fip_dev_con, (uintptr_t)&loader_fip_spec,
152 &fip_dev_handle);
153 assert(result == 0);
154
155 result = io_dev_open(mmap_dev_con, (uintptr_t)NULL, &mmap_dev_handle);
156 assert(result == 0);
157
158 (void) result;
159}