Aparna Mallavarapu | 2269a2f | 2013-01-07 19:44:48 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are met: |
| 5 | * * Redistributions of source code must retain the above copyright |
| 6 | * notice, this list of conditions and the following disclaimer. |
| 7 | * * Redistributions in binary form must reproduce the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer in the |
| 9 | * documentation and/or other materials provided with the distribution. |
Channagoud Kadabi | a6f305d | 2012-10-04 14:43:17 +0530 | [diff] [blame] | 10 | * * Neither the name of Linux Foundation nor |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 11 | * the names of its contributors may be used to endorse or promote |
| 12 | * products derived from this software without specific prior written |
| 13 | * permission. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | * |
| 27 | */ |
| 28 | |
Ajay Dudani | be7733b | 2011-07-06 15:39:26 -0700 | [diff] [blame] | 29 | #include <reg.h> |
| 30 | #include <debug.h> |
| 31 | #include <smem.h> |
| 32 | #include <stdint.h> |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 33 | #include "board.h" |
| 34 | #include "baseband.h" |
Shashank Mittal | 2ce1645 | 2011-04-26 17:50:00 -0700 | [diff] [blame] | 35 | |
Ajay Dudani | be7733b | 2011-07-06 15:39:26 -0700 | [diff] [blame] | 36 | #define SIZE_1M (1024 * 1024) |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 37 | #define SIZE_2M (2 * SIZE_1M) |
| 38 | #define SIZE_256M (256 * SIZE_1M) |
| 39 | #define SIZE_512M (512 * SIZE_1M) |
Channagoud Kadabi | 7d84dd6 | 2012-08-24 21:20:56 +0530 | [diff] [blame] | 40 | #define SIZE_768M (768 * SIZE_1M) |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 41 | |
| 42 | #define ATAG_MEM 0x54410002 |
| 43 | |
| 44 | #define PHYS_MEM_START_ADDR 0x80000000 |
| 45 | |
| 46 | typedef struct { |
| 47 | uint32_t size; |
| 48 | uint32_t start_addr; |
| 49 | }atag_mem_info; |
| 50 | |
| 51 | atag_mem_info apq8064_standalone_first_256M[] = { |
| 52 | { .size = (140 * SIZE_1M), |
| 53 | .start_addr = PHYS_MEM_START_ADDR + SIZE_2M |
| 54 | }, |
Channagoud Kadabi | a6f305d | 2012-10-04 14:43:17 +0530 | [diff] [blame] | 55 | { .size = (58 * SIZE_1M), |
| 56 | .start_addr = PHYS_MEM_START_ADDR + (0xA0 * SIZE_1M) |
| 57 | }, |
| 58 | { .size = (4 * SIZE_1M), |
| 59 | .start_addr = PHYS_MEM_START_ADDR + (0xEC * SIZE_1M) |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 60 | }, |
| 61 | { .size = (7 * SIZE_1M), |
| 62 | .start_addr = PHYS_MEM_START_ADDR + (0xF7 * SIZE_1M) |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | atag_mem_info apq8064_fusion_first_256M[] = { |
| 67 | { .size = (140 * SIZE_1M), |
| 68 | .start_addr = PHYS_MEM_START_ADDR + SIZE_2M |
| 69 | }, |
| 70 | { .size = (74 * SIZE_1M), |
| 71 | .start_addr = PHYS_MEM_START_ADDR + (0x90 * SIZE_1M) |
| 72 | }, |
| 73 | { .size = (7 * SIZE_1M), |
| 74 | .start_addr = PHYS_MEM_START_ADDR + (0xF7 * SIZE_1M) |
| 75 | }, |
Channagoud Kadabi | 9738c55 | 2012-08-13 15:49:55 +0530 | [diff] [blame] | 76 | { .size = (4 * SIZE_1M), |
| 77 | .start_addr = PHYS_MEM_START_ADDR + (0xEC * SIZE_1M) |
| 78 | }, |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 79 | { .size = SIZE_1M, |
| 80 | .start_addr = PHYS_MEM_START_ADDR + (0xFF * SIZE_1M) |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | atag_mem_info mpq8064_first_256M[] = { |
| 85 | { .size = (140 * SIZE_1M), |
| 86 | .start_addr = PHYS_MEM_START_ADDR + SIZE_2M |
| 87 | }, |
| 88 | { .size = (74 * SIZE_1M), |
| 89 | .start_addr = PHYS_MEM_START_ADDR + (0x90 * SIZE_1M) |
| 90 | }, |
Amol Jadi | 8f15a72 | 2012-08-20 14:28:42 -0700 | [diff] [blame] | 91 | { .size = (20 * SIZE_1M), |
| 92 | .start_addr = PHYS_MEM_START_ADDR + (0xEC * SIZE_1M) |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 93 | } |
| 94 | }; |
| 95 | |
| 96 | atag_mem_info msm8960_default_first_256M[] = { |
| 97 | { .size = (140 * SIZE_1M), |
| 98 | .start_addr = PHYS_MEM_START_ADDR + SIZE_2M |
| 99 | } |
| 100 | }; |
| 101 | |
Channagoud Kadabi | c8c8e02 | 2012-10-09 11:39:39 +0530 | [diff] [blame] | 102 | atag_mem_info msm8930_default_first_256M[] = { |
| 103 | { .size = (140 * SIZE_1M), |
| 104 | .start_addr = PHYS_MEM_START_ADDR + SIZE_2M |
| 105 | }, |
| 106 | { .size = (4 * SIZE_1M), |
| 107 | .start_addr = PHYS_MEM_START_ADDR + (0xEC * SIZE_1M) |
| 108 | }, |
| 109 | { .size = (3 * SIZE_1M), |
| 110 | .start_addr = PHYS_MEM_START_ADDR + (0xF8 * SIZE_1M) |
| 111 | }, |
| 112 | { .size = (1 * SIZE_1M), |
| 113 | .start_addr = PHYS_MEM_START_ADDR + (0xFE * SIZE_1M) |
| 114 | } |
| 115 | }; |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 116 | |
| 117 | unsigned *target_mem_atag_create(unsigned *ptr, uint32_t size, uint32_t addr) |
| 118 | { |
| 119 | *ptr++ = 4; |
| 120 | *ptr++ = ATAG_MEM; |
| 121 | *ptr++ = size; |
| 122 | *ptr++ = addr; |
| 123 | |
| 124 | return ptr; |
| 125 | } |
| 126 | |
| 127 | unsigned *target_atag(unsigned *ptr, atag_mem_info usable_mem_map[], unsigned num_regions) |
| 128 | { |
| 129 | unsigned i; |
| 130 | |
| 131 | dprintf(SPEW, "Number of regions for HLOS in 1st 256MB = %u\n", num_regions); |
| 132 | for (i=0; i < num_regions; i++) |
| 133 | { |
| 134 | ptr = target_mem_atag_create(ptr, |
| 135 | usable_mem_map[i].size, |
| 136 | usable_mem_map[i].start_addr); |
| 137 | } |
| 138 | return ptr; |
| 139 | } |
| 140 | |
| 141 | unsigned *target_first_256M_atag(unsigned *ptr) |
| 142 | { |
| 143 | unsigned int platform_id = board_platform_id(); |
| 144 | unsigned int baseband = board_baseband(); |
| 145 | |
| 146 | switch (platform_id) { |
| 147 | case APQ8064: |
Aparna Mallavarapu | 2269a2f | 2013-01-07 19:44:48 +0530 | [diff] [blame] | 148 | case APQ8064AA: |
Amol Jadi | 117ef3a | 2012-09-20 13:32:55 -0700 | [diff] [blame] | 149 | case APQ8064AB: |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 150 | if(baseband == BASEBAND_MDM) |
| 151 | { |
| 152 | /* Use 8064 Fusion 3 memory map */ |
| 153 | ptr = target_atag(ptr, |
| 154 | apq8064_fusion_first_256M, |
| 155 | ARRAY_SIZE(apq8064_fusion_first_256M)); |
| 156 | } else { |
| 157 | /* Use 8064 standalone memory map */ |
| 158 | ptr = target_atag(ptr, |
| 159 | apq8064_standalone_first_256M, |
| 160 | ARRAY_SIZE(apq8064_standalone_first_256M)); |
| 161 | } |
| 162 | break; |
| 163 | |
| 164 | case MPQ8064: |
| 165 | ptr = target_atag(ptr, mpq8064_first_256M, ARRAY_SIZE(mpq8064_first_256M)); |
| 166 | break; |
David Ng | 0f56e93 | 2013-02-12 18:11:56 -0800 | [diff] [blame] | 167 | case MSM8130: |
Channagoud Kadabi | c8c8e02 | 2012-10-09 11:39:39 +0530 | [diff] [blame] | 168 | case MSM8230: |
| 169 | case MSM8930: |
| 170 | case MSM8630: |
David Ng | 0f56e93 | 2013-02-12 18:11:56 -0800 | [diff] [blame] | 171 | case MSM8130AA: |
Channagoud Kadabi | c8c8e02 | 2012-10-09 11:39:39 +0530 | [diff] [blame] | 172 | case MSM8230AA: |
| 173 | case MSM8630AA: |
| 174 | case MSM8930AA: |
| 175 | case MSM8930AB: |
| 176 | case MSM8630AB: |
| 177 | case MSM8230AB: |
David Ng | 0f56e93 | 2013-02-12 18:11:56 -0800 | [diff] [blame] | 178 | case MSM8130AB: |
Channagoud Kadabi | c8c8e02 | 2012-10-09 11:39:39 +0530 | [diff] [blame] | 179 | case APQ8030AB: |
| 180 | case APQ8030: |
Channagoud Kadabi | 512295f | 2012-10-23 10:00:42 +0530 | [diff] [blame] | 181 | case APQ8030AA: |
Channagoud Kadabi | c8c8e02 | 2012-10-09 11:39:39 +0530 | [diff] [blame] | 182 | ptr = target_atag(ptr, msm8930_default_first_256M, |
| 183 | ARRAY_SIZE(msm8930_default_first_256M)); |
| 184 | break; |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 185 | case MSM8960: /* fall through */ |
Neeti Desai | 6e01525 | 2012-08-13 13:22:37 -0700 | [diff] [blame] | 186 | case MSM8960AB: |
| 187 | case APQ8060AB: |
| 188 | case MSM8260AB: |
| 189 | case MSM8660AB: |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 190 | default: |
| 191 | ptr = target_atag(ptr, |
| 192 | msm8960_default_first_256M, |
| 193 | ARRAY_SIZE(msm8960_default_first_256M)); |
| 194 | break; |
| 195 | } |
| 196 | return ptr; |
| 197 | } |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 198 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 199 | unsigned *target_atag_mem(unsigned *ptr) |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 200 | { |
Ajay Dudani | be7733b | 2011-07-06 15:39:26 -0700 | [diff] [blame] | 201 | struct smem_ram_ptable ram_ptable; |
| 202 | uint8_t i = 0; |
Shashank Mittal | 2ce1645 | 2011-04-26 17:50:00 -0700 | [diff] [blame] | 203 | |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 204 | if (smem_ram_ptable_init(&ram_ptable)) |
| 205 | { |
| 206 | for (i = 0; i < ram_ptable.len; i++) |
| 207 | { |
Ajay Dudani | ebb0b5b | 2011-08-02 14:35:55 -0700 | [diff] [blame] | 208 | if (ram_ptable.parts[i].category == SDRAM && |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 209 | (ram_ptable.parts[i].type == SYS_MEMORY) && |
| 210 | (ram_ptable.parts[i].start == PHYS_MEM_START_ADDR)) |
| 211 | { |
Ajay Dudani | ebb0b5b | 2011-08-02 14:35:55 -0700 | [diff] [blame] | 212 | ASSERT(ram_ptable.parts[i].size >= SIZE_256M); |
Ajay Dudani | be7733b | 2011-07-06 15:39:26 -0700 | [diff] [blame] | 213 | |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 214 | ptr = target_first_256M_atag(ptr); |
Ajay Dudani | be7733b | 2011-07-06 15:39:26 -0700 | [diff] [blame] | 215 | |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 216 | if (ram_ptable.parts[i].size > SIZE_256M) |
| 217 | { |
| 218 | ptr = target_mem_atag_create(ptr, |
| 219 | (ram_ptable.parts[i].size - SIZE_256M), |
| 220 | (ram_ptable.parts[i].start + SIZE_256M)); |
Ajay Dudani | 0ec110f | 2011-08-26 12:57:45 -0700 | [diff] [blame] | 221 | } |
Ajay Dudani | be7733b | 2011-07-06 15:39:26 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Ajay Dudani | ebb0b5b | 2011-08-02 14:35:55 -0700 | [diff] [blame] | 224 | /* Pass along all other usable memory regions to Linux */ |
| 225 | if (ram_ptable.parts[i].category == SDRAM && |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 226 | (ram_ptable.parts[i].type == SYS_MEMORY) && |
| 227 | (ram_ptable.parts[i].start != PHYS_MEM_START_ADDR)) |
| 228 | { |
| 229 | ptr = target_mem_atag_create(ptr, |
| 230 | ram_ptable.parts[i].size, |
| 231 | ram_ptable.parts[i].start); |
Ajay Dudani | be7733b | 2011-07-06 15:39:26 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 234 | } else { |
Ajay Dudani | be7733b | 2011-07-06 15:39:26 -0700 | [diff] [blame] | 235 | dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n"); |
| 236 | ASSERT(0); |
| 237 | } |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 238 | |
| 239 | return ptr; |
| 240 | } |
| 241 | |
| 242 | void *target_get_scratch_address(void) |
| 243 | { |
Naveen Kalla | a022187 | 2012-04-09 18:24:57 -0700 | [diff] [blame] | 244 | return ((void *) SCRATCH_ADDR); |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 245 | } |
Shashank Mittal | daef9e5 | 2011-05-09 15:23:14 -0700 | [diff] [blame] | 246 | |
| 247 | unsigned target_get_max_flash_size(void) |
| 248 | { |
Channagoud Kadabi | 7d84dd6 | 2012-08-24 21:20:56 +0530 | [diff] [blame] | 249 | return (SIZE_768M); |
Shashank Mittal | daef9e5 | 2011-05-09 15:23:14 -0700 | [diff] [blame] | 250 | } |