blob: fae3aeac6246a180efaf774da7a1b857ff4cb349 [file] [log] [blame]
Neeti Desai17379b82012-06-04 18:42:53 -07001/* Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
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.
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.
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
29#if DEVICE_TREE /* If using device tree */
30
31#include <reg.h>
32#include <debug.h>
33#include <malloc.h>
34#include <smem.h>
35#include <stdint.h>
36#include <libfdt.h>
37#include <platform/iomap.h>
38
39#define SIZE_1M (1024 * 1024)
40
41typedef struct {
42 uint32_t size;
43 uint32_t start_addr;
44}mem_info;
45
46
47mem_info copper_default_fixed_memory[] = {
48 { .size = (132 * SIZE_1M),
49 .start_addr = SDRAM_START_ADDR
50 },
51 { .size = SIZE_1M,
52 .start_addr = SDRAM_START_ADDR +
53 (250 * SIZE_1M) +
54 (5 * SIZE_1M)
55 },
56 { .size = (240 * SIZE_1M),
57 .start_addr = SDRAM_START_ADDR +
58 (16 * SIZE_1M) +
59 (256 * SIZE_1M)
60 },
Neeti Desai17379b82012-06-04 18:42:53 -070061};
62
63uint32_t *target_mem_dev_tree_create(uint32_t *ptr, uint32_t size, uint32_t addr)
64{
65 *ptr++ = cpu_to_fdt32(addr);
66 *ptr++ = cpu_to_fdt32(size);
67
68 return ptr;
69}
70
71uint32_t *target_dev_tree_create(uint32_t *ptr,
72 mem_info usable_mem_map[],
73 uint32_t num_regions)
74{
75 uint32_t i;
76
77 ASSERT(num_regions);
78
79 dprintf(SPEW, "Number of HLOS regions in 1st bank = %u\n", num_regions);
80
81 for (i = 0; i < num_regions; i++)
82 {
83 ptr = target_mem_dev_tree_create(ptr,
84 usable_mem_map[i].size,
85 usable_mem_map[i].start_addr);
86 }
87 return ptr;
88}
89
90uint32_t* target_dev_tree_mem(uint32_t *num_of_entries)
91{
92 struct smem_ram_ptable ram_ptable;
Neeti Desaicf0a62c2012-08-10 16:58:21 -070093 uint32_t *meminfo_ptr;
94 uint32_t num_of_sections = 0;
95 uint32_t *ptr;
96 uint32_t last_fixed_add;
97 int n;
98 int i;
99 int index = 0;
100 int count = 0;
101 int overflow = 0;
Neeti Desai17379b82012-06-04 18:42:53 -0700102
103 /* Make sure RAM partition table is initialized */
104 ASSERT(smem_ram_ptable_init(&ram_ptable));
105
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700106 n = ARRAY_SIZE(copper_default_fixed_memory);
107 last_fixed_add = copper_default_fixed_memory[n-1].start_addr +
108 copper_default_fixed_memory[n-1].size;
Neeti Desai17379b82012-06-04 18:42:53 -0700109
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700110 /* Find the number of parts in ram_ptable of category SDRAM and type SYS_MEMORY */
111 for(i = 0; i < ram_ptable.len; i++)
112 { if((ram_ptable.parts[i].category ==SDRAM) &&
113 (ram_ptable.parts[i].type == SYS_MEMORY))
114 count++;
115 }
Neeti Desai17379b82012-06-04 18:42:53 -0700116
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700117 /* Calculating the size of the mem_info_ptr */
118 for (i = 0 ; i < ram_ptable.len; i++)
119 {
120 if((ram_ptable.parts[i].category ==SDRAM) &&
121 (ram_ptable.parts[i].type == SYS_MEMORY))
122 {
123 if((ram_ptable.parts[i].start <= last_fixed_add) &&
124 ((ram_ptable.parts[i].start + ram_ptable.parts[i].size) >= last_fixed_add))
125 {
126 if((ram_ptable.parts[i].start + ram_ptable.parts[i].size) == last_fixed_add)
127 {
128 num_of_sections = n + (count - i - 1);
129 }
130 else
131 {
132 num_of_sections = n + (count - i );
133 overflow = 1;
134 }
135 index = i+1;
136 break;
137 }
138 }
139 }
Neeti Desai17379b82012-06-04 18:42:53 -0700140
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700141 *num_of_entries = num_of_sections;
142 meminfo_ptr = (uint32_t*) malloc(sizeof(uint32_t) * num_of_sections * 2);
143 ptr = meminfo_ptr;
144
145 /* Assumption that the fixed memory region always starts from the first ram_ptable part */
146 ASSERT((ram_ptable.parts[0].category ==SDRAM) &&
147 (ram_ptable.parts[0].type == SYS_MEMORY) &&
148 (ram_ptable.parts[0].start == SDRAM_START_ADDR));
149
150 /* Pass along all fixed memory regions to Linux */
151 meminfo_ptr = target_dev_tree_create(meminfo_ptr, copper_default_fixed_memory,
152 ARRAY_SIZE(copper_default_fixed_memory));
153
154 if(overflow)
155 {
156 /* Pass the memory beyond the fixed memory present in the partition */
157 meminfo_ptr = target_mem_dev_tree_create(meminfo_ptr,
158 ram_ptable.parts[i].size - last_fixed_add,
159 ram_ptable.parts[i].start + last_fixed_add);
160 }
161 for( i = index ; i < ram_ptable.len ; i ++)
162 {
163 if((ram_ptable.parts[i].category ==SDRAM) &&
164 (ram_ptable.parts[i].type == SYS_MEMORY))
165 {
166 /* Pass along all other usable memory regions to Linux */
167 meminfo_ptr = target_mem_dev_tree_create(meminfo_ptr,
168 ram_ptable.parts[i].size,
169 ram_ptable.parts[i].start);
170 }
171 }
172 return ptr;
Neeti Desai17379b82012-06-04 18:42:53 -0700173}
174
175void *target_get_scratch_address(void)
176{
177 return ((void *)SCRATCH_ADDR);
178}
179
Deepa Dinamani157a93c2012-08-10 11:13:15 -0700180unsigned target_get_max_flash_size(void)
181{
182 return (512 * 1024 * 1024);
183}
Neeti Desai17379b82012-06-04 18:42:53 -0700184#endif /* DEVICE_TREE */
185