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