blob: 8ef3df2ba72a0f1ca954d3530296b7337eb2ffcb [file] [log] [blame]
Shalini Krishnamoorthi3d4bb2a2016-06-24 15:17:29 -07001/* Copyright (c) 2014-2016, 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>
Channagoud Kadabid2f06a22015-06-23 18:25:42 -070039#include <target/display.h>
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070040
41#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
42#define MSM_SHARED_SIZE 2
43
Channagoud Kadabi9ee188c2015-07-07 15:06:28 -070044/* LK memory - cacheable, write back */
45#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070046 MMU_MEMORY_AP_READ_WRITE)
47
48/* Peripherals - non-shared device */
49#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
Channagoud Kadabi428a2132015-06-17 17:32:01 -070050 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN | MMU_MEMORY_PXN)
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070051
Channagoud Kadabi9ee188c2015-07-07 15:06:28 -070052/* SCRATCH memory - cacheable, write back */
53#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070054 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
55
Channagoud Kadabi428a2132015-06-17 17:32:01 -070056/* COMMON memory - cacheable, write through */
57#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
58 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
59
Channagoud Kadabi7dccf842015-08-11 16:21:40 -070060/* downlaod mode memory - cacheable, write through */
61#define DLOAD_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
62 MMU_MEMORY_AP_READ_ONLY | MMU_MEMORY_XN)
63
Channagoud Kadabi2324bd52015-07-13 15:02:20 -070064static uint64_t ddr_start;
Channagoud Kadabi428a2132015-06-17 17:32:01 -070065
66static mmu_section_t default_mmu_section_table[] =
67{
Channagoud Kadabi2324bd52015-07-13 15:02:20 -070068/* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */
Channagoud Kadabid2f06a22015-06-23 18:25:42 -070069 { 0x00000000, 0x00000000, MMU_L2_NS_SECTION_MAPPING, 512, IOMAP_MEMORY},
Channagoud Kadabi428a2132015-06-17 17:32:01 -070070 { MEMBASE, MEMBASE, MMU_L2_NS_SECTION_MAPPING, (MEMSIZE / MB), LK_MEMORY},
Channagoud Kadabic0dbac92016-01-11 16:49:01 -080071 { MIPI_FB_ADDR, MIPI_FB_ADDR, MMU_L2_NS_SECTION_MAPPING, 40, LK_MEMORY},
Channagoud Kadabi428a2132015-06-17 17:32:01 -070072 { SCRATCH_ADDR, SCRATCH_ADDR, MMU_L2_NS_SECTION_MAPPING, SCRATCH_SIZE, SCRATCH_MEMORY},
73 { MSM_SHARED_BASE, MSM_SHARED_BASE, MMU_L2_NS_SECTION_MAPPING, MSM_SHARED_SIZE, COMMON_MEMORY},
74 { RPMB_SND_RCV_BUF, RPMB_SND_RCV_BUF, MMU_L2_NS_SECTION_MAPPING, RPMB_SND_RCV_BUF_SZ, IOMAP_MEMORY},
75};
76
Channagoud Kadabi7dccf842015-08-11 16:21:40 -070077/* Map the ddr for download mode, this region belongs to non-hlos images and pil */
Channagoud Kadabi428a2132015-06-17 17:32:01 -070078static mmu_section_t dload_mmu_section_table[] =
79{
Channagoud Kadabi7dccf842015-08-11 16:21:40 -070080/* Physical addr, Virtual addr, Mapping type , Size (in MB), Flags */
Channagoud Kadabi40039922015-09-29 15:23:03 -070081 { 0x85800000, 0x85800000, MMU_L2_NS_SECTION_MAPPING, 189, DLOAD_MEMORY},
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070082};
83
84void platform_early_init(void)
85{
86 board_init();
87 platform_clock_init();
88 qgic_init();
89 qtimer_init();
90 scm_init();
91}
92
93void platform_init(void)
94{
95 dprintf(INFO, "platform_init()\n");
96}
97
98void platform_uninit(void)
99{
100#if DISPLAY_SPLASH_SCREEN
101 display_shutdown();
102#endif
103
104 qtimer_uninit();
105}
106
107int platform_use_identity_mmu_mappings(void)
108{
109 /* Use only the mappings specified in this file. */
110 return 0;
111}
112
113/* Setup memory for this platform */
114void platform_init_mmu_mappings(void)
115{
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700116 int i;
117 int table_sz = ARRAY_SIZE(default_mmu_section_table);
Channagoud Kadabic0dbac92016-01-11 16:49:01 -0800118 mmu_section_t kernel_mmu_section_table;
119 uint64_t ddr_size = smem_get_ddr_size();
120
121 switch(ddr_size)
122 {
123 case MEM_4GB:
124 case MEM_3GB:
125 ddr_start = 0x80000000;
126 break;
127 case MEM_6GB:
128 ddr_start = 0x40000000;
129 break;
130 default:
131 dprintf(CRITICAL, "Unsupported ddr\n");
132 ASSERT(0);
133 };
134
135 kernel_mmu_section_table.paddress = ddr_start;
136 kernel_mmu_section_table.vaddress = ddr_start;
137 kernel_mmu_section_table.type = MMU_L2_NS_SECTION_MAPPING;
138 kernel_mmu_section_table.size = 88;
139 kernel_mmu_section_table.flags = SCRATCH_MEMORY;
140
141 arm_mmu_map_entry(&kernel_mmu_section_table);
Channagoud Kadabi2324bd52015-07-13 15:02:20 -0700142
143 /* Map default memory needed for lk , scratch, rpmb & iomap */
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700144 for (i = 0 ; i < table_sz; i++)
145 arm_mmu_map_entry(&default_mmu_section_table[i]);
146
147 if (scm_device_enter_dload())
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700148 {
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700149 /* TZ & Hyp memory can be mapped only while entering the download mode */
150 table_sz = ARRAY_SIZE(dload_mmu_section_table);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700151
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700152 for (i = 0 ; i < table_sz; i++)
153 arm_mmu_map_entry(&dload_mmu_section_table[i]);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700154 }
155}
156
157addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
158{
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700159 return virtual_to_physical_mapping(virt_addr);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700160}
161
162addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
163{
Channagoud Kadabi428a2132015-06-17 17:32:01 -0700164 return physical_to_virtual_mapping(phys_addr);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700165}
166
167uint32_t platform_get_sclk_count(void)
168{
169 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
170}
Channagoud Kadabi99d23702015-02-02 20:52:17 -0800171
172addr_t get_bs_info_addr()
173{
174 return BS_INFO_ADDR;
175}
Channagoud Kadabi652a6f62014-11-17 17:23:23 -0800176
177uint32_t platform_get_qmp_rev()
178{
179 return readl(USB3_PHY_REVISION_ID3) << 24 | readl(USB3_PHY_REVISION_ID2) << 16 |
180 readl(USB3_PHY_REVISION_ID1) << 8 | readl(USB3_PHY_REVISION_ID0);
181}
Channagoud Kadabi1fc3c682015-03-29 19:49:11 -0700182
183uint32_t platform_get_max_periph()
184{
185 return 256;
186}
Channagoud Kadabi53a21262015-04-09 16:18:23 -0700187
188int platform_is_msm8996()
189{
190 if (board_platform_id() == MSM8996)
191 return 1;
192 else
193 return 0;
194}
Channagoud Kadabi2324bd52015-07-13 15:02:20 -0700195
Parth Dixitf4bc1582016-09-16 22:14:33 +0530196int platform_is_msm8996sg()
197{
198 if (board_platform_id() == MSM8996SG)
199 return 1;
200 else
201 return 0;
202}
203
Shalini Krishnamoorthi3d4bb2a2016-06-24 15:17:29 -0700204int platform_is_apq8096_mediabox()
205{
206 return ((board_platform_id() == APQ8096) &&
207 (board_hardware_id() == HW_PLATFORM_DRAGON) &&
208 (board_hardware_subtype() == HW_PLATFORM_SUBTYPE_SVLTE1));
209}
210
Channagoud Kadabi2324bd52015-07-13 15:02:20 -0700211uint64_t platform_get_ddr_start()
212{
213 return ddr_start;
214}
Channagoud Kadabie35356f2015-08-05 18:06:38 -0700215
216bool platform_use_qmp_misc_settings()
217{
Parth Dixitf4bc1582016-09-16 22:14:33 +0530218 if ((board_soc_version() < 0x30000) && (board_platform_id() != MSM8996SG))
Channagoud Kadabie35356f2015-08-05 18:06:38 -0700219 return true;
220
221 return false;
222}
Tanya Finkel0df43632016-05-31 13:02:35 +0300223
224
225/* USB platform specific bases*/
226uint32_t usb_ctrl_base()
227{
228 if (board_hardware_id() == HW_PLATFORM_SBC)
229 return MSM_USB20_SEC_BASE;
230 else
231 return MSM_USB30_PRIM_BASE;
232
233}
234
235uint32_t usb_qscratch_base()
236{
237 if (board_hardware_id() == HW_PLATFORM_SBC)
238 return MSM_USB20_SEC_QSCRATCH_BASE;
239 else
240 return MSM_USB30_QSCRATCH_PRIM_BASE;
241}
242
243uint32_t usb_phy_base()
244{
245 if (board_hardware_id() == HW_PLATFORM_SBC)
246 return QUSB2_SEC_PHY_BASE;
247 else
248 return QUSB2_PRIM_PHY_BASE;
249}
250
251uint32_t usb_phy_bcr()
252{
253 if (board_hardware_id() == HW_PLATFORM_SBC)
254 return GCC_QUSB2_SEC_PHY_BCR;
255 else
256 return GCC_QUSB2_PRIM_PHY_BCR;
257}
258
Tanya Finkel77318e02016-05-17 14:20:59 +0300259int usb_irq()
260{
261 if (board_hardware_id() == HW_PLATFORM_SBC)
262 return USB20_IRQ;
263 else
264 return USB30_IRQ;
265}