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 |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 34 | #define SIZE_1M 0x00100000 |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 35 | |
Ajay Dudani | 2787125 | 2011-07-05 12:23:59 -0700 | [diff] [blame] | 36 | |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 37 | static int scratch_addr = -1; |
David Ng | 3679bc5 | 2010-02-09 15:43:43 -0800 | [diff] [blame] | 38 | |
| 39 | unsigned* target_atag_mem(unsigned* ptr) |
| 40 | { |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 41 | struct smem_ram_ptable ram_ptable; |
| 42 | unsigned i = 0; |
Ajay Dudani | 3337ebb | 2009-12-05 18:13:05 -0800 | [diff] [blame] | 43 | |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 44 | if (smem_ram_ptable_init(&ram_ptable)) |
Chandan Uddaraju | a71835f | 2010-03-31 13:06:47 -0700 | [diff] [blame] | 45 | { |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 46 | for (i = 0; i < ram_ptable.len; i++) |
| 47 | { |
| 48 | if ((ram_ptable.parts[i].attr == READWRITE) |
| 49 | && (ram_ptable.parts[i].domain == APPS_DOMAIN) |
Dima Zavin | b6da17d | 2011-01-11 16:45:22 -0800 | [diff] [blame] | 50 | && (ram_ptable.parts[i].type == APPS_MEMORY) |
| 51 | && (ram_ptable.parts[i].category != IMEM)) |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 52 | { |
| 53 | /* ATAG_MEM */ |
| 54 | *ptr++ = 4; |
Ajay Dudani | 2787125 | 2011-07-05 12:23:59 -0700 | [diff] [blame] | 55 | *ptr++ = 0x54410002; |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 56 | *ptr++ = ram_ptable.parts[i].size; |
| 57 | *ptr++ = ram_ptable.parts[i].start; |
| 58 | } |
Ajay Dudani | 9539c2d | 2010-09-22 14:35:20 -0700 | [diff] [blame] | 59 | |
| 60 | /* Check for modem bootloader memory that can be reclaimed */ |
| 61 | if ((ram_ptable.parts[i].attr == READWRITE) |
| 62 | && (ram_ptable.parts[i].domain == APPS_DOMAIN) |
| 63 | && (ram_ptable.parts[i].type == BOOT_REGION_MEMORY1)) |
| 64 | { |
| 65 | /* ATAG_MEM_OSBL */ |
| 66 | *ptr++ = 4; |
| 67 | *ptr++ = 0x5441000C; |
| 68 | *ptr++ = ram_ptable.parts[i].size; |
| 69 | *ptr++ = ram_ptable.parts[i].start; |
| 70 | } |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 71 | } |
Ajay Dudani | c51bf63 | 2010-04-15 10:41:23 -0700 | [diff] [blame] | 72 | } |
| 73 | else |
| 74 | { |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 75 | dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n"); |
| 76 | ASSERT(0); |
Chandan Uddaraju | a71835f | 2010-03-31 13:06:47 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Ajay Dudani | 3337ebb | 2009-12-05 18:13:05 -0800 | [diff] [blame] | 79 | return ptr; |
Chandan Uddaraju | c6860e1 | 2009-11-19 11:22:15 -0800 | [diff] [blame] | 80 | } |
Ajay Dudani | 3337ebb | 2009-12-05 18:13:05 -0800 | [diff] [blame] | 81 | |
David Ng | 3679bc5 | 2010-02-09 15:43:43 -0800 | [diff] [blame] | 82 | void *target_get_scratch_address(void) |
| 83 | { |
Ajay Dudani | a1eafc4 | 2010-04-21 19:48:11 -0700 | [diff] [blame] | 84 | struct smem_ram_ptable ram_ptable; |
| 85 | unsigned i = 0; |
| 86 | |
| 87 | if (smem_ram_ptable_init(&ram_ptable)) |
| 88 | { |
| 89 | for (i = 0; i < ram_ptable.len; i++) |
| 90 | { |
| 91 | if ((ram_ptable.parts[i].attr == READWRITE) |
| 92 | && (ram_ptable.parts[i].domain == APPS_DOMAIN) |
| 93 | && (ram_ptable.parts[i].start != 0x0)) |
| 94 | { |
| 95 | if (ram_ptable.parts[i].size >= FASTBOOT_BUF_SIZE) |
| 96 | { |
| 97 | scratch_addr = ram_ptable.parts[i].start; |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n"); |
| 106 | ASSERT(0); |
| 107 | } |
| 108 | |
| 109 | return (void *)((scratch_addr == -1) ? EBI1_ADDR_128M : scratch_addr); |
David Ng | 3679bc5 | 2010-02-09 15:43:43 -0800 | [diff] [blame] | 110 | } |