Ajay Dudani | fa746af | 2009-12-02 13:51:09 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2009, Code Aurora Forum. All rights reserved. |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 2 | * |
Ajay Dudani | fa746af | 2009-12-02 13:51:09 -0800 | [diff] [blame] | 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. |
| 10 | * * Neither the name of Code Aurora nor |
| 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. |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 14 | * |
Ajay Dudani | fa746af | 2009-12-02 13:51:09 -0800 | [diff] [blame] | 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. |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 26 | * |
| 27 | */ |
| 28 | |
| 29 | #include <reg.h> |
Ajay Dudani | 3337ebb | 2009-12-05 18:13:05 -0800 | [diff] [blame] | 30 | #include <debug.h> |
| 31 | #include <smem.h> |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 32 | |
Chandan Uddaraju | a71835f | 2010-03-31 13:06:47 -0700 | [diff] [blame] | 33 | #define EBI1_ADDR_128M 0x08000000 |
Karthik Parsha | b26c956 | 2010-06-23 16:27:30 -0700 | [diff] [blame] | 34 | #define SIZE_256M 0x10000000 |
| 35 | #define SIZE_128M 0x08000000 |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 36 | #define SIZE_1M 0x00100000 |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 37 | |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 38 | static int scratch_addr = -1; |
| 39 | int smem_ram_ptable_init(struct smem_ram_ptable *); |
David Ng | 3679bc5 | 2010-02-09 15:43:43 -0800 | [diff] [blame] | 40 | |
| 41 | unsigned* target_atag_mem(unsigned* ptr) |
| 42 | { |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 43 | struct smem_ram_ptable ram_ptable; |
| 44 | unsigned i = 0; |
Ajay Dudani | 3337ebb | 2009-12-05 18:13:05 -0800 | [diff] [blame] | 45 | |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 46 | if (smem_ram_ptable_init(&ram_ptable)) |
Chandan Uddaraju | a71835f | 2010-03-31 13:06:47 -0700 | [diff] [blame] | 47 | { |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 48 | for (i = 0; i < ram_ptable.len; i++) |
| 49 | { |
| 50 | if ((ram_ptable.parts[i].attr == READWRITE) |
| 51 | && (ram_ptable.parts[i].domain == APPS_DOMAIN) |
Dima Zavin | b6da17d | 2011-01-11 16:45:22 -0800 | [diff] [blame^] | 52 | && (ram_ptable.parts[i].type == APPS_MEMORY) |
| 53 | && (ram_ptable.parts[i].category != IMEM)) |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 54 | { |
| 55 | /* ATAG_MEM */ |
| 56 | *ptr++ = 4; |
Karthik Parsha | b26c956 | 2010-06-23 16:27:30 -0700 | [diff] [blame] | 57 | // Tag EBI-1 memory as unstable. |
| 58 | if(ram_ptable.parts[i].category == EBI1_CS0) { |
| 59 | // if EBI-1 CS-0 is 256Mb then this is a 2x256 target and |
| 60 | // the kernel can reserve this mem region as unstable. |
| 61 | // This memory region can be activated when the kernel |
| 62 | // receives a request from Android init scripts. |
| 63 | if(ram_ptable.parts[i].size == SIZE_256M) |
| 64 | *ptr++ = 0x5441000A; //Deep-Power-Down Tag. |
| 65 | |
| 66 | //if EBI-1 CS-0 s 128Mb then this is a 2x128 target. |
| 67 | //Android + Kernel + PMEM regions account for more than |
| 68 | //128Mb and the target will not be able to boot with just |
| 69 | //one memory bank active and the second memory bank is reserved. |
| 70 | //In the case of 2x128 the tag is set to SelfRefresh Only. |
| 71 | else if(ram_ptable.parts[i].size == SIZE_128M) |
| 72 | *ptr++ = 0x5441000B; //Self-Refresh Tag. |
| 73 | } |
| 74 | else |
| 75 | *ptr++ = 0x54410002; |
| 76 | |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 77 | *ptr++ = ram_ptable.parts[i].size; |
| 78 | *ptr++ = ram_ptable.parts[i].start; |
| 79 | } |
Ajay Dudani | 9539c2d | 2010-09-22 14:35:20 -0700 | [diff] [blame] | 80 | |
| 81 | /* Check for modem bootloader memory that can be reclaimed */ |
| 82 | if ((ram_ptable.parts[i].attr == READWRITE) |
| 83 | && (ram_ptable.parts[i].domain == APPS_DOMAIN) |
| 84 | && (ram_ptable.parts[i].type == BOOT_REGION_MEMORY1)) |
| 85 | { |
| 86 | /* ATAG_MEM_OSBL */ |
| 87 | *ptr++ = 4; |
| 88 | *ptr++ = 0x5441000C; |
| 89 | *ptr++ = ram_ptable.parts[i].size; |
| 90 | *ptr++ = ram_ptable.parts[i].start; |
| 91 | } |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 92 | } |
Ajay Dudani | c51bf63 | 2010-04-15 10:41:23 -0700 | [diff] [blame] | 93 | } |
| 94 | else |
| 95 | { |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 96 | dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n"); |
| 97 | ASSERT(0); |
Chandan Uddaraju | a71835f | 2010-03-31 13:06:47 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Ajay Dudani | 3337ebb | 2009-12-05 18:13:05 -0800 | [diff] [blame] | 100 | return ptr; |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 101 | } |
Ajay Dudani | 3337ebb | 2009-12-05 18:13:05 -0800 | [diff] [blame] | 102 | |
David Ng | 3679bc5 | 2010-02-09 15:43:43 -0800 | [diff] [blame] | 103 | void *target_get_scratch_address(void) |
| 104 | { |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 105 | struct smem_ram_ptable ram_ptable; |
| 106 | unsigned i = 0; |
| 107 | |
| 108 | if (smem_ram_ptable_init(&ram_ptable)) |
| 109 | { |
| 110 | for (i = 0; i < ram_ptable.len; i++) |
| 111 | { |
| 112 | if ((ram_ptable.parts[i].attr == READWRITE) |
| 113 | && (ram_ptable.parts[i].domain == APPS_DOMAIN) |
| 114 | && (ram_ptable.parts[i].start != 0x0)) |
| 115 | { |
| 116 | if (ram_ptable.parts[i].size >= FASTBOOT_BUF_SIZE) |
| 117 | { |
| 118 | scratch_addr = ram_ptable.parts[i].start; |
| 119 | break; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n"); |
| 127 | ASSERT(0); |
| 128 | } |
| 129 | |
| 130 | return (void *)((scratch_addr == -1) ? EBI1_ADDR_128M : scratch_addr); |
David Ng | 3679bc5 | 2010-02-09 15:43:43 -0800 | [diff] [blame] | 131 | } |