Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2020, ARM Limited. All rights reserved. |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 5 | */ |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 6 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <common/debug.h> |
| 10 | #include <drivers/io/io_driver.h> |
| 11 | #include <drivers/io/io_fip.h> |
| 12 | #include <drivers/io/io_memmap.h> |
| 13 | #include <drivers/io/io_storage.h> |
| 14 | #include <lib/utils.h> |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 15 | |
| 16 | #include <plat/arm/common/arm_fconf_getter.h> |
| 17 | #include <plat/arm/common/arm_fconf_io_storage.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 18 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 19 | #include <plat/common/platform.h> |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 20 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 21 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 22 | /* IO devices */ |
| 23 | static const io_dev_connector_t *fip_dev_con; |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 24 | uintptr_t fip_dev_handle; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 25 | static const io_dev_connector_t *memmap_dev_con; |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 26 | uintptr_t memmap_dev_handle; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 27 | |
| 28 | /* Weak definitions may be overridden in specific ARM standard platform */ |
| 29 | #pragma weak plat_arm_io_setup |
| 30 | #pragma weak plat_arm_get_alt_image_source |
| 31 | |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 32 | int open_fip(const uintptr_t spec) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 33 | { |
| 34 | int result; |
| 35 | uintptr_t local_image_handle; |
| 36 | |
| 37 | /* See if a Firmware Image Package is available */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 38 | result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 39 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 40 | result = io_open(fip_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 41 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 42 | VERBOSE("Using FIP\n"); |
| 43 | io_close(local_image_handle); |
| 44 | } |
| 45 | } |
| 46 | return result; |
| 47 | } |
| 48 | |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 49 | int open_memmap(const uintptr_t spec) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 50 | { |
| 51 | int result; |
| 52 | uintptr_t local_image_handle; |
| 53 | |
| 54 | result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 55 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 56 | result = io_open(memmap_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 57 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 58 | VERBOSE("Using Memmap\n"); |
| 59 | io_close(local_image_handle); |
| 60 | } |
| 61 | } |
| 62 | return result; |
| 63 | } |
| 64 | |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 65 | int arm_io_setup(void) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 66 | { |
| 67 | int io_result; |
| 68 | |
| 69 | io_result = register_io_dev_fip(&fip_dev_con); |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 70 | if (io_result < 0) { |
| 71 | return io_result; |
| 72 | } |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 73 | |
| 74 | io_result = register_io_dev_memmap(&memmap_dev_con); |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 75 | if (io_result < 0) { |
| 76 | return io_result; |
| 77 | } |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 78 | |
| 79 | /* Open connections to devices and cache the handles */ |
| 80 | io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL, |
| 81 | &fip_dev_handle); |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 82 | if (io_result < 0) { |
| 83 | return io_result; |
| 84 | } |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 85 | |
| 86 | io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL, |
| 87 | &memmap_dev_handle); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 88 | |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 89 | return io_result; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void plat_arm_io_setup(void) |
| 93 | { |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 94 | int err; |
| 95 | |
| 96 | err = arm_io_setup(); |
| 97 | if (err < 0) { |
| 98 | panic(); |
| 99 | } |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | int plat_arm_get_alt_image_source( |
Soren Brinkmann | 46dd170 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 103 | unsigned int image_id __unused, |
| 104 | uintptr_t *dev_handle __unused, |
| 105 | uintptr_t *image_spec __unused) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 106 | { |
| 107 | /* By default do not try an alternative */ |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 108 | return -ENOENT; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* Return an IO device handle and specification which can be used to access |
| 112 | * an image. Use this to enforce platform load policy */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 113 | int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 114 | uintptr_t *image_spec) |
| 115 | { |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 116 | int result; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 117 | const struct plat_io_policy *policy; |
| 118 | |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 119 | assert(image_id < MAX_NUMBER_IDS); |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 120 | |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 121 | policy = FCONF_GET_PROPERTY(arm, io_policies, image_id); |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 122 | result = policy->check(policy->image_spec); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 123 | if (result == 0) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 124 | *image_spec = policy->image_spec; |
| 125 | *dev_handle = *(policy->dev_handle); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 126 | } else { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 127 | VERBOSE("Trying alternative IO\n"); |
| 128 | result = plat_arm_get_alt_image_source(image_id, dev_handle, |
| 129 | image_spec); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 130 | } |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 131 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 132 | return result; |
| 133 | } |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * See if a Firmware Image Package is available, |
| 137 | * by checking if TOC is valid or not. |
| 138 | */ |
Louis Mayencourt | 70d7c09 | 2020-01-29 11:42:31 +0000 | [diff] [blame] | 139 | bool arm_io_is_toc_valid(void) |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 140 | { |
Louis Mayencourt | 70d7c09 | 2020-01-29 11:42:31 +0000 | [diff] [blame] | 141 | return (io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID) == 0); |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 142 | } |