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