From c1185ffde17cf2fdf50aac172a0be9e2d7669fd0 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Fri, 24 May 2019 20:37:58 -0700 Subject: [PATCH] plat/rockchip: Switch to use new common BL aux parameter library This patch changes all Rockchip platforms to use the new common BL aux parameter helpers. Since the parameter space is now cleanly split in generic and vendor-specific parameters and the COREBOOT_TABLE parameter is now generic, the parameter type number for that parameter has to change. Since it only affects coreboot which always builds TF as a submodule and includes its headers directly to get these constants, this should not cause any issues. In general, after this point, we should avoid changing already assigned parameter type numbers whenever possible. Change-Id: Ic99ddd1e91ff5e5fe212fa30c793a0b8394c9dad Signed-off-by: Julius Werner --- plat/rockchip/common/bl31_plat_setup.c | 7 +- plat/rockchip/common/include/plat_params.h | 86 ++------------- plat/rockchip/common/include/plat_private.h | 13 +-- plat/rockchip/common/params_setup.c | 109 ++++++++------------ plat/rockchip/common/sp_min_plat_setup.c | 5 +- plat/rockchip/rk3288/platform.mk | 5 +- plat/rockchip/rk3328/platform.mk | 5 +- plat/rockchip/rk3368/platform.mk | 5 +- plat/rockchip/rk3399/drivers/pmu/pmu.c | 14 +-- plat/rockchip/rk3399/drivers/pmu/pmu.h | 2 +- plat/rockchip/rk3399/platform.mk | 5 +- 11 files changed, 86 insertions(+), 170 deletions(-) diff --git a/plat/rockchip/common/bl31_plat_setup.c b/plat/rockchip/common/bl31_plat_setup.c index 18f8dd915..e009b88e1 100644 --- a/plat/rockchip/common/bl31_plat_setup.c +++ b/plat/rockchip/common/bl31_plat_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -41,7 +41,7 @@ entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) } #pragma weak params_early_setup -void params_early_setup(void *plat_param_from_bl2) +void params_early_setup(u_register_t plat_param_from_bl2) { } @@ -58,9 +58,8 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, { static console_16550_t console; struct rockchip_bl31_params *arg_from_bl2 = (struct rockchip_bl31_params *) arg0; - void *plat_params_from_bl2 = (void *) arg1; - params_early_setup(plat_params_from_bl2); + params_early_setup(arg1); #if COREBOOT if (coreboot_serial.type) diff --git a/plat/rockchip/common/include/plat_params.h b/plat/rockchip/common/include/plat_params.h index 1ec02f55e..781123880 100644 --- a/plat/rockchip/common/include/plat_params.h +++ b/plat/rockchip/common/include/plat_params.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -7,59 +7,18 @@ #ifndef PLAT_PARAMS_H #define PLAT_PARAMS_H +#include #include -/* - * We defined several plat parameter structs for BL2 to pass platform related - * parameters to Rockchip BL31 platform code. All plat parameters start with - * a common header, which has a type field to indicate the parameter type, and - * a next pointer points to next parameter. If the parameter is the last one in - * the list, next pointer will points to NULL. After the header comes the - * variable-sized members that describe the parameter. The picture below shows - * how the parameters are kept in memory. - * - * head of list ---> +----------------+ --+ - * | type | | - * +----------------+ |--> struct bl31_plat_param - * +----| next | | - * | +----------------+ --+ - * | | parameter data | - * | +----------------+ - * | - * +--> +----------------+ --+ - * | type | | - * +----------------+ |--> struct bl31_plat_param - * NULL <---| next | | - * +----------------+ --+ - * | parameter data | - * +----------------+ - * - * Note: The SCTLR_EL3.A bit (Alignment fault check enable) of ARM TF is set, - * so be sure each parameter struct starts on 64-bit aligned address. If not, - * alignment fault will occur during accessing its data member. - */ - -#define BL31_GPIO_DIR_OUT 0 -#define BL31_GPIO_DIR_IN 1 - -#define BL31_GPIO_LEVEL_LOW 0 -#define BL31_GPIO_LEVEL_HIGH 1 - -#define BL31_GPIO_PULL_NONE 0 -#define BL31_GPIO_PULL_UP 1 -#define BL31_GPIO_PULL_DOWN 2 - /* param type */ -enum { - PARAM_NONE = 0, - PARAM_RESET, - PARAM_POWEROFF, - PARAM_SUSPEND_GPIO, - PARAM_SUSPEND_APIO, - PARAM_COREBOOT_TABLE, +enum bl_aux_rk_param_type { + BL_AUX_PARAM_RK_RESET_GPIO = BL_AUX_PARAM_VENDOR_SPECIFIC_FIRST, + BL_AUX_PARAM_RK_POWEROFF_GPIO, + BL_AUX_PARAM_RK_SUSPEND_GPIO, + BL_AUX_PARAM_RK_SUSPEND_APIO, }; -struct apio_info { +struct bl_aux_rk_apio_info { uint8_t apio1 : 1; uint8_t apio2 : 1; uint8_t apio3 : 1; @@ -67,32 +26,9 @@ struct apio_info { uint8_t apio5 : 1; }; -struct gpio_info { - uint8_t polarity; - uint8_t direction; - uint8_t pull_mode; - uint32_t index; -}; - -/* common header for all plat parameter type */ -struct bl31_plat_param { - uint64_t type; - void *next; -}; - -struct bl31_gpio_param { - struct bl31_plat_param h; - struct gpio_info gpio; -}; - -struct bl31_apio_param { - struct bl31_plat_param h; - struct apio_info apio; -}; - -struct bl31_u64_param { - struct bl31_plat_param h; - uint64_t value; +struct bl_aux_param_rk_apio { + struct bl_aux_param_header h; + struct bl_aux_rk_apio_info apio; }; #endif /* PLAT_PARAMS_H */ diff --git a/plat/rockchip/common/include/plat_private.h b/plat/rockchip/common/include/plat_private.h index c0ebefc4a..242b52815 100644 --- a/plat/rockchip/common/include/plat_private.h +++ b/plat/rockchip/common/include/plat_private.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2014-2019, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -14,6 +14,7 @@ #include #include #include +#include #define __sramdata __attribute__((section(".sram.data"))) #define __sramconst __attribute__((section(".sram.rodata"))) @@ -94,7 +95,7 @@ void plat_cci_disable(void); void plat_delay_timer_init(void); -void params_early_setup(void *plat_params_from_bl2); +void params_early_setup(u_register_t plat_params_from_bl2); void plat_rockchip_gic_driver_init(void); void plat_rockchip_gic_init(void); @@ -108,10 +109,10 @@ uintptr_t plat_get_sec_entrypoint(void); void platform_cpu_warmboot(void); -struct gpio_info *plat_get_rockchip_gpio_reset(void); -struct gpio_info *plat_get_rockchip_gpio_poweroff(void); -struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count); -struct apio_info *plat_get_rockchip_suspend_apio(void); +struct bl_aux_gpio_info *plat_get_rockchip_gpio_reset(void); +struct bl_aux_gpio_info *plat_get_rockchip_gpio_poweroff(void); +struct bl_aux_gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count); +struct bl_aux_rk_apio_info *plat_get_rockchip_suspend_apio(void); void plat_rockchip_gpio_init(void); void plat_rockchip_save_gpio(void); void plat_rockchip_restore_gpio(void); diff --git a/plat/rockchip/common/params_setup.c b/plat/rockchip/common/params_setup.c index 8a743bfee..d0fea4ffa 100644 --- a/plat/rockchip/common/params_setup.c +++ b/plat/rockchip/common/params_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -20,14 +21,11 @@ #include #include -static struct gpio_info param_reset; -static struct gpio_info param_poweroff; -static struct bl31_apio_param param_apio; -static struct gpio_info *rst_gpio; -static struct gpio_info *poweroff_gpio; -static struct gpio_info suspend_gpio[10]; +static struct bl_aux_gpio_info rst_gpio; +static struct bl_aux_gpio_info poweroff_gpio; +static struct bl_aux_gpio_info suspend_gpio[10]; uint32_t suspend_gpio_cnt; -static struct apio_info *suspend_apio; +static struct bl_aux_rk_apio_info suspend_apio; static uint32_t rk_uart_base = PLAT_RK_UART_BASE; uint32_t rockchip_get_uart_base(void) @@ -36,7 +34,7 @@ uint32_t rockchip_get_uart_base(void) } #if COREBOOT -static int dt_process_fdt(void *blob) +static int dt_process_fdt(u_register_t param_from_bl2) { return -ENODEV; } @@ -105,12 +103,12 @@ static void plat_rockchip_dt_process_fdt_uart(void *fdt) rk_uart_base = uart_base; } -static int dt_process_fdt(void *blob) +static int dt_process_fdt(u_register_t param_from_bl2) { void *fdt = plat_get_fdt(); int ret; - ret = fdt_open_into(blob, fdt, 0x10000); + ret = fdt_open_into((void *)param_from_bl2, fdt, 0x10000); if (ret < 0) return ret; @@ -120,33 +118,56 @@ static int dt_process_fdt(void *blob) } #endif -struct gpio_info *plat_get_rockchip_gpio_reset(void) +struct bl_aux_gpio_info *plat_get_rockchip_gpio_reset(void) { - return rst_gpio; + return &rst_gpio; } -struct gpio_info *plat_get_rockchip_gpio_poweroff(void) +struct bl_aux_gpio_info *plat_get_rockchip_gpio_poweroff(void) { - return poweroff_gpio; + return &poweroff_gpio; } -struct gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count) +struct bl_aux_gpio_info *plat_get_rockchip_suspend_gpio(uint32_t *count) { *count = suspend_gpio_cnt; return &suspend_gpio[0]; } -struct apio_info *plat_get_rockchip_suspend_apio(void) +struct bl_aux_rk_apio_info *plat_get_rockchip_suspend_apio(void) { - return suspend_apio; + return &suspend_apio; } -void params_early_setup(void *plat_param_from_bl2) +static bool rk_aux_param_handler(struct bl_aux_param_header *param) { - struct bl31_plat_param *bl2_param; - struct bl31_gpio_param *gpio_param; + /* Store platform parameters for later processing if needed. */ + switch (param->type) { + case BL_AUX_PARAM_RK_RESET_GPIO: + rst_gpio = ((struct bl_aux_param_gpio *)param)->gpio; + return true; + case BL_AUX_PARAM_RK_POWEROFF_GPIO: + poweroff_gpio = ((struct bl_aux_param_gpio *)param)->gpio; + return true; + case BL_AUX_PARAM_RK_SUSPEND_GPIO: + if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) { + ERROR("Exceeded the supported suspend GPIO number.\n"); + return true; + } + suspend_gpio[suspend_gpio_cnt++] = + ((struct bl_aux_param_gpio *)param)->gpio; + return true; + case BL_AUX_PARAM_RK_SUSPEND_APIO: + suspend_apio = ((struct bl_aux_param_rk_apio *)param)->apio; + return true; + } + return false; +} + +void params_early_setup(u_register_t plat_param_from_bl2) +{ /* * Test if this is a FDT passed as a platform-specific parameter * block. @@ -154,49 +175,5 @@ void params_early_setup(void *plat_param_from_bl2) if (!dt_process_fdt(plat_param_from_bl2)) return; - /* keep plat parameters for later processing if need */ - bl2_param = (struct bl31_plat_param *)plat_param_from_bl2; - while (bl2_param) { - switch (bl2_param->type) { - case PARAM_RESET: - gpio_param = (struct bl31_gpio_param *)bl2_param; - memcpy(¶m_reset, &gpio_param->gpio, - sizeof(struct gpio_info)); - rst_gpio = ¶m_reset; - break; - case PARAM_POWEROFF: - gpio_param = (struct bl31_gpio_param *)bl2_param; - memcpy(¶m_poweroff, &gpio_param->gpio, - sizeof(struct gpio_info)); - poweroff_gpio = ¶m_poweroff; - break; - case PARAM_SUSPEND_GPIO: - if (suspend_gpio_cnt >= ARRAY_SIZE(suspend_gpio)) { - ERROR("exceed support suspend gpio number\n"); - break; - } - gpio_param = (struct bl31_gpio_param *)bl2_param; - memcpy(&suspend_gpio[suspend_gpio_cnt], - &gpio_param->gpio, - sizeof(struct gpio_info)); - suspend_gpio_cnt++; - break; - case PARAM_SUSPEND_APIO: - memcpy(¶m_apio, bl2_param, - sizeof(struct bl31_apio_param)); - suspend_apio = ¶m_apio.apio; - break; -#if COREBOOT - case PARAM_COREBOOT_TABLE: - coreboot_table_setup((void *) - ((struct bl31_u64_param *)bl2_param)->value); - break; -#endif - default: - ERROR("not expected type found %lld\n", - bl2_param->type); - break; - } - bl2_param = bl2_param->next; - } + bl_aux_params_parse(plat_param_from_bl2, rk_aux_param_handler); } diff --git a/plat/rockchip/common/sp_min_plat_setup.c b/plat/rockchip/common/sp_min_plat_setup.c index 7cdbaba1d..cb28b7a61 100644 --- a/plat/rockchip/common/sp_min_plat_setup.c +++ b/plat/rockchip/common/sp_min_plat_setup.c @@ -40,7 +40,7 @@ entry_point_info_t *sp_min_plat_get_bl33_ep_info(void) } #pragma weak params_early_setup -void params_early_setup(void *plat_param_from_bl2) +void params_early_setup(u_register_t plat_param_from_bl2) { } @@ -54,9 +54,8 @@ void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1, { static console_16550_t console; struct rockchip_bl31_params *arg_from_bl2 = (struct rockchip_bl31_params *) arg0; - void *plat_params_from_bl2 = (void *) arg1; - params_early_setup(plat_params_from_bl2); + params_early_setup(arg1); #if COREBOOT if (coreboot_serial.type) diff --git a/plat/rockchip/rk3288/platform.mk b/plat/rockchip/rk3288/platform.mk index 1811b3af8..980fb6bf0 100644 --- a/plat/rockchip/rk3288/platform.mk +++ b/plat/rockchip/rk3288/platform.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -30,7 +30,8 @@ RK_GIC_SOURCES := drivers/arm/gic/common/gic_common.c \ plat/common/plat_gicv2.c \ ${RK_PLAT}/common/rockchip_gicv2.c -PLAT_BL_COMMON_SOURCES := plat/common/aarch32/crash_console_helpers.S \ +PLAT_BL_COMMON_SOURCES := lib/bl_aux_params/bl_aux_params.c \ + plat/common/aarch32/crash_console_helpers.S \ plat/common/plat_psci_common.c PLAT_BL_COMMON_SOURCES += lib/xlat_tables/xlat_tables_common.c \ diff --git a/plat/rockchip/rk3328/platform.mk b/plat/rockchip/rk3328/platform.mk index fa207aa50..2be2be3da 100644 --- a/plat/rockchip/rk3328/platform.mk +++ b/plat/rockchip/rk3328/platform.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -28,7 +28,8 @@ RK_GIC_SOURCES := drivers/arm/gic/common/gic_common.c \ plat/common/plat_gicv2.c \ ${RK_PLAT}/common/rockchip_gicv2.c -PLAT_BL_COMMON_SOURCES := lib/xlat_tables/aarch64/xlat_tables.c \ +PLAT_BL_COMMON_SOURCES := lib/bl_aux_params/bl_aux_params.c \ + lib/xlat_tables/aarch64/xlat_tables.c \ lib/xlat_tables/xlat_tables_common.c \ plat/common/aarch64/crash_console_helpers.S \ plat/common/plat_psci_common.c diff --git a/plat/rockchip/rk3368/platform.mk b/plat/rockchip/rk3368/platform.mk index f8878f1db..8812378b1 100644 --- a/plat/rockchip/rk3368/platform.mk +++ b/plat/rockchip/rk3368/platform.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -26,7 +26,8 @@ RK_GIC_SOURCES := drivers/arm/gic/common/gic_common.c \ plat/common/plat_gicv2.c \ ${RK_PLAT}/common/rockchip_gicv2.c -PLAT_BL_COMMON_SOURCES := lib/xlat_tables/xlat_tables_common.c \ +PLAT_BL_COMMON_SOURCES := lib/bl_aux_params/bl_aux_params.c \ + lib/xlat_tables/xlat_tables_common.c \ lib/xlat_tables/aarch64/xlat_tables.c \ plat/common/aarch64/crash_console_helpers.S \ plat/common/plat_psci_common.c diff --git a/plat/rockchip/rk3399/drivers/pmu/pmu.c b/plat/rockchip/rk3399/drivers/pmu/pmu.c index 42589b9b9..a6b597360 100644 --- a/plat/rockchip/rk3399/drivers/pmu/pmu.c +++ b/plat/rockchip/rk3399/drivers/pmu/pmu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -890,7 +890,7 @@ static uint32_t gpio_2_4_clk_gate; static void suspend_apio(void) { - struct apio_info *suspend_apio; + struct bl_aux_rk_apio_info *suspend_apio; int i; suspend_apio = plat_get_rockchip_suspend_apio(); @@ -1010,7 +1010,7 @@ static void suspend_apio(void) static void resume_apio(void) { - struct apio_info *suspend_apio; + struct bl_aux_rk_apio_info *suspend_apio; int i; suspend_apio = plat_get_rockchip_suspend_apio(); @@ -1038,7 +1038,7 @@ static void resume_apio(void) static void suspend_gpio(void) { - struct gpio_info *suspend_gpio; + struct bl_aux_gpio_info *suspend_gpio; uint32_t count; int i; @@ -1053,7 +1053,7 @@ static void suspend_gpio(void) static void resume_gpio(void) { - struct gpio_info *suspend_gpio; + struct bl_aux_gpio_info *suspend_gpio; uint32_t count; int i; @@ -1491,7 +1491,7 @@ int rockchip_soc_sys_pwr_dm_resume(void) void __dead2 rockchip_soc_soft_reset(void) { - struct gpio_info *rst_gpio; + struct bl_aux_gpio_info *rst_gpio; rst_gpio = plat_get_rockchip_gpio_reset(); @@ -1508,7 +1508,7 @@ void __dead2 rockchip_soc_soft_reset(void) void __dead2 rockchip_soc_system_off(void) { - struct gpio_info *poweroff_gpio; + struct bl_aux_gpio_info *poweroff_gpio; poweroff_gpio = plat_get_rockchip_gpio_poweroff(); diff --git a/plat/rockchip/rk3399/drivers/pmu/pmu.h b/plat/rockchip/rk3399/drivers/pmu/pmu.h index e1ba41041..74db82ff2 100644 --- a/plat/rockchip/rk3399/drivers/pmu/pmu.h +++ b/plat/rockchip/rk3399/drivers/pmu/pmu.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ diff --git a/plat/rockchip/rk3399/platform.mk b/plat/rockchip/rk3399/platform.mk index 1d81d7e9f..88fa8e9c0 100644 --- a/plat/rockchip/rk3399/platform.mk +++ b/plat/rockchip/rk3399/platform.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. +# Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -32,7 +32,8 @@ RK_GIC_SOURCES := drivers/arm/gic/common/gic_common.c \ plat/common/plat_gicv3.c \ ${RK_PLAT}/common/rockchip_gicv3.c -PLAT_BL_COMMON_SOURCES := lib/xlat_tables/xlat_tables_common.c \ +PLAT_BL_COMMON_SOURCES := lib/bl_aux_params/bl_aux_params.c \ + lib/xlat_tables/xlat_tables_common.c \ lib/xlat_tables/aarch64/xlat_tables.c \ plat/common/aarch64/crash_console_helpers.S \ plat/common/plat_psci_common.c