blob: cb8876ec8fc61728116e423940770ec266186046 [file] [log] [blame]
Amol Jadid3d7cdc2013-01-16 17:02:01 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -08002 *
3 * Redistribution and use in source and binary forms, with or without
Deepa Dinamani17338312012-10-18 11:29:54 -07004 * 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.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080015 *
Deepa Dinamani17338312012-10-18 11:29:54 -070016 * 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.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080027 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
32#include <qgic.h>
Deepa Dinamani81eddd52012-05-31 11:18:50 -070033#include <qtimer.h>
Amol Jadi29f95032012-06-22 12:52:54 -070034#include <platform/clock.h>
Neeti Desai13e688d2012-08-22 16:30:55 -070035#include <mmu.h>
36#include <arch/arm/mmu.h>
37#include <smem.h>
Amol Jadibaee4742013-03-18 15:35:05 -070038#include <board.h>
39#include <boot_stats.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080040
Neeti Desai13e688d2012-08-22 16:30:55 -070041#define MB (1024*1024)
42
43#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
44
45/* LK memory - cacheable, write through */
46#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
47 MMU_MEMORY_AP_READ_WRITE)
48
49/* Peripherals - non-shared device */
50#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
51 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
52
Deepa Dinamani17338312012-10-18 11:29:54 -070053static mmu_section_t mmu_section_table[] = {
Neeti Desai13e688d2012-08-22 16:30:55 -070054/* Physical addr, Virtual addr, Size (in MB), Flags */
55 {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
56 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
57};
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080058
Deepa Dinamani17338312012-10-18 11:29:54 -070059static struct smem_ram_ptable ram_ptable;
60
Amol Jadibaee4742013-03-18 15:35:05 -070061/* Boot timestamps */
62#define BS_INFO_OFFSET (0x6B0)
63#define BS_INFO_ADDR_V1 (RPM_MSG_RAM_BASE + BS_INFO_OFFSET)
64#define BS_INFO_ADDR_V2 (MSM_SHARED_IMEM_BASE + BS_INFO_OFFSET)
65
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080066void platform_early_init(void)
67{
Neeti Desai465491e2012-07-31 12:53:35 -070068 board_init();
Amol Jadi29f95032012-06-22 12:52:54 -070069 platform_clock_init();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080070 qgic_init();
Deepa Dinamani81eddd52012-05-31 11:18:50 -070071 qtimer_init();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080072}
73
74void platform_init(void)
75{
76 dprintf(INFO, "platform_init()\n");
77}
78
Amol Jadibaee4742013-03-18 15:35:05 -070079static uint32_t platform_get_sclk_count(void)
Joel King46d2a452013-02-13 18:35:21 -080080{
Amol Jadibaee4742013-03-18 15:35:05 -070081 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
82}
Joel King46d2a452013-02-13 18:35:21 -080083
Amol Jadibaee4742013-03-18 15:35:05 -070084static uint32_t kernel_load_start;
85void bs_set_timestamp(enum bs_entry bs_id)
86{
87 void *bs_imem;
88 uint32_t soc_ver = board_soc_version();
Joel King46d2a452013-02-13 18:35:21 -080089
Amol Jadibaee4742013-03-18 15:35:05 -070090 if (bs_id >= BS_MAX) {
91 dprintf(CRITICAL, "bad bs id: %u, max: %u\n", bs_id, BS_MAX);
92 ASSERT(0);
93 }
94
95 if (bs_id == BS_KERNEL_LOAD_START) {
96 kernel_load_start = platform_get_sclk_count();
97 return;
98 }
99
100 if (soc_ver < BOARD_SOC_VERSION2)
101 bs_imem = (void *)BS_INFO_ADDR_V1;
102 else
103 bs_imem = (void *)BS_INFO_ADDR_V2;
104
105 if(bs_id == BS_KERNEL_LOAD_DONE)
106 writel(platform_get_sclk_count() - kernel_load_start,
107 bs_imem + (sizeof(uint32_t) * BS_KERNEL_LOAD_TIME));
108 else
109 writel(platform_get_sclk_count(),
110 bs_imem + (sizeof(uint32_t) * bs_id));
Joel King46d2a452013-02-13 18:35:21 -0800111}
112
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800113void platform_uninit(void)
114{
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800115#if DISPLAY_SPLASH_SCREEN
116 display_shutdown();
117#endif
118
Deepa Dinamani81eddd52012-05-31 11:18:50 -0700119 qtimer_uninit();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800120}
Neeti Desai13e688d2012-08-22 16:30:55 -0700121
122/* Setup memory for this platform */
123void platform_init_mmu_mappings(void)
124{
Neeti Desai13e688d2012-08-22 16:30:55 -0700125 uint32_t i;
126 uint32_t sections;
127 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
128
129 ASSERT(smem_ram_ptable_init(&ram_ptable));
130
131 /* Configure the MMU page entries for SDRAM and IMEM memory read
132 from the smem ram table*/
133 for(i = 0; i < ram_ptable.len; i++)
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800134 {
135 if(ram_ptable.parts[i].type == SYS_MEMORY)
Neeti Desai13e688d2012-08-22 16:30:55 -0700136 {
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800137 if((ram_ptable.parts[i].category == SDRAM) ||
138 (ram_ptable.parts[i].category == IMEM))
139 {
140 /* Check to ensure that start address is 1MB aligned */
141 ASSERT((ram_ptable.parts[i].start & 0xFFFFF) == 0);
Neeti Desai13e688d2012-08-22 16:30:55 -0700142
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800143 sections = (ram_ptable.parts[i].size) / MB;
144 while(sections--) {
145 arm_mmu_map_section(ram_ptable.parts[i].start +
146 sections * MB,
147 ram_ptable.parts[i].start +
148 sections * MB,
149 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
150 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
151 }
Neeti Desai13e688d2012-08-22 16:30:55 -0700152 }
153 }
154 }
155 /* Configure the MMU page entries for memory read from the
156 mmu_section_table */
157 for (i = 0; i < table_size; i++) {
158 sections = mmu_section_table[i].num_of_sections;
159
160 while (sections--) {
161 arm_mmu_map_section(mmu_section_table[i].paddress +
162 sections * MB,
163 mmu_section_table[i].vaddress +
164 sections * MB,
165 mmu_section_table[i].flags);
166 }
167 }
168}