Daniel Allred | 5f858eb | 2016-09-02 00:40:21 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * |
| 3 | * Security related functions for OMAP5 class devices |
| 4 | * |
| 5 | * (C) Copyright 2016 |
| 6 | * Texas Instruments, <www.ti.com> |
| 7 | * |
| 8 | * Daniel Allred <d-allred@ti.com> |
| 9 | * Harinarayan Bhatta <harinarayan@ti.com> |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0+ |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <stdarg.h> |
| 16 | |
| 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <asm/omap_common.h> |
| 19 | #include <asm/omap_sec_common.h> |
| 20 | #include <asm/spl.h> |
| 21 | #include <spl.h> |
| 22 | |
| 23 | /* Index for signature PPA-based TI HAL APIs */ |
| 24 | #define PPA_HAL_SERVICES_START_INDEX (0x200) |
| 25 | #define PPA_SERV_HAL_SETUP_SEC_RESVD_REGION (PPA_HAL_SERVICES_START_INDEX + 25) |
| 26 | #define PPA_SERV_HAL_SETUP_EMIF_FW_REGION (PPA_HAL_SERVICES_START_INDEX + 26) |
| 27 | #define PPA_SERV_HAL_LOCK_EMIF_FW (PPA_HAL_SERVICES_START_INDEX + 27) |
| 28 | |
| 29 | static u32 get_sec_mem_start(void) |
| 30 | { |
| 31 | u32 sec_mem_start = CONFIG_TI_SECURE_EMIF_REGION_START; |
| 32 | u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE; |
| 33 | /* |
| 34 | * Total reserved region is all contiguous with protected |
| 35 | * region coming first, followed by the non-secure region. |
| 36 | * If 0x0 start address is given, we simply put the reserved |
| 37 | * region at the end of the external DRAM. |
| 38 | */ |
| 39 | if (sec_mem_start == 0) |
| 40 | sec_mem_start = |
| 41 | (CONFIG_SYS_SDRAM_BASE + |
| 42 | (omap_sdram_size() - sec_mem_size)); |
| 43 | return sec_mem_start; |
| 44 | } |
| 45 | |
| 46 | int secure_emif_firewall_setup(uint8_t region_num, uint32_t start_addr, |
| 47 | uint32_t size, uint32_t access_perm, |
| 48 | uint32_t initiator_perm) |
| 49 | { |
| 50 | int result = 1; |
| 51 | |
| 52 | /* |
| 53 | * Call PPA HAL API to do any other general firewall |
| 54 | * configuration for regions 1-6 of the EMIF firewall. |
| 55 | */ |
| 56 | debug("%s: regionNum = %x, startAddr = %x, size = %x", __func__, |
| 57 | region_num, start_addr, size); |
| 58 | |
| 59 | result = secure_rom_call( |
| 60 | PPA_SERV_HAL_SETUP_EMIF_FW_REGION, 0, 0, 4, |
| 61 | (start_addr & 0xFFFFFFF0) | (region_num & 0x0F), |
| 62 | size, access_perm, initiator_perm); |
| 63 | |
| 64 | if (result != 0) { |
| 65 | puts("Secure EMIF Firewall Setup failed!\n"); |
| 66 | debug("Return Value = %x\n", result); |
| 67 | } |
| 68 | |
| 69 | return result; |
| 70 | } |
| 71 | |
| 72 | #if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE < \ |
| 73 | CONFIG_TI_SECURE_EMIF_PROTECTED_REGION_SIZE) |
| 74 | #error "TI Secure EMIF: Protected size cannot be larger than total size." |
| 75 | #endif |
| 76 | int secure_emif_reserve(void) |
| 77 | { |
| 78 | int result = 1; |
| 79 | u32 sec_mem_start = get_sec_mem_start(); |
| 80 | u32 sec_prot_size = CONFIG_TI_SECURE_EMIF_PROTECTED_REGION_SIZE; |
| 81 | |
| 82 | /* If there is no protected region, there is no reservation to make */ |
| 83 | if (sec_prot_size == 0) |
| 84 | return 0; |
| 85 | |
| 86 | /* |
| 87 | * Call PPA HAL API to reserve a chunk of EMIF SDRAM |
| 88 | * for secure world use. This region should be carved out |
| 89 | * from use by any public code. EMIF firewall region 7 |
| 90 | * will be used to protect this block of memory. |
| 91 | */ |
| 92 | result = secure_rom_call( |
| 93 | PPA_SERV_HAL_SETUP_SEC_RESVD_REGION, |
| 94 | 0, 0, 2, sec_mem_start, sec_prot_size); |
| 95 | |
| 96 | if (result != 0) { |
| 97 | puts("SDRAM Firewall: Secure memory reservation failed!\n"); |
| 98 | debug("Return Value = %x\n", result); |
| 99 | } |
| 100 | |
| 101 | return result; |
| 102 | } |
| 103 | |
| 104 | int secure_emif_firewall_lock(void) |
| 105 | { |
| 106 | int result = 1; |
| 107 | |
| 108 | /* |
| 109 | * Call PPA HAL API to lock the EMIF firewall configurations. |
| 110 | * After this API is called, none of the PPA HAL APIs for |
| 111 | * configuring the EMIF firewalls will be usable again (that |
| 112 | * is, calls to those APIs will return failure and have no |
| 113 | * effect). |
| 114 | */ |
| 115 | |
| 116 | result = secure_rom_call( |
| 117 | PPA_SERV_HAL_LOCK_EMIF_FW, |
| 118 | 0, 0, 0); |
| 119 | |
| 120 | if (result != 0) { |
| 121 | puts("Secure EMIF Firewall Lock failed!\n"); |
| 122 | debug("Return Value = %x\n", result); |
| 123 | } |
| 124 | |
| 125 | return result; |
| 126 | } |