blob: 34b4101e1a0bda96b01074034a2a7f2a6a4e1b61 [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Louis Mayencourt6b232d92020-02-28 16:57:30 +00002 * Copyright (c) 2015-2020, ARM Limited. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00006
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <common/debug.h>
8#include <drivers/io/io_driver.h>
9#include <drivers/io/io_fip.h>
10#include <drivers/io/io_memmap.h>
11#include <drivers/io/io_storage.h>
12#include <lib/utils.h>
Louis Mayencourt6b232d92020-02-28 16:57:30 +000013
14#include <plat/arm/common/arm_fconf_getter.h>
15#include <plat/arm/common/arm_fconf_io_storage.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000016#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <plat/common/platform.h>
Louis Mayencourt6b232d92020-02-28 16:57:30 +000018#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000019
Dan Handley9df48042015-03-19 18:58:55 +000020/* IO devices */
21static const io_dev_connector_t *fip_dev_con;
Louis Mayencourt6b232d92020-02-28 16:57:30 +000022uintptr_t fip_dev_handle;
Dan Handley9df48042015-03-19 18:58:55 +000023static const io_dev_connector_t *memmap_dev_con;
Louis Mayencourt6b232d92020-02-28 16:57:30 +000024uintptr_t memmap_dev_handle;
Dan Handley9df48042015-03-19 18:58:55 +000025
26/* Weak definitions may be overridden in specific ARM standard platform */
27#pragma weak plat_arm_io_setup
28#pragma weak plat_arm_get_alt_image_source
29
Louis Mayencourt6b232d92020-02-28 16:57:30 +000030int open_fip(const uintptr_t spec)
Dan Handley9df48042015-03-19 18:58:55 +000031{
32 int result;
33 uintptr_t local_image_handle;
34
35 /* See if a Firmware Image Package is available */
Juan Castillo3a66aca2015-04-13 17:36:19 +010036 result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
Juan Castillo6e762062015-11-02 10:47:01 +000037 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +000038 result = io_open(fip_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +000039 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +000040 VERBOSE("Using FIP\n");
41 io_close(local_image_handle);
42 }
43 }
44 return result;
45}
46
Louis Mayencourt6b232d92020-02-28 16:57:30 +000047int open_memmap(const uintptr_t spec)
Dan Handley9df48042015-03-19 18:58:55 +000048{
49 int result;
50 uintptr_t local_image_handle;
51
52 result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL);
Juan Castillo6e762062015-11-02 10:47:01 +000053 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +000054 result = io_open(memmap_dev_handle, spec, &local_image_handle);
Juan Castillo6e762062015-11-02 10:47:01 +000055 if (result == 0) {
Dan Handley9df48042015-03-19 18:58:55 +000056 VERBOSE("Using Memmap\n");
57 io_close(local_image_handle);
58 }
59 }
60 return result;
61}
62
Louis Mayencourt7d24ce12020-01-29 14:43:06 +000063int arm_io_setup(void)
Dan Handley9df48042015-03-19 18:58:55 +000064{
65 int io_result;
66
67 io_result = register_io_dev_fip(&fip_dev_con);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +000068 if (io_result < 0) {
69 return io_result;
70 }
Dan Handley9df48042015-03-19 18:58:55 +000071
72 io_result = register_io_dev_memmap(&memmap_dev_con);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +000073 if (io_result < 0) {
74 return io_result;
75 }
Dan Handley9df48042015-03-19 18:58:55 +000076
77 /* Open connections to devices and cache the handles */
78 io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL,
79 &fip_dev_handle);
Louis Mayencourt7d24ce12020-01-29 14:43:06 +000080 if (io_result < 0) {
81 return io_result;
82 }
Dan Handley9df48042015-03-19 18:58:55 +000083
84 io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL,
85 &memmap_dev_handle);
Dan Handley9df48042015-03-19 18:58:55 +000086
Louis Mayencourt7d24ce12020-01-29 14:43:06 +000087 return io_result;
Dan Handley9df48042015-03-19 18:58:55 +000088}
89
90void plat_arm_io_setup(void)
91{
Louis Mayencourt7d24ce12020-01-29 14:43:06 +000092 int err;
93
94 err = arm_io_setup();
95 if (err < 0) {
96 panic();
97 }
Dan Handley9df48042015-03-19 18:58:55 +000098}
99
100int plat_arm_get_alt_image_source(
Soren Brinkmann46dd1702016-01-14 10:11:05 -0800101 unsigned int image_id __unused,
102 uintptr_t *dev_handle __unused,
103 uintptr_t *image_spec __unused)
Dan Handley9df48042015-03-19 18:58:55 +0000104{
105 /* By default do not try an alternative */
Juan Castillo6e762062015-11-02 10:47:01 +0000106 return -ENOENT;
Dan Handley9df48042015-03-19 18:58:55 +0000107}
108
109/* Return an IO device handle and specification which can be used to access
110 * an image. Use this to enforce platform load policy */
Juan Castillo3a66aca2015-04-13 17:36:19 +0100111int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
Dan Handley9df48042015-03-19 18:58:55 +0000112 uintptr_t *image_spec)
113{
Juan Castillo6e762062015-11-02 10:47:01 +0000114 int result;
Dan Handley9df48042015-03-19 18:58:55 +0000115 const struct plat_io_policy *policy;
116
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000117 policy = FCONF_GET_PROPERTY(arm, io_policies, image_id);
Juan Castillo3a66aca2015-04-13 17:36:19 +0100118 result = policy->check(policy->image_spec);
Juan Castillo6e762062015-11-02 10:47:01 +0000119 if (result == 0) {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100120 *image_spec = policy->image_spec;
121 *dev_handle = *(policy->dev_handle);
Dan Handley9df48042015-03-19 18:58:55 +0000122 } else {
Juan Castillo3a66aca2015-04-13 17:36:19 +0100123 VERBOSE("Trying alternative IO\n");
124 result = plat_arm_get_alt_image_source(image_id, dev_handle,
125 image_spec);
Dan Handley9df48042015-03-19 18:58:55 +0000126 }
Juan Castillo3a66aca2015-04-13 17:36:19 +0100127
Dan Handley9df48042015-03-19 18:58:55 +0000128 return result;
129}
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100130
131/*
132 * See if a Firmware Image Package is available,
133 * by checking if TOC is valid or not.
134 */
Louis Mayencourt70d7c092020-01-29 11:42:31 +0000135bool arm_io_is_toc_valid(void)
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100136{
Louis Mayencourt70d7c092020-01-29 11:42:31 +0000137 return (io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID) == 0);
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100138}