blob: e0feaa11403896296ef1be3611902addda1e6a69 [file] [log] [blame]
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
Neeti Desai17379b82012-06-04 18:42:53 -07002 *
3 * Redistribution and use in source and binary forms, with or without
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07004 * modification, are permitted provided that the following conditions are
5 * met:
Neeti Desai17379b82012-06-04 18:42:53 -07006 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07008 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
Neeti Desai17379b82012-06-04 18:42:53 -070015 *
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070016 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Neeti Desai17379b82012-06-04 18:42:53 -070027 */
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>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070038#include <dev_tree.h>
Neeti Desai17379b82012-06-04 18:42:53 -070039
40#define SIZE_1M (1024 * 1024)
41
42typedef struct {
43 uint32_t size;
44 uint32_t start_addr;
45}mem_info;
46
Neeti Desai17379b82012-06-04 18:42:53 -070047mem_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
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070063int target_add_first_mem_bank(void *fdt,
64 uint32_t offset,
65 mem_info usable_mem_map[],
66 uint32_t num_regions)
Neeti Desai17379b82012-06-04 18:42:53 -070067{
68 uint32_t i;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070069 int ret;
Neeti Desai17379b82012-06-04 18:42:53 -070070
71 ASSERT(num_regions);
72
73 dprintf(SPEW, "Number of HLOS regions in 1st bank = %u\n", num_regions);
74
75 for (i = 0; i < num_regions; i++)
76 {
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070077 ret = dev_tree_add_mem_info(fdt,
78 offset,
79 usable_mem_map[i].start_addr,
80 usable_mem_map[i].size);
Neeti Desai17379b82012-06-04 18:42:53 -070081 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070082 return ret;
Neeti Desai17379b82012-06-04 18:42:53 -070083}
84
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070085/* Funtion to add the ram partition entries into device tree.
86 * The function assumes that all the entire fixed memory regions should
87 * be listed in the first bank of the passed in ddr regions.
88 */
89uint32_t target_dev_tree_mem(void *fdt, uint32_t memory_node_offset)
Neeti Desai17379b82012-06-04 18:42:53 -070090{
91 struct smem_ram_ptable ram_ptable;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070092 uint32_t last_fixed_addr;
Neeti Desaicf0a62c2012-08-10 16:58:21 -070093 int n;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070094 unsigned int i;
95 int ret;
Neeti Desai17379b82012-06-04 18:42:53 -070096
97 /* Make sure RAM partition table is initialized */
98 ASSERT(smem_ram_ptable_init(&ram_ptable));
99
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700100 n = ARRAY_SIZE(copper_default_fixed_memory);
Neeti Desai17379b82012-06-04 18:42:53 -0700101
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700102 last_fixed_addr = copper_default_fixed_memory[n-1].start_addr +
103 copper_default_fixed_memory[n-1].size;
Neeti Desai17379b82012-06-04 18:42:53 -0700104
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700105 /* Calculating the size of the mem_info_ptr */
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700106 for (i = 0 ; i < ram_ptable.len; i++)
107 {
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700108 if((ram_ptable.parts[i].category == SDRAM) &&
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700109 (ram_ptable.parts[i].type == SYS_MEMORY))
110 {
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700111 if((ram_ptable.parts[i].start <= last_fixed_addr) &&
112 ((ram_ptable.parts[i].start + ram_ptable.parts[i].size) >= last_fixed_addr))
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700113 {
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700114
115 /* Pass along all fixed memory regions to Linux */
116 ret = target_add_first_mem_bank(fdt,
117 memory_node_offset,
118 copper_default_fixed_memory,
119 ARRAY_SIZE(copper_default_fixed_memory));
120
121 if (ret)
122 {
123 dprintf(CRITICAL, "Failed to add first bank fixed memory addresses\n");
124 goto target_dev_tree_mem_err;
125 }
126
127 if((ram_ptable.parts[i].start + ram_ptable.parts[i].size) != last_fixed_addr)
128 {
129 /* Pass the memory beyond the fixed memory present in the partition */
130 ret = dev_tree_add_mem_info(fdt,
131 memory_node_offset,
132 ram_ptable.parts[i].start + last_fixed_addr,
133 ram_ptable.parts[i].size - last_fixed_addr);
134
135 if (ret)
136 {
137 dprintf(CRITICAL, "Failed to add first bank memory addresses\n");
138 goto target_dev_tree_mem_err;
139 }
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700140 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700141 }
142 else
143 {
144 /* Pass along all other usable memory regions to Linux */
145 ret = dev_tree_add_mem_info(fdt,
146 memory_node_offset,
147 ram_ptable.parts[i].start,
148 ram_ptable.parts[i].size);
149
150 if (ret)
151 {
152 dprintf(CRITICAL, "Failed to add secondary banks memory addresses\n");
153 goto target_dev_tree_mem_err;
154 }
155 }
156 }
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700157 }
Neeti Desai17379b82012-06-04 18:42:53 -0700158
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700159target_dev_tree_mem_err:
Neeti Desaicf0a62c2012-08-10 16:58:21 -0700160
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700161 return ret;
Neeti Desai17379b82012-06-04 18:42:53 -0700162}
163
164void *target_get_scratch_address(void)
165{
166 return ((void *)SCRATCH_ADDR);
167}
168
Deepa Dinamani157a93c2012-08-10 11:13:15 -0700169unsigned target_get_max_flash_size(void)
170{
171 return (512 * 1024 * 1024);
172}
Neeti Desai17379b82012-06-04 18:42:53 -0700173#endif /* DEVICE_TREE */