blob: 2f2fdcc7f5993e2e652146427de8e8a3392ec6a9 [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 },
61 { .size = (512 * SIZE_1M),
62 .start_addr = (512 * SIZE_1M),
63 }
64};
65
66uint32_t *target_mem_dev_tree_create(uint32_t *ptr, uint32_t size, uint32_t addr)
67{
68 *ptr++ = cpu_to_fdt32(addr);
69 *ptr++ = cpu_to_fdt32(size);
70
71 return ptr;
72}
73
74uint32_t *target_dev_tree_create(uint32_t *ptr,
75 mem_info usable_mem_map[],
76 uint32_t num_regions)
77{
78 uint32_t i;
79
80 ASSERT(num_regions);
81
82 dprintf(SPEW, "Number of HLOS regions in 1st bank = %u\n", num_regions);
83
84 for (i = 0; i < num_regions; i++)
85 {
86 ptr = target_mem_dev_tree_create(ptr,
87 usable_mem_map[i].size,
88 usable_mem_map[i].start_addr);
89 }
90 return ptr;
91}
92
93uint32_t* target_dev_tree_mem(uint32_t *num_of_entries)
94{
95 struct smem_ram_ptable ram_ptable;
96 uint32_t *meminfo_ptr;
97 uint32_t num_of_sections;
98 uint32_t *ptr;
99
100 /* Make sure RAM partition table is initialized */
101 ASSERT(smem_ram_ptable_init(&ram_ptable));
102
103 num_of_sections = ARRAY_SIZE(copper_default_fixed_memory);
104 *num_of_entries = num_of_sections;
105
106 meminfo_ptr = (uint32_t*) malloc(sizeof(uint32_t) * num_of_sections * 2);
107 ptr = meminfo_ptr;
108
109 target_dev_tree_create(ptr,
110 copper_default_fixed_memory,
111 ARRAY_SIZE(copper_default_fixed_memory));
112
113 return meminfo_ptr;
114}
115
116void *target_get_scratch_address(void)
117{
118 return ((void *)SCRATCH_ADDR);
119}
120
121#endif /* DEVICE_TREE */
122