blob: 1b60c18b0089cdb922207e41f1be25563fed81b1 [file] [log] [blame]
Aparna Mallavarapu9e014372013-10-19 15:04:58 +05301/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
2 *
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 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053032#include <platform/irqs.h>
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053033#include <qgic.h>
34#include <qtimer.h>
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080035#include <mmu.h>
36#include <arch/arm/mmu.h>
37#include <smem.h>
38#include <board.h>
39#include <boot_stats.h>
40
41#define MB (1024*1024)
42
43#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053044#define A53_SS_SIZE ((A53_SS_END - A53_SS_BASE)/MB)
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080045
46/* LK memory - cacheable, write through */
47#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
48 MMU_MEMORY_AP_READ_WRITE)
49
50/* Peripherals - non-shared device */
51#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
52 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
53
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053054/* IMEM memory - cacheable, write through */
55#define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
56 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
57
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080058static mmu_section_t mmu_section_table[] = {
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +053059/* Physical addr, Virtual addr, Size (in MB), Flags */
60 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
61 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
62 { A53_SS_BASE, A53_SS_BASE, A53_SS_SIZE, IOMAP_MEMORY},
63 { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY},
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080064};
65
66static struct smem_ram_ptable ram_ptable;
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053067
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053068static int platform_is_msm8939();
69
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053070void platform_early_init(void)
71{
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080072 board_init();
73 platform_clock_init();
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053074 qgic_init();
75 qtimer_init();
76}
77
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +053078int qtmr_irq()
79{
80 if (platform_is_msm8939())
81 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x39;
82 else
83 return INT_QTMR_FRM_0_PHYSICAL_TIMER_EXP_8x16;
84}
85
Aparna Mallavarapu9e014372013-10-19 15:04:58 +053086void platform_init(void)
87{
88 dprintf(INFO, "platform_init()\n");
89}
90
91void platform_uninit(void)
92{
93 qtimer_uninit();
94}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -080095
96uint32_t platform_get_sclk_count(void)
97{
98 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
99}
100
101addr_t get_bs_info_addr()
102{
103 return ((addr_t)BS_INFO_ADDR);
104}
105
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530106int platform_use_identity_mmu_mappings(void)
107{
108 /* Use only the mappings specified in this file. */
109 return 0;
110}
Aparna Mallavarapu70e5df52014-02-27 22:51:29 -0800111/* Setup memory for this platform */
112void platform_init_mmu_mappings(void)
113{
114 uint32_t i;
115 uint32_t sections;
116 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
117 ram_partition ptn_entry;
118 uint32_t len = 0;
119
120 ASSERT(smem_ram_ptable_init_v1());
121
122 len = smem_get_ram_ptable_len();
123
124 /* Configure the MMU page entries for SDRAM and IMEM memory read
125 from the smem ram table*/
126 for(i = 0; i < len; i++)
127 {
128 smem_get_ram_ptable_entry(&ptn_entry, i);
129 if(ptn_entry.type == SYS_MEMORY)
130 {
131 if((ptn_entry.category == SDRAM) ||
132 (ptn_entry.category == IMEM))
133 {
134 /* Check to ensure that start address is 1MB aligned */
135 ASSERT((ptn_entry.start & (MB-1)) == 0);
136
137 sections = (ptn_entry.size) / MB;
138 while(sections--)
139 {
140 arm_mmu_map_section(ptn_entry.start +
141 sections * MB,
142 ptn_entry.start +
143 sections * MB,
144 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
145 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
146 }
147 }
148 }
149 }
150
151 /* Configure the MMU page entries for memory read from the
152 mmu_section_table */
153 for (i = 0; i < table_size; i++)
154 {
155 sections = mmu_section_table[i].num_of_sections;
156
157 while (sections--)
158 {
159 arm_mmu_map_section(mmu_section_table[i].paddress +
160 sections * MB,
161 mmu_section_table[i].vaddress +
162 sections * MB,
163 mmu_section_table[i].flags);
164 }
165 }
166}
Aparna Mallavarapu6b9ee0c2014-04-17 13:58:43 +0530167
168addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
169{
170 /* Using 1-1 mapping on this platform. */
171 return virt_addr;
172}
173
174addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
175{
176 /* Using 1-1 mapping on this platform. */
177 return phys_addr;
178}
Unnati Gandhi5d1f5c22014-04-25 19:24:00 +0530179
180static int platform_is_msm8939()
181{
182 uint32_t platform = board_platform_id();
183 uint32_t ret = 0;
184
185 switch(platform)
186 {
187 case MSM8939:
188 case APQ8036:
189 case APQ8039:
190 case MSM8236:
191 case MSM8636:
192 ret = 1;
193 break;
194 default:
195 ret = 0;
196 };
197
198 return ret;
199}