blob: 4d79e765b69ac81332347ebb395c9f7a875caf62 [file] [log] [blame]
Ajay Dudanifa746af2009-12-02 13:51:09 -08001/* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
Chandan Uddarajuc6860e12009-11-19 11:22:15 -08002 *
Ajay Dudanifa746af2009-12-02 13:51:09 -08003 * 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 Uddarajuc6860e12009-11-19 11:22:15 -080014 *
Ajay Dudanifa746af2009-12-02 13:51:09 -080015 * 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 Uddarajuc6860e12009-11-19 11:22:15 -080026 *
27 */
28
29#include <reg.h>
Ajay Dudani3337ebb2009-12-05 18:13:05 -080030#include <debug.h>
31#include <smem.h>
Chandan Uddarajuc6860e12009-11-19 11:22:15 -080032
Chandan Uddarajua71835f2010-03-31 13:06:47 -070033#define EBI1_ADDR_128M 0x08000000
Karthik Parshab26c9562010-06-23 16:27:30 -070034#define SIZE_256M 0x10000000
35#define SIZE_128M 0x08000000
Ajay Dudania1eafc42010-04-21 19:48:11 -070036#define SIZE_1M 0x00100000
Chandan Uddarajuc6860e12009-11-19 11:22:15 -080037
Ajay Dudania1eafc42010-04-21 19:48:11 -070038static int scratch_addr = -1;
39int smem_ram_ptable_init(struct smem_ram_ptable *);
David Ng3679bc52010-02-09 15:43:43 -080040
41unsigned* target_atag_mem(unsigned* ptr)
42{
Ajay Dudania1eafc42010-04-21 19:48:11 -070043 struct smem_ram_ptable ram_ptable;
44 unsigned i = 0;
Ajay Dudani3337ebb2009-12-05 18:13:05 -080045
Ajay Dudania1eafc42010-04-21 19:48:11 -070046 if (smem_ram_ptable_init(&ram_ptable))
Chandan Uddarajua71835f2010-03-31 13:06:47 -070047 {
Ajay Dudania1eafc42010-04-21 19:48:11 -070048 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 Zavinb6da17d2011-01-11 16:45:22 -080052 && (ram_ptable.parts[i].type == APPS_MEMORY)
53 && (ram_ptable.parts[i].category != IMEM))
Ajay Dudania1eafc42010-04-21 19:48:11 -070054 {
55 /* ATAG_MEM */
56 *ptr++ = 4;
Karthik Parshab26c9562010-06-23 16:27:30 -070057 // 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 Dudania1eafc42010-04-21 19:48:11 -070077 *ptr++ = ram_ptable.parts[i].size;
78 *ptr++ = ram_ptable.parts[i].start;
79 }
Ajay Dudani9539c2d2010-09-22 14:35:20 -070080
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 Dudania1eafc42010-04-21 19:48:11 -070092 }
Ajay Dudanic51bf632010-04-15 10:41:23 -070093 }
94 else
95 {
Ajay Dudania1eafc42010-04-21 19:48:11 -070096 dprintf(CRITICAL, "ERROR: Unable to read RAM partition\n");
97 ASSERT(0);
Chandan Uddarajua71835f2010-03-31 13:06:47 -070098 }
99
Ajay Dudani3337ebb2009-12-05 18:13:05 -0800100 return ptr;
Chandan Uddarajuc6860e12009-11-19 11:22:15 -0800101}
Ajay Dudani3337ebb2009-12-05 18:13:05 -0800102
David Ng3679bc52010-02-09 15:43:43 -0800103void *target_get_scratch_address(void)
104{
Ajay Dudania1eafc42010-04-21 19:48:11 -0700105 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 Ng3679bc52010-02-09 15:43:43 -0800131}