3 * Security related functions for OMAP5 class devices
6 * Texas Instruments, <www.ti.com>
8 * Daniel Allred <d-allred@ti.com>
9 * Harinarayan Bhatta <harinarayan@ti.com>
11 * SPDX-License-Identifier: GPL-2.0+
17 #include <asm/arch/sys_proto.h>
18 #include <asm/omap_common.h>
19 #include <asm/omap_sec_common.h>
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)
29 static u32 get_sec_mem_start(void)
31 u32 sec_mem_start = CONFIG_TI_SECURE_EMIF_REGION_START;
32 u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;
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.
39 if (sec_mem_start == 0)
41 (CONFIG_SYS_SDRAM_BASE +
42 (omap_sdram_size() - sec_mem_size));
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)
53 * Call PPA HAL API to do any other general firewall
54 * configuration for regions 1-6 of the EMIF firewall.
56 debug("%s: regionNum = %x, startAddr = %x, size = %x", __func__,
57 region_num, start_addr, size);
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);
65 puts("Secure EMIF Firewall Setup failed!\n");
66 debug("Return Value = %x\n", result);
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."
76 int secure_emif_reserve(void)
79 u32 sec_mem_start = get_sec_mem_start();
80 u32 sec_prot_size = CONFIG_TI_SECURE_EMIF_PROTECTED_REGION_SIZE;
82 /* If there is no protected region, there is no reservation to make */
83 if (sec_prot_size == 0)
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.
92 result = secure_rom_call(
93 PPA_SERV_HAL_SETUP_SEC_RESVD_REGION,
94 0, 0, 2, sec_mem_start, sec_prot_size);
97 puts("SDRAM Firewall: Secure memory reservation failed!\n");
98 debug("Return Value = %x\n", result);
104 int secure_emif_firewall_lock(void)
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
116 result = secure_rom_call(
117 PPA_SERV_HAL_LOCK_EMIF_FW,
121 puts("Secure EMIF Firewall Lock failed!\n");
122 debug("Return Value = %x\n", result);