bl2_plat_setup.c 4.3 KB
Newer Older
1
2
/*
 * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
3
 * Copyright (c) 2019, Intel Corporation. All rights reserved.
4
5
6
7
8
9
10
11
12
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch.h>
#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include <common/desc_image_load.h>
13
#include <drivers/generic_delay_timer.h>
14
#include <drivers/synopsys/dw_mmc.h>
15
#include <drivers/ti/uart/uart_16550.h>
16
17
#include <lib/xlat_tables/xlat_tables.h>

18
#include "qspi/cadence_qspi.h"
19
#include "socfpga_handoff.h"
20
#include "socfpga_mailbox.h"
21
#include "socfpga_private.h"
22
23
24
25
26
#include "s10_clock_manager.h"
#include "s10_memory_controller.h"
#include "s10_pinmux.h"
#include "s10_reset_manager.h"
#include "s10_system_manager.h"
27
#include "wdt/watchdog.h"
28

29
30

const mmap_region_t plat_stratix10_mmap[] = {
31
32
33
34
35
36
	MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
		MT_MEMORY | MT_RW | MT_NS),
	MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE,
		MT_DEVICE | MT_RW | MT_NS),
	MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE,
		MT_DEVICE | MT_RW | MT_SECURE),
37
38
39
40
	MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
		MT_NON_CACHEABLE | MT_RW | MT_SECURE),
	MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
		MT_DEVICE | MT_RW | MT_SECURE),
41
42
43
44
	MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
		MT_DEVICE | MT_RW | MT_NS),
	MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE,
		MT_DEVICE | MT_RW | MT_NS),
45
46
47
48
49
50
51
52
53
54
55
56
57
	{0},
};

boot_source_type boot_source;

void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
				u_register_t x2, u_register_t x4)
{
	static console_16550_t console;
	handoff reverse_handoff_ptr;

	generic_delay_timer_init();

58
	if (socfpga_get_handoff(&reverse_handoff_ptr))
59
60
61
62
63
64
65
66
67
		return;
	config_pinmux(&reverse_handoff_ptr);
	boot_source = reverse_handoff_ptr.boot_source;

	config_clkmgr_handoff(&reverse_handoff_ptr);
	enable_nonsecure_access();
	deassert_peripheral_reset();
	config_hps_hs_before_warm_reset();

68
	watchdog_init(get_wdt_clk());
69

70
	console_16550_register(PLAT_UART0_BASE, get_uart_clk(), PLAT_BAUDRATE,
71
72
		&console);

73
	socfpga_delay_timer_init();
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
	init_hard_memory_controller();
}


void bl2_el3_plat_arch_setup(void)
{

	struct mmc_device_info info;
	const mmap_region_t bl_regions[] = {
		MAP_REGION_FLAT(BL2_BASE, BL2_END - BL2_BASE,
			MT_MEMORY | MT_RW | MT_SECURE),
		MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
			MT_CODE | MT_SECURE),
		MAP_REGION_FLAT(BL_RO_DATA_BASE,
			BL_RO_DATA_END - BL_RO_DATA_BASE,
			MT_RO_DATA | MT_SECURE),
#if USE_COHERENT_MEM_BAR
		MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
			BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
			MT_DEVICE | MT_RW | MT_SECURE),
#endif
		{0},
	};

	setup_page_tables(bl_regions, plat_stratix10_mmap);

	enable_mmu_el3(0);

102
	dw_mmc_params_t params = EMMC_INIT_PARAMS(0x100000, get_mmc_clk());
103
104

	info.mmc_dev_type = MMC_IS_SD;
105
	info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
106
107
108
109

	switch (boot_source) {
	case BOOT_SOURCE_SDMMC:
		dw_mmc_init(&params, &info);
110
		socfpga_io_setup(boot_source);
111
112
113
114
115
116
117
118
		break;

	case BOOT_SOURCE_QSPI:
		mailbox_set_qspi_open();
		mailbox_set_qspi_direct();
		cad_qspi_init(0, QSPI_CONFIG_CPHA, QSPI_CONFIG_CPOL,
			QSPI_CONFIG_CSDA, QSPI_CONFIG_CSDADS,
			QSPI_CONFIG_CSEOT, QSPI_CONFIG_CSSOT, 0);
119
		socfpga_io_setup(boot_source);
120
		break;
121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
	default:
		ERROR("Unsupported boot source\n");
		panic();
		break;
	}
}

uint32_t get_spsr_for_bl33_entry(void)
{
	unsigned long el_status;
	unsigned int mode;
	uint32_t spsr;

	/* Figure out what mode we enter the non-secure world in */
	el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
	el_status &= ID_AA64PFR0_ELX_MASK;

	mode = (el_status) ? MODE_EL2 : MODE_EL1;

	/*
	 * TODO: Consider the possibility of specifying the SPSR in
	 * the FIP ToC and allowing the platform to have a say as
	 * well.
	 */
	spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
	return spsr;
}


int bl2_plat_handle_post_image_load(unsigned int image_id)
{
	bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);

	switch (image_id) {
	case BL33_IMAGE_ID:
		bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
		bl_mem_params->ep_info.spsr = get_spsr_for_bl33_entry();
		break;
	default:
		break;
	}

	return 0;
}

/*******************************************************************************
 * Perform any BL3-1 platform setup code
 ******************************************************************************/
void bl2_platform_setup(void)
{
}