stm32mp1_common.c 2.32 KB
Newer Older
1
/*
Yann Gautier's avatar
Yann Gautier committed
2
 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
8

9
#include <platform_def.h>
10
11
12
13
14

#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include <drivers/arm/gicv2.h>
15
#include <dt-bindings/clock/stm32mp1-clks.h>
16
17
18
19
#include <lib/mmio.h>
#include <lib/xlat_tables/xlat_tables_v2.h>
#include <plat/common/platform.h>

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stm32mp1_private.h>

#define MAP_SRAM	MAP_REGION_FLAT(STM32MP1_SRAM_BASE, \
					STM32MP1_SRAM_SIZE, \
					MT_MEMORY | \
					MT_RW | \
					MT_SECURE | \
					MT_EXECUTE_NEVER)

#define MAP_DEVICE1	MAP_REGION_FLAT(STM32MP1_DEVICE1_BASE, \
					STM32MP1_DEVICE1_SIZE, \
					MT_DEVICE | \
					MT_RW | \
					MT_SECURE | \
					MT_EXECUTE_NEVER)

#define MAP_DEVICE2	MAP_REGION_FLAT(STM32MP1_DEVICE2_BASE, \
					STM32MP1_DEVICE2_SIZE, \
					MT_DEVICE | \
					MT_RW | \
					MT_SECURE | \
					MT_EXECUTE_NEVER)

43
#if defined(IMAGE_BL2)
44
45
46
47
48
49
static const mmap_region_t stm32mp1_mmap[] = {
	MAP_SRAM,
	MAP_DEVICE1,
	MAP_DEVICE2,
	{0}
};
50
51
52
53
54
55
56
57
58
#endif
#if defined(IMAGE_BL32)
static const mmap_region_t stm32mp1_mmap[] = {
	MAP_SRAM,
	MAP_DEVICE1,
	MAP_DEVICE2,
	{0}
};
#endif
59
60
61
62
63
64

void configure_mmu(void)
{
	mmap_add(stm32mp1_mmap);
	init_xlat_tables();

65
	enable_mmu_svc_mon(0);
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
}

uintptr_t plat_get_ns_image_entrypoint(void)
{
	return BL33_BASE;
}

unsigned int plat_get_syscnt_freq2(void)
{
	return read_cntfrq_el0();
}

/* Functions to save and get boot context address given by ROM code */
static uintptr_t boot_ctx_address;

void stm32mp1_save_boot_ctx_address(uintptr_t address)
{
	boot_ctx_address = address;
}

uintptr_t stm32mp1_get_boot_ctx_address(void)
{
	return boot_ctx_address;
}
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

uintptr_t stm32_get_gpio_bank_base(unsigned int bank)
{
	switch (bank) {
	case GPIO_BANK_A ... GPIO_BANK_K:
		return GPIOA_BASE + (bank * GPIO_BANK_OFFSET);
	case GPIO_BANK_Z:
		return GPIOZ_BASE;
	default:
		panic();
	}
}

/* Return clock ID on success, negative value on error */
unsigned long stm32_get_gpio_bank_clock(unsigned int bank)
{
	switch (bank) {
	case GPIO_BANK_A ... GPIO_BANK_K:
		return GPIOA + (bank - GPIO_BANK_A);
	case GPIO_BANK_Z:
		return GPIOZ;
	default:
		panic();
	}
}

uint32_t stm32_get_gpio_bank_offset(unsigned int bank)
{
	if (bank == GPIO_BANK_Z) {
		return 0;
	} else {
		return bank * GPIO_BANK_OFFSET;
	}
}