developer | 2189d3a | 2020-04-17 17:14:23 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, MediaTek Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | /* System Includes */ |
| 8 | #include <assert.h> |
| 9 | |
| 10 | /* Project Includes */ |
| 11 | #include <common/bl_common.h> |
| 12 | #include <common/debug.h> |
| 13 | #include <common/desc_image_load.h> |
developer | f13d649 | 2020-08-05 13:53:59 +0800 | [diff] [blame] | 14 | #include <drivers/generic_delay_timer.h> |
developer | 2189d3a | 2020-04-17 17:14:23 +0800 | [diff] [blame] | 15 | #include <drivers/ti/uart/uart_16550.h> |
| 16 | #include <lib/coreboot.h> |
| 17 | |
| 18 | /* Platform Includes */ |
developer | 47aad1c | 2021-02-09 11:28:00 +0800 | [diff] [blame] | 19 | #include <devapc/devapc.h> |
developer | bd48115 | 2020-11-02 10:45:34 +0800 | [diff] [blame] | 20 | #include <emi_mpu/emi_mpu.h> |
developer | 404e08b | 2020-09-18 09:32:31 +0800 | [diff] [blame] | 21 | #include <gpio/mtgpio.h> |
developer | f9b5684 | 2020-06-09 13:38:35 +0800 | [diff] [blame] | 22 | #include <mt_gic_v3.h> |
developer | 5f73516 | 2021-01-04 00:02:34 +0800 | [diff] [blame] | 23 | #include <mt_spm.h> |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 24 | #include <mt_timer.h> |
developer | a630463 | 2020-09-08 14:36:07 +0800 | [diff] [blame] | 25 | #include <mtk_dcm.h> |
developer | 2189d3a | 2020-04-17 17:14:23 +0800 | [diff] [blame] | 26 | #include <plat_params.h> |
| 27 | #include <plat_private.h> |
| 28 | |
| 29 | static entry_point_info_t bl32_ep_info; |
| 30 | static entry_point_info_t bl33_ep_info; |
| 31 | |
| 32 | /******************************************************************************* |
| 33 | * Return a pointer to the 'entry_point_info' structure of the next image for |
| 34 | * the security state specified. BL33 corresponds to the non-secure image type |
| 35 | * while BL32 corresponds to the secure image type. A NULL pointer is returned |
| 36 | * if the image does not exist. |
| 37 | ******************************************************************************/ |
| 38 | entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) |
| 39 | { |
| 40 | entry_point_info_t *next_image_info; |
| 41 | |
| 42 | next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info; |
| 43 | assert(next_image_info->h.type == PARAM_EP); |
| 44 | |
| 45 | /* None of the images on this platform can have 0x0 as the entrypoint */ |
| 46 | if (next_image_info->pc) { |
| 47 | return next_image_info; |
| 48 | } else { |
| 49 | return NULL; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /******************************************************************************* |
| 54 | * Perform any BL31 early platform setup. Here is an opportunity to copy |
| 55 | * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they |
| 56 | * are lost (potentially). This needs to be done before the MMU is initialized |
| 57 | * so that the memory layout can be used while creating page tables. |
| 58 | * BL2 has flushed this information to memory, so we are guaranteed to pick up |
| 59 | * good data. |
| 60 | ******************************************************************************/ |
| 61 | void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 62 | u_register_t arg2, u_register_t arg3) |
| 63 | { |
| 64 | static console_t console; |
| 65 | |
| 66 | params_early_setup(arg1); |
| 67 | |
| 68 | #if COREBOOT |
| 69 | if (coreboot_serial.type) { |
| 70 | console_16550_register(coreboot_serial.baseaddr, |
| 71 | coreboot_serial.input_hertz, |
| 72 | coreboot_serial.baud, |
| 73 | &console); |
| 74 | } |
| 75 | #else |
| 76 | console_16550_register(UART0_BASE, UART_CLOCK, UART_BAUDRATE, &console); |
| 77 | #endif |
| 78 | |
| 79 | NOTICE("MT8192 bl31_setup\n"); |
| 80 | |
| 81 | bl31_params_parse_helper(arg0, &bl32_ep_info, &bl33_ep_info); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /******************************************************************************* |
| 86 | * Perform any BL31 platform setup code |
| 87 | ******************************************************************************/ |
| 88 | void bl31_platform_setup(void) |
| 89 | { |
developer | a630463 | 2020-09-08 14:36:07 +0800 | [diff] [blame] | 90 | /* Set dcm on */ |
| 91 | if (!dcm_set_default()) { |
| 92 | ERROR("Failed to set default dcm on!!\n"); |
| 93 | } |
| 94 | |
developer | bd48115 | 2020-11-02 10:45:34 +0800 | [diff] [blame] | 95 | /* MPU Init */ |
| 96 | emi_mpu_init(); |
| 97 | |
developer | 47aad1c | 2021-02-09 11:28:00 +0800 | [diff] [blame] | 98 | /* DAPC Init */ |
| 99 | devapc_init(); |
| 100 | |
developer | f9b5684 | 2020-06-09 13:38:35 +0800 | [diff] [blame] | 101 | /* Initialize the GIC driver, CPU and distributor interfaces */ |
| 102 | mt_gic_driver_init(); |
| 103 | mt_gic_init(); |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 104 | |
developer | 912c7d2 | 2021-03-31 14:53:43 +0800 | [diff] [blame] | 105 | mt_gpio_init(); |
developer | 57d8b88 | 2020-07-06 18:01:42 +0800 | [diff] [blame] | 106 | mt_systimer_init(); |
developer | f13d649 | 2020-08-05 13:53:59 +0800 | [diff] [blame] | 107 | generic_delay_timer_init(); |
developer | 5f73516 | 2021-01-04 00:02:34 +0800 | [diff] [blame] | 108 | spm_boot_init(); |
developer | 2189d3a | 2020-04-17 17:14:23 +0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /******************************************************************************* |
| 112 | * Perform the very early platform specific architectural setup here. At the |
| 113 | * moment this is only intializes the mmu in a quick and dirty way. |
| 114 | ******************************************************************************/ |
| 115 | void bl31_plat_arch_setup(void) |
| 116 | { |
| 117 | plat_configure_mmu_el3(BL31_START, |
| 118 | BL31_END - BL31_START, |
| 119 | BL_CODE_BASE, |
| 120 | BL_CODE_END); |
| 121 | } |