Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <assert.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 32 | #include <debug.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 33 | #include <tzc400.h> |
| 34 | #include "fvp_def.h" |
| 35 | #include "fvp_private.h" |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 36 | |
| 37 | /* Used to improve readability for configuring regions. */ |
| 38 | #define FILTER_SHIFT(filter) (1 << filter) |
| 39 | |
| 40 | /* |
| 41 | * For the moment we assume that all security programming is done by the |
| 42 | * primary core. |
| 43 | * TODO: |
| 44 | * Might want to enable interrupt on violations when supported? |
| 45 | */ |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 46 | void fvp_security_setup(void) |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 47 | { |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 48 | tzc_instance_t controller; |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * The Base FVP has a TrustZone address space controller, the Foundation |
| 52 | * FVP does not. Trying to program the device on the foundation FVP will |
| 53 | * cause an abort. |
| 54 | * |
| 55 | * If the platform had additional peripheral specific security |
| 56 | * configurations, those would be configured here. |
| 57 | */ |
| 58 | |
Dan Handley | ea45157 | 2014-05-15 14:53:30 +0100 | [diff] [blame] | 59 | if (!fvp_get_cfgvar(CONFIG_HAS_TZC)) |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 60 | return; |
| 61 | |
| 62 | /* |
| 63 | * The TrustZone controller controls access to main DRAM. Give |
| 64 | * full NS access for the moment to use with OS. |
| 65 | */ |
| 66 | INFO("Configuring TrustZone Controller\n"); |
| 67 | |
| 68 | /* |
| 69 | * The driver does some error checking and will assert. |
| 70 | * - Provide base address of device on platform. |
| 71 | * - Provide width of ACE-Lite IDs on platform. |
| 72 | */ |
| 73 | controller.base = TZC400_BASE; |
| 74 | controller.aid_width = FVP_AID_WIDTH; |
| 75 | tzc_init(&controller); |
| 76 | |
| 77 | /* |
| 78 | * Currently only filters 0 and 2 are connected on Base FVP. |
| 79 | * Filter 0 : CPU clusters (no access to DRAM by default) |
| 80 | * Filter 1 : not connected |
| 81 | * Filter 2 : LCDs (access to VRAM allowed by default) |
| 82 | * Filter 3 : not connected |
| 83 | * Programming unconnected filters will have no effect at the |
| 84 | * moment. These filter could, however, be connected in future. |
| 85 | * So care should be taken not to configure the unused filters. |
| 86 | */ |
| 87 | |
| 88 | /* Disable all filters before programming. */ |
| 89 | tzc_disable_filters(&controller); |
| 90 | |
| 91 | /* |
Andrew Thoelke | fe3374b | 2014-05-09 15:36:13 +0100 | [diff] [blame] | 92 | * Allow only non-secure access to all DRAM to supported devices. |
| 93 | * Give access to the CPUs and Virtio. Some devices |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 94 | * would normally use the default ID so allow that too. We use |
Andrew Thoelke | fe3374b | 2014-05-09 15:36:13 +0100 | [diff] [blame] | 95 | * two regions to cover the blocks of physical memory in the FVPs. |
| 96 | * |
| 97 | * Software executing in the secure state, such as a secure |
| 98 | * boot-loader, can access the DRAM by using the NS attributes in |
| 99 | * the MMU translation tables and descriptors. |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 100 | */ |
| 101 | |
Andrew Thoelke | fe3374b | 2014-05-09 15:36:13 +0100 | [diff] [blame] | 102 | /* Set to cover the first block of DRAM */ |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 103 | tzc_configure_region(&controller, FILTER_SHIFT(0), 1, |
Juan Castillo | 7055ca4 | 2014-05-16 15:33:15 +0100 | [diff] [blame] | 104 | DRAM1_BASE, DRAM1_END - DRAM1_SEC_SIZE, |
| 105 | TZC_REGION_S_NONE, |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 106 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_DEFAULT) | |
Andrew Thoelke | fe3374b | 2014-05-09 15:36:13 +0100 | [diff] [blame] | 107 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_PCI) | |
| 108 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_AP) | |
| 109 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_VIRTIO) | |
| 110 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_VIRTIO_OLD)); |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 111 | |
Juan Castillo | 7055ca4 | 2014-05-16 15:33:15 +0100 | [diff] [blame] | 112 | /* Set to cover the secure reserved region */ |
| 113 | tzc_configure_region(&controller, FILTER_SHIFT(0), 3, |
| 114 | (DRAM1_END - DRAM1_SEC_SIZE) + 1 , DRAM1_END, |
| 115 | TZC_REGION_S_RDWR, |
| 116 | 0x0); |
| 117 | |
Andrew Thoelke | fe3374b | 2014-05-09 15:36:13 +0100 | [diff] [blame] | 118 | /* Set to cover the second block of DRAM */ |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 119 | tzc_configure_region(&controller, FILTER_SHIFT(0), 2, |
Juan Castillo | 7055ca4 | 2014-05-16 15:33:15 +0100 | [diff] [blame] | 120 | DRAM2_BASE, DRAM2_END, TZC_REGION_S_NONE, |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 121 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_DEFAULT) | |
Andrew Thoelke | fe3374b | 2014-05-09 15:36:13 +0100 | [diff] [blame] | 122 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_PCI) | |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 123 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_AP) | |
Andrew Thoelke | fe3374b | 2014-05-09 15:36:13 +0100 | [diff] [blame] | 124 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_VIRTIO) | |
| 125 | TZC_REGION_ACCESS_RDWR(FVP_NSAID_VIRTIO_OLD)); |
Harry Liebel | cef9339 | 2014-04-01 19:27:38 +0100 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * TODO: Interrupts are not currently supported. The only |
| 129 | * options we have are for access errors to occur quietly or to |
| 130 | * cause an exception. We choose to cause an exception. |
| 131 | */ |
| 132 | tzc_set_action(&controller, TZC_ACTION_ERR); |
| 133 | |
| 134 | /* Enable filters. */ |
| 135 | tzc_enable_filters(&controller); |
| 136 | } |