diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2017-11-01 22:06:46 +0000 |
---|---|---|
committer | android-build-prod (mdb) <android-build-team-robot@google.com> | 2017-11-01 22:06:46 +0000 |
commit | e0b7f4e72df2c34c82f19b463eb63a78cfb4347e (patch) | |
tree | 1c743b0eef46e536bb5e9d2066e85f3341c6cc27 | |
parent | 36aa82dda56169333aba6b2c55341404c1d631f0 (diff) | |
parent | 8fa3096942d2faed55122efd47348dacca991141 (diff) | |
download | arm-trusted-firmware-e0b7f4e72df2c34c82f19b463eb63a78cfb4347e.tar.gz |
Snap for 4429331 from 8fa3096942d2faed55122efd47348dacca991141 to sdk-release
Change-Id: Ibfc3f4a5649dd900d94c2fb3a88a04f9c20b1f06
-rw-r--r-- | include/bl31/runtime_svc.h | 4 | ||||
-rw-r--r-- | include/lib/utils.h | 83 | ||||
-rw-r--r-- | plat/hikey/bl1_plat_setup.c | 15 | ||||
-rw-r--r-- | plat/hikey/drivers/hisi_ipc.c | 16 | ||||
-rw-r--r-- | plat/hikey/drivers/hisi_pwrc.c | 6 | ||||
-rw-r--r-- | plat/hikey/hikey_def.h | 10 | ||||
-rw-r--r-- | plat/hikey/include/hi6553.h | 2 | ||||
-rw-r--r-- | plat/hikey/plat_security.c | 13 |
8 files changed, 142 insertions, 7 deletions
diff --git a/include/bl31/runtime_svc.h b/include/bl31/runtime_svc.h index f1124183..de400412 100644 --- a/include/bl31/runtime_svc.h +++ b/include/bl31/runtime_svc.h @@ -31,6 +31,8 @@ #ifndef __RUNTIME_SVC_H__ #define __RUNTIME_SVC_H__ +#include <utils.h> + /******************************************************************************* * Bit definitions inside the function id as per the SMC calling convention ******************************************************************************/ @@ -57,7 +59,7 @@ #define SMC_64 1 #define SMC_32 0 #define SMC_UNK 0xffffffff -#define SMC_TYPE_FAST 1 +#define SMC_TYPE_FAST ULL(1) #define SMC_TYPE_STD 0 #define SMC_PREEMPTED 0xfffffffe /******************************************************************************* diff --git a/include/lib/utils.h b/include/lib/utils.h new file mode 100644 index 00000000..b6bc9af6 --- /dev/null +++ b/include/lib/utils.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of ARM nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __UTILS_H__ +#define __UTILS_H__ + +/* Compute the number of elements in the given array */ +#define ARRAY_SIZE(a) \ + (sizeof(a) / sizeof((a)[0])) + +#define IS_POWER_OF_TWO(x) \ + (((x) & ((x) - 1)) == 0) + +#define SIZE_FROM_LOG2_WORDS(n) (4 << (n)) + +#define BIT(nr) (1UL << (nr)) + +/* + * The round_up() macro rounds up a value to the given boundary in a + * type-agnostic yet type-safe manner. The boundary must be a power of two. + * In other words, it computes the smallest multiple of boundary which is + * greater than or equal to value. + * + * round_down() is similar but rounds the value down instead. + */ +#define round_boundary(value, boundary) \ + ((__typeof__(value))((boundary) - 1)) + +#define round_up(value, boundary) \ + ((((value) - 1) | round_boundary(value, boundary)) + 1) + +#define round_down(value, boundary) \ + ((value) & ~round_boundary(value, boundary)) + +/* + * Evaluates to 1 if (ptr + inc) overflows, 0 otherwise. + * Both arguments must be unsigned pointer values (i.e. uintptr_t). + */ +#define check_uptr_overflow(ptr, inc) \ + (((ptr) > UINTPTR_MAX - (inc)) ? 1 : 0) + +/* + * For those constants to be shared between C and other sources, apply a 'ull' + * suffix to the argument only in C, to avoid undefined or unintended behaviour. + * + * The GNU assembler and linker do not support the 'ull' suffix (it causes the + * build process to fail) therefore the suffix is omitted when used in linker + * scripts and assembler files. +*/ +#if defined(__LINKER__) || defined(__ASSEMBLY__) +# define ULL(_x) (_x) +#else +# define ULL(_x) (_x##ull) +#endif + +#endif /* __UTILS_H__ */ diff --git a/plat/hikey/bl1_plat_setup.c b/plat/hikey/bl1_plat_setup.c index 984c0eea..cb3b252b 100644 --- a/plat/hikey/bl1_plat_setup.c +++ b/plat/hikey/bl1_plat_setup.c @@ -384,6 +384,12 @@ static void hikey_hi6553_init(void) hi6553_write_8(LDO15_REG_ADJ, data); hi6553_write_8(ENABLE3_LDO9_16, 1 << 6); mdelay(5); + /* enable LDO21 */ + data = hi6553_read_8(LDO21_REG_ADJ); + data = (data & 0xf8) | 0x3; + hi6553_write_8(LDO21_REG_ADJ, data); + hi6553_write_8(ENABLE4_LDO17_22, 1 << 4); + mdelay(5); /* enable LDO22 */ data = hi6553_read_8(LDO22_REG_ADJ); data = (data & 0xf8) | 0x7; @@ -393,6 +399,11 @@ static void hikey_hi6553_init(void) /* select 32.764KHz */ hi6553_write_8(CLK19M2_600_586_EN, 0x01); + + /* Disable PMIC internal interrupt */ + data = hi6553_read_8(IRQ2_MASK); + data = data | 0x3; + hi6553_write_8(IRQ2_MASK, data); } static void hikey_gpio_init(void) @@ -425,6 +436,10 @@ static void hikey_gpio_init(void) gpio_direction_output(34); gpio_direction_output(35); + /* Clear GPIO5 and GPIO6 interrutps */ + mmio_write_32(GPIO5_BASE + 0x41C, 0xFF); + mmio_write_32(GPIO6_BASE + 0x41C, 0xFF); + /* Initialize PWR_HOLD GPIO */ gpio_set_value(0, 1); gpio_direction_output(0); diff --git a/plat/hikey/drivers/hisi_ipc.c b/plat/hikey/drivers/hisi_ipc.c index c3b34d31..393982c1 100644 --- a/plat/hikey/drivers/hisi_ipc.c +++ b/plat/hikey/drivers/hisi_ipc.c @@ -37,6 +37,8 @@ #include <stdarg.h> #include <string.h> +#include <hi6220_regs_acpu.h> + #define BIT(x) (0x1 << (x)) static int _ipc_init = 0; @@ -138,7 +140,21 @@ void hisi_ipc_cpu_on_off(unsigned int cpu, unsigned int cluster, void hisi_ipc_cpu_on(unsigned int cpu, unsigned int cluster) { + unsigned int data, expected; + hisi_ipc_cpu_on_off(cpu, cluster, HISI_IPC_PM_ON); + + /* Enable debug module */ + data = mmio_read_32(ACPU_SC_PDBGUP_MBIST); + if (cluster) + expected = 1 << (cpu + PDBGUP_CLUSTER1_SHIFT); + else + expected = 1 << cpu; + mmio_write_32(ACPU_SC_PDBGUP_MBIST, data | expected); + do { + /* RAW barrier */ + data = mmio_read_32(ACPU_SC_PDBGUP_MBIST); + } while (!(data & expected)); } void hisi_ipc_cpu_off(unsigned int cpu, unsigned int cluster) diff --git a/plat/hikey/drivers/hisi_pwrc.c b/plat/hikey/drivers/hisi_pwrc.c index 9f189da7..c1d9e471 100644 --- a/plat/hikey/drivers/hisi_pwrc.c +++ b/plat/hikey/drivers/hisi_pwrc.c @@ -98,7 +98,13 @@ int hisi_pwrc_setup(void) pm_asm_code_end - pm_asm_code); reg = mmio_read_32(0xF7800000 + 0x004); + + /* Remap SRAM address */ reg |= BIT(0x1) | BIT(17); + + /* Enable reset signal for watchdog */ + reg |= BIT(0x0) | BIT(16); + mmio_write_32(0xF7800000 + 0x004, reg); return 0; diff --git a/plat/hikey/hikey_def.h b/plat/hikey/hikey_def.h index 20076337..d81b6d7a 100644 --- a/plat/hikey/hikey_def.h +++ b/plat/hikey/hikey_def.h @@ -46,13 +46,19 @@ #define PLAT_TRUSTED_DRAM_ID 1 /* - * DRAM at 0x0000_0000 is divided in two regions: - * - Secure DRAM (default is the top 16MB) + * DRAM (1 GB) at 0x0000_0000 is divided in several regions: + * - Secure DRAM (default is the top 16MB) used by OP-TEE + * - Non-secure DRAM used by OP-TEE (shared memory and padding) (4MB) + * - Secure DRAM (4MB aligned on 4MB) for OP-TEE's "Secure Data Path" feature * - Non-Secure DRAM (remaining DRAM starting at DRAM_BASE) */ #define DRAM_SEC_SIZE 0x01000000 #define DRAM_SEC_BASE (DRAM_BASE + DRAM_SIZE - DRAM_SEC_SIZE) +#define DRAM_SDP_SIZE 0x00400000 +#define DRAM_SDP_BASE (DRAM_SEC_BASE - 0x400000 /* align */ - \ + DRAM_SDP_SIZE) + #define DRAM_NS_BASE DRAM_BASE #define DRAM_NS_SIZE (DRAM_SIZE - DRAM_SEC_SIZE) diff --git a/plat/hikey/include/hi6553.h b/plat/hikey/include/hi6553.h index 9efc5808..7e642c02 100644 --- a/plat/hikey/include/hi6553.h +++ b/plat/hikey/include/hi6553.h @@ -41,6 +41,7 @@ #define DISABLE6_XO_CLK_RF2 (1 << 4) #define VERSION_REG 0x000 +#define IRQ2_MASK 0x008 #define ENABLE2_LDO1_8 0x029 #define DISABLE2_LDO1_8 0x02a #define ONOFF_STATUS2_LDO1_8 0x02b @@ -70,6 +71,7 @@ #define LDO15_REG_ADJ 0x080 #define LDO19_REG_ADJ 0x084 #define LDO20_REG_ADJ 0x085 +#define LDO21_REG_ADJ 0x086 #define LDO22_REG_ADJ 0x087 #define DR_LED_CTRL 0x098 #define DR_OUT_CTRL 0x099 diff --git a/plat/hikey/plat_security.c b/plat/hikey/plat_security.c index b2cd6024..dc439c7b 100644 --- a/plat/hikey/plat_security.c +++ b/plat/hikey/plat_security.c @@ -90,13 +90,17 @@ static int is_power_of_two(uint32_t x) * region_size must be a power of 2 and at least 64KB * region_base must be region_size aligned */ -static void sec_protect(uint32_t region_base, uint32_t region_size) +static void sec_protect(uint32_t region_base, uint32_t region_size, + int region) { volatile struct int_en_reg *int_en_reg ; volatile struct rgn_map_reg *rgn_map_reg; volatile struct rgn_attr_reg *rgn_attr_reg; uint32_t i = 0; + if (region < 1 || region > 15) { + ERROR("Secure region number is invalid\n"); + } if (!is_power_of_two(region_size) || region_size < 0x10000) { ERROR("Secure region size is not a power of 2 >= 64KB\n"); return; @@ -113,8 +117,8 @@ static void sec_protect(uint32_t region_base, uint32_t region_size) int_en_reg->in_en = 0x1; for (i = 0; i < PORTNUM_MAX; i++) { - rgn_map_reg = get_rgn_map_reg(MDDRC_SECURITY_BASE, 1, i); - rgn_attr_reg = get_rgn_attr_reg(MDDRC_SECURITY_BASE, 1, i); + rgn_map_reg = get_rgn_map_reg(MDDRC_SECURITY_BASE, region, i); + rgn_attr_reg = get_rgn_attr_reg(MDDRC_SECURITY_BASE, region, i); rgn_map_reg->rgn_base_addr = region_base >> 16; rgn_attr_reg->subrgn_disable = 0x0; rgn_attr_reg->sp = (i == 3) ? 0xC : 0x0; @@ -128,5 +132,6 @@ static void sec_protect(uint32_t region_base, uint32_t region_size) ******************************************************************************/ void plat_security_setup(void) { - sec_protect(DRAM_SEC_BASE, DRAM_SEC_SIZE); + sec_protect(DRAM_SEC_BASE, DRAM_SEC_SIZE, 1); + sec_protect(DRAM_SDP_BASE, DRAM_SDP_SIZE, 2); } |