blob: 26228f69e4afbfa1abfd8891f3048523c2074a1c [file] [log] [blame]
Oliver Swede8fed2fe2019-11-11 11:11:06 +00001/*
2 * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Oliver Swedef94e2ee2019-11-11 11:32:32 +00007#include <assert.h>
Oliver Swede20e01372019-12-02 13:33:40 +00008#include <lib/mmio.h>
9#include <drivers/generic_delay_timer.h>
Oliver Swedef94e2ee2019-11-11 11:32:32 +000010
Oliver Swede8fed2fe2019-11-11 11:11:06 +000011#include <plat/common/platform.h>
12#include <platform_def.h>
13
14#include "fpga_private.h"
15
Oliver Swedef94e2ee2019-11-11 11:32:32 +000016static entry_point_info_t bl33_image_ep_info;
17
18uintptr_t plat_get_ns_image_entrypoint(void)
19{
20#ifdef PRELOADED_BL33_BASE
21 return PRELOADED_BL33_BASE;
22#else
23 return 0;
24#endif
25}
26
27uint32_t fpga_get_spsr_for_bl33_entry(void)
28{
29 return SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
30}
31
Oliver Swede8fed2fe2019-11-11 11:11:06 +000032void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
33 u_register_t arg2, u_register_t arg3)
34{
35 fpga_console_init();
Oliver Swedef94e2ee2019-11-11 11:32:32 +000036
37 bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
38 bl33_image_ep_info.spsr = fpga_get_spsr_for_bl33_entry();
39 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
40
41 /* Set x0-x3 for the primary CPU as expected by the kernel */
42 bl33_image_ep_info.args.arg0 = (u_register_t)FPGA_PRELOADED_DTB_BASE;
43 bl33_image_ep_info.args.arg1 = 0U;
44 bl33_image_ep_info.args.arg2 = 0U;
45 bl33_image_ep_info.args.arg3 = 0U;
Oliver Swede8fed2fe2019-11-11 11:11:06 +000046}
47
48void bl31_plat_arch_setup(void)
49{
50}
51
52void bl31_platform_setup(void)
53{
Oliver Swede20e01372019-12-02 13:33:40 +000054 /* Write frequency to CNTCRL and initialize timer */
55 generic_delay_timer_init();
56 mmio_write_32(FPGA_TIMER_BASE, ((1 << 8) | 1UL));
57
58 /* TODO: initialize GIC using the specifications of the FPGA image */
Oliver Swede8fed2fe2019-11-11 11:11:06 +000059}
60
61entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
62{
Oliver Swedef94e2ee2019-11-11 11:32:32 +000063 entry_point_info_t *next_image_info;
64 next_image_info = &bl33_image_ep_info;
65
66 /* Only expecting BL33: the kernel will run in EL2NS */
67 assert(type == NON_SECURE);
68
69 /* None of the images can have 0x0 as the entrypoint */
70 if (next_image_info->pc) {
71 return next_image_info;
72 } else {
73 return NULL;
74 }
Oliver Swede8fed2fe2019-11-11 11:11:06 +000075}
76
77unsigned int plat_get_syscnt_freq2(void)
78{
Oliver Swede20e01372019-12-02 13:33:40 +000079 return FPGA_TIMER_FREQUENCY;
Oliver Swede8fed2fe2019-11-11 11:11:06 +000080}
81
82void bl31_plat_enable_mmu(uint32_t flags)
83{
84 /* TODO: determine if MMU needs to be enabled */
85}