blob: 6e04abfb71657bdb2fd5da01a4991d0426a09dd7 [file] [log] [blame]
Sridhar Parasurambe12c3d2015-01-16 13:42:26 -08001/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Channagoud Kadabied60a8b2014-06-27 15:35:09 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
Channagoud Kadabi0ffa7862015-03-19 11:58:28 -070016 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070027 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
32#include <qgic.h>
33#include <qtimer.h>
34#include <platform/clock.h>
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070035#include <arch/arm/mmu.h>
Channagoud Kadabi428a2132015-06-17 17:32:01 -070036#include <mmu.h>
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070037#include <smem.h>
38#include <board.h>
39
40#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
41#define MSM_SHARED_SIZE 2
42
Sanrio Alvares42553e12015-06-08 15:21:54 -070043/* LK memory - cacheable, write through */
44#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070045 MMU_MEMORY_AP_READ_WRITE)
46
47/* Peripherals - non-shared device */
48#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
Channagoud Kadabi428a2132015-06-17 17:32:01 -070049 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN | MMU_MEMORY_PXN)
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070050
Sanrio Alvares42553e12015-06-08 15:21:54 -070051/* SCRATCH memory - cacheable, write through */
52#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070053 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
54
Channagoud Kadabi428a2132015-06-17 17:32:01 -070055/* COMMON memory - cacheable, write through */
56#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
57 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
58
59
60static mmu_section_t default_mmu_section_table[] =
61{
62/* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */
63 { 0x00000000, 0x00000000, MMU_L1_NS_SECTION_MAPPING, 1024, IOMAP_MEMORY},
64 { KERNEL_ADDR, KERNEL_ADDR, MMU_L2_NS_SECTION_MAPPING, KERNEL_SIZE, COMMON_MEMORY},
65 { MEMBASE, MEMBASE, MMU_L2_NS_SECTION_MAPPING, (MEMSIZE / MB), LK_MEMORY},
66 { SCRATCH_ADDR, SCRATCH_ADDR, MMU_L2_NS_SECTION_MAPPING, SCRATCH_SIZE, SCRATCH_MEMORY},
67 { MSM_SHARED_BASE, MSM_SHARED_BASE, MMU_L2_NS_SECTION_MAPPING, MSM_SHARED_SIZE, COMMON_MEMORY},
68 { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, MMU_L2_NS_SECTION_MAPPING, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
69};
70
71static mmu_section_t dload_mmu_section_table[] =
72{
73 { 0x85800000, 0x85800000, MMU_L2_NS_SECTION_MAPPING, 178, COMMON_MEMORY},
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070074};
75
76void platform_early_init(void)
77{
78 board_init();
79 platform_clock_init();
80 qgic_init();
81 qtimer_init();
82 scm_init();
83}
84
85void platform_init(void)
86{
87 dprintf(INFO, "platform_init()\n");
88}
89
90void platform_uninit(void)
91{
92#if DISPLAY_SPLASH_SCREEN
93 display_shutdown();
94#endif
95
96 qtimer_uninit();
97}
98
99int platform_use_identity_mmu_mappings(void)
100{
101 /* Use only the mappings specified in this file. */
102 return 0;
103}
104
105/* Setup memory for this platform */
106void platform_init_mmu_mappings(void)
107{
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700108 int i;
109 int table_sz = ARRAY_SIZE(default_mmu_section_table);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700110
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700111 for (i = 0 ; i < table_sz; i++)
112 arm_mmu_map_entry(&default_mmu_section_table[i]);
113
114 if (scm_device_enter_dload())
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700115 {
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700116 /* TZ & Hyp memory can be mapped only while entering the download mode */
117 table_sz = ARRAY_SIZE(dload_mmu_section_table);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700118
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700119 for (i = 0 ; i < table_sz; i++)
120 arm_mmu_map_entry(&dload_mmu_section_table[i]);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700121 }
122}
123
124addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
125{
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700126 return virtual_to_physical_mapping(virt_addr);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700127}
128
129addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
130{
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700131 return physical_to_virtual_mapping(phys_addr);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700132}
133
134uint32_t platform_get_sclk_count(void)
135{
136 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
137}
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800138
139addr_t get_bs_info_addr()
140{
141 return BS_INFO_ADDR;
142}
Channagoud Kadabi652a6f62014-11-17 17:23:23 -0800143
144uint32_t platform_get_qmp_rev()
145{
146 return readl(USB3_PHY_REVISION_ID3) << 24 | readl(USB3_PHY_REVISION_ID2) << 16 |
147 readl(USB3_PHY_REVISION_ID1) << 8 | readl(USB3_PHY_REVISION_ID0);
148}
Channagoud Kadabi1fc3c682015-03-29 19:49:11 -0700149
150uint32_t platform_get_max_periph()
151{
152 return 256;
153}
Channagoud Kadabi53a21262015-04-09 16:18:23 -0700154
155int platform_is_msm8996()
156{
157 if (board_platform_id() == MSM8996)
158 return 1;
159 else
160 return 0;
161}