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 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #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 Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 13 | |
| 14 | #include <plat/arm/common/arm_fconf_getter.h> |
| 15 | #include <plat/arm/common/arm_fconf_io_storage.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 16 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | #include <plat/common/platform.h> |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 18 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 19 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 20 | /* IO devices */ |
| 21 | static const io_dev_connector_t *fip_dev_con; |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 22 | uintptr_t fip_dev_handle; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 23 | static const io_dev_connector_t *memmap_dev_con; |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 24 | uintptr_t memmap_dev_handle; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 25 | |
| 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 Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 30 | int open_fip(const uintptr_t spec) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 31 | { |
| 32 | int result; |
| 33 | uintptr_t local_image_handle; |
| 34 | |
| 35 | /* See if a Firmware Image Package is available */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 36 | result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 37 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 38 | result = io_open(fip_dev_handle, spec, &local_image_handle); |
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 | VERBOSE("Using FIP\n"); |
| 41 | io_close(local_image_handle); |
| 42 | } |
| 43 | } |
| 44 | return result; |
| 45 | } |
| 46 | |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 47 | int open_memmap(const uintptr_t spec) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 48 | { |
| 49 | int result; |
| 50 | uintptr_t local_image_handle; |
| 51 | |
| 52 | result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 53 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 54 | result = io_open(memmap_dev_handle, spec, &local_image_handle); |
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 | VERBOSE("Using Memmap\n"); |
| 57 | io_close(local_image_handle); |
| 58 | } |
| 59 | } |
| 60 | return result; |
| 61 | } |
| 62 | |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 63 | int arm_io_setup(void) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 64 | { |
| 65 | int io_result; |
| 66 | |
| 67 | io_result = register_io_dev_fip(&fip_dev_con); |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 68 | if (io_result < 0) { |
| 69 | return io_result; |
| 70 | } |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 71 | |
| 72 | io_result = register_io_dev_memmap(&memmap_dev_con); |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 73 | if (io_result < 0) { |
| 74 | return io_result; |
| 75 | } |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 76 | |
| 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 Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 80 | if (io_result < 0) { |
| 81 | return io_result; |
| 82 | } |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 83 | |
| 84 | io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL, |
| 85 | &memmap_dev_handle); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 86 | |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 87 | return io_result; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void plat_arm_io_setup(void) |
| 91 | { |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 92 | int err; |
| 93 | |
| 94 | err = arm_io_setup(); |
| 95 | if (err < 0) { |
| 96 | panic(); |
| 97 | } |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | int plat_arm_get_alt_image_source( |
Soren Brinkmann | 46dd170 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 101 | unsigned int image_id __unused, |
| 102 | uintptr_t *dev_handle __unused, |
| 103 | uintptr_t *image_spec __unused) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 104 | { |
| 105 | /* By default do not try an alternative */ |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 106 | return -ENOENT; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 107 | } |
| 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 Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 111 | 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] | 112 | uintptr_t *image_spec) |
| 113 | { |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 114 | int result; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 115 | const struct plat_io_policy *policy; |
| 116 | |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 117 | policy = FCONF_GET_PROPERTY(arm, io_policies, image_id); |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 118 | result = policy->check(policy->image_spec); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 119 | if (result == 0) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 120 | *image_spec = policy->image_spec; |
| 121 | *dev_handle = *(policy->dev_handle); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 122 | } else { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 123 | VERBOSE("Trying alternative IO\n"); |
| 124 | result = plat_arm_get_alt_image_source(image_id, dev_handle, |
| 125 | image_spec); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 126 | } |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 127 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 128 | return result; |
| 129 | } |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * See if a Firmware Image Package is available, |
| 133 | * by checking if TOC is valid or not. |
| 134 | */ |
Louis Mayencourt | 70d7c09 | 2020-01-29 11:42:31 +0000 | [diff] [blame] | 135 | bool arm_io_is_toc_valid(void) |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 136 | { |
Louis Mayencourt | 70d7c09 | 2020-01-29 11:42:31 +0000 | [diff] [blame] | 137 | 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] | 138 | } |