arm_io_storage.c 3.18 KB
Newer Older
1
/*
Louis Mayencourt's avatar
Louis Mayencourt committed
2
 * Copyright (c) 2015-2020, ARM Limited. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
 */
6

7
#include <assert.h>
8
9
10
11
12
13
14

#include <common/debug.h>
#include <drivers/io/io_driver.h>
#include <drivers/io/io_fip.h>
#include <drivers/io/io_memmap.h>
#include <drivers/io/io_storage.h>
#include <lib/utils.h>
Louis Mayencourt's avatar
Louis Mayencourt committed
15
16
17

#include <plat/arm/common/arm_fconf_getter.h>
#include <plat/arm/common/arm_fconf_io_storage.h>
18
#include <plat/arm/common/plat_arm.h>
19
#include <plat/common/platform.h>
Louis Mayencourt's avatar
Louis Mayencourt committed
20
#include <platform_def.h>
21

22
23
/* IO devices */
static const io_dev_connector_t *fip_dev_con;
Louis Mayencourt's avatar
Louis Mayencourt committed
24
uintptr_t fip_dev_handle;
25
static const io_dev_connector_t *memmap_dev_con;
Louis Mayencourt's avatar
Louis Mayencourt committed
26
uintptr_t memmap_dev_handle;
27
28
29
30
31

/* Weak definitions may be overridden in specific ARM standard platform */
#pragma weak plat_arm_io_setup
#pragma weak plat_arm_get_alt_image_source

Louis Mayencourt's avatar
Louis Mayencourt committed
32
int open_fip(const uintptr_t spec)
33
34
35
36
37
{
	int result;
	uintptr_t local_image_handle;

	/* See if a Firmware Image Package is available */
38
	result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
39
	if (result == 0) {
40
		result = io_open(fip_dev_handle, spec, &local_image_handle);
41
		if (result == 0) {
42
43
44
45
46
47
48
			VERBOSE("Using FIP\n");
			io_close(local_image_handle);
		}
	}
	return result;
}

Louis Mayencourt's avatar
Louis Mayencourt committed
49
int open_memmap(const uintptr_t spec)
50
51
52
53
54
{
	int result;
	uintptr_t local_image_handle;

	result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
55
	if (result == 0) {
56
		result = io_open(memmap_dev_handle, spec, &local_image_handle);
57
		if (result == 0) {
58
59
60
61
62
63
64
			VERBOSE("Using Memmap\n");
			io_close(local_image_handle);
		}
	}
	return result;
}

65
int arm_io_setup(void)
66
67
68
69
{
	int io_result;

	io_result = register_io_dev_fip(&fip_dev_con);
70
71
72
	if (io_result < 0) {
		return io_result;
	}
73
74

	io_result = register_io_dev_memmap(&memmap_dev_con);
75
76
77
	if (io_result < 0) {
		return io_result;
	}
78
79
80
81

	/* Open connections to devices and cache the handles */
	io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
				&fip_dev_handle);
82
83
84
	if (io_result < 0) {
		return io_result;
	}
85
86
87
88

	io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
				&memmap_dev_handle);

89
	return io_result;
90
91
92
93
}

void plat_arm_io_setup(void)
{
94
95
96
97
98
99
	int err;

	err = arm_io_setup();
	if (err < 0) {
		panic();
	}
100
101
102
}

int plat_arm_get_alt_image_source(
103
104
105
	unsigned int image_id __unused,
	uintptr_t *dev_handle __unused,
	uintptr_t *image_spec __unused)
106
107
{
	/* By default do not try an alternative */
108
	return -ENOENT;
109
110
111
112
}

/* Return an IO device handle and specification which can be used to access
 * an image. Use this to enforce platform load policy */
113
int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
114
115
			  uintptr_t *image_spec)
{
116
	int result;
117
118
	const struct plat_io_policy *policy;

Louis Mayencourt's avatar
Louis Mayencourt committed
119
	assert(image_id < MAX_NUMBER_IDS);
120

Louis Mayencourt's avatar
Louis Mayencourt committed
121
	policy = FCONF_GET_PROPERTY(arm, io_policies, image_id);
122
	result = policy->check(policy->image_spec);
123
	if (result == 0) {
124
125
		*image_spec = policy->image_spec;
		*dev_handle = *(policy->dev_handle);
126
	} else {
127
128
129
		VERBOSE("Trying alternative IO\n");
		result = plat_arm_get_alt_image_source(image_id, dev_handle,
						       image_spec);
130
	}
131

132
133
	return result;
}
134
135
136
137
138

/*
 * See if a Firmware Image Package is available,
 * by checking if TOC is valid or not.
 */
139
bool arm_io_is_toc_valid(void)
140
{
141
	return (io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID) == 0);
142
}