aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm')
-rw-r--r--arch/arm/include/asm/memory.h9
-rw-r--r--arch/arm/kernel/tcm.c91
-rw-r--r--arch/arm/mach-u300/include/mach/memory.h8
-rw-r--r--arch/arm/mm/init.c17
4 files changed, 64 insertions, 61 deletions
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 4312ee5e3d0b..ab08d977ad49 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -124,6 +124,15 @@
124#endif /* !CONFIG_MMU */ 124#endif /* !CONFIG_MMU */
125 125
126/* 126/*
127 * We fix the TCM memories max 32 KiB ITCM resp DTCM at these
128 * locations
129 */
130#ifdef CONFIG_HAVE_TCM
131#define ITCM_OFFSET UL(0xfffe0000)
132#define DTCM_OFFSET UL(0xfffe8000)
133#endif
134
135/*
127 * Physical vs virtual RAM address space conversion. These are 136 * Physical vs virtual RAM address space conversion. These are
128 * private definitions which should NOT be used outside memory.h 137 * private definitions which should NOT be used outside memory.h
129 * files. Use virt_to_phys/phys_to_virt/__pa/__va instead. 138 * files. Use virt_to_phys/phys_to_virt/__pa/__va instead.
diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
index f2ead32c1aa0..26685c2f7a49 100644
--- a/arch/arm/kernel/tcm.c
+++ b/arch/arm/kernel/tcm.c
@@ -18,32 +18,30 @@
18#include <mach/memory.h> 18#include <mach/memory.h>
19#include "tcm.h" 19#include "tcm.h"
20 20
21/* Scream and warn about misuse */
22#if !defined(ITCM_OFFSET) || !defined(ITCM_END) || \
23 !defined(DTCM_OFFSET) || !defined(DTCM_END)
24#error "TCM support selected but offsets not defined!"
25#endif
26
27static struct gen_pool *tcm_pool; 21static struct gen_pool *tcm_pool;
28 22
29/* TCM section definitions from the linker */ 23/* TCM section definitions from the linker */
30extern char __itcm_start, __sitcm_text, __eitcm_text; 24extern char __itcm_start, __sitcm_text, __eitcm_text;
31extern char __dtcm_start, __sdtcm_data, __edtcm_data; 25extern char __dtcm_start, __sdtcm_data, __edtcm_data;
32 26
27/* These will be increased as we run */
28u32 dtcm_end = DTCM_OFFSET;
29u32 itcm_end = ITCM_OFFSET;
30
33/* 31/*
34 * TCM memory resources 32 * TCM memory resources
35 */ 33 */
36static struct resource dtcm_res = { 34static struct resource dtcm_res = {
37 .name = "DTCM RAM", 35 .name = "DTCM RAM",
38 .start = DTCM_OFFSET, 36 .start = DTCM_OFFSET,
39 .end = DTCM_END, 37 .end = DTCM_OFFSET,
40 .flags = IORESOURCE_MEM 38 .flags = IORESOURCE_MEM
41}; 39};
42 40
43static struct resource itcm_res = { 41static struct resource itcm_res = {
44 .name = "ITCM RAM", 42 .name = "ITCM RAM",
45 .start = ITCM_OFFSET, 43 .start = ITCM_OFFSET,
46 .end = ITCM_END, 44 .end = ITCM_OFFSET,
47 .flags = IORESOURCE_MEM 45 .flags = IORESOURCE_MEM
48}; 46};
49 47
@@ -51,7 +49,7 @@ static struct map_desc dtcm_iomap[] __initdata = {
51 { 49 {
52 .virtual = DTCM_OFFSET, 50 .virtual = DTCM_OFFSET,
53 .pfn = __phys_to_pfn(DTCM_OFFSET), 51 .pfn = __phys_to_pfn(DTCM_OFFSET),
54 .length = (DTCM_END - DTCM_OFFSET + 1), 52 .length = 0,
55 .type = MT_MEMORY_DTCM 53 .type = MT_MEMORY_DTCM
56 } 54 }
57}; 55};
@@ -60,7 +58,7 @@ static struct map_desc itcm_iomap[] __initdata = {
60 { 58 {
61 .virtual = ITCM_OFFSET, 59 .virtual = ITCM_OFFSET,
62 .pfn = __phys_to_pfn(ITCM_OFFSET), 60 .pfn = __phys_to_pfn(ITCM_OFFSET),
63 .length = (ITCM_END - ITCM_OFFSET + 1), 61 .length = 0,
64 .type = MT_MEMORY_ITCM 62 .type = MT_MEMORY_ITCM
65 } 63 }
66}; 64};
@@ -92,8 +90,8 @@ void tcm_free(void *addr, size_t len)
92} 90}
93EXPORT_SYMBOL(tcm_free); 91EXPORT_SYMBOL(tcm_free);
94 92
95static void __init setup_tcm_bank(u8 type, u8 bank, u8 banks, 93static int __init setup_tcm_bank(u8 type, u8 bank, u8 banks,
96 u32 offset, u32 expected_size) 94 u32 *offset)
97{ 95{
98 const int tcm_sizes[16] = { 0, -1, -1, 4, 8, 16, 32, 64, 128, 96 const int tcm_sizes[16] = { 0, -1, -1, 4, 8, 16, 32, 64, 128,
99 256, 512, 1024, -1, -1, -1, -1 }; 97 256, 512, 1024, -1, -1, -1, -1 };
@@ -120,8 +118,13 @@ static void __init setup_tcm_bank(u8 type, u8 bank, u8 banks,
120 118
121 tcm_size = tcm_sizes[(tcm_region >> 2) & 0x0f]; 119 tcm_size = tcm_sizes[(tcm_region >> 2) & 0x0f];
122 if (tcm_size < 0) { 120 if (tcm_size < 0) {
123 pr_err("CPU: %sTCM%d of unknown size!\n", 121 pr_err("CPU: %sTCM%d of unknown size\n",
124 type ? "I" : "D", bank); 122 type ? "I" : "D", bank);
123 return -EINVAL;
124 } else if (tcm_size > 32) {
125 pr_err("CPU: %sTCM%d larger than 32k found\n",
126 type ? "I" : "D", bank);
127 return -EINVAL;
125 } else { 128 } else {
126 pr_info("CPU: found %sTCM%d %dk @ %08x, %senabled\n", 129 pr_info("CPU: found %sTCM%d %dk @ %08x, %senabled\n",
127 type ? "I" : "D", 130 type ? "I" : "D",
@@ -131,17 +134,8 @@ static void __init setup_tcm_bank(u8 type, u8 bank, u8 banks,
131 (tcm_region & 1) ? "" : "not "); 134 (tcm_region & 1) ? "" : "not ");
132 } 135 }
133 136
134 if (tcm_size != (expected_size >> 10)) {
135 pr_crit("CPU: %sTCM%d was detected %dk but expected %dk!\n",
136 type ? "I" : "D",
137 bank,
138 tcm_size,
139 (expected_size >> 10));
140 /* Adjust to the expected size? what can we do... */
141 }
142
143 /* Force move the TCM bank to where we want it, enable */ 137 /* Force move the TCM bank to where we want it, enable */
144 tcm_region = offset | (tcm_region & 0x00000ffeU) | 1; 138 tcm_region = *offset | (tcm_region & 0x00000ffeU) | 1;
145 139
146 if (!type) 140 if (!type)
147 asm("mcr p15, 0, %0, c9, c1, 0" 141 asm("mcr p15, 0, %0, c9, c1, 0"
@@ -152,17 +146,17 @@ static void __init setup_tcm_bank(u8 type, u8 bank, u8 banks,
152 : /* No output operands */ 146 : /* No output operands */
153 : "r" (tcm_region)); 147 : "r" (tcm_region));
154 148
149 /* Increase offset */
150 *offset += (tcm_size << 10);
151
155 pr_info("CPU: moved %sTCM%d %dk to %08x, enabled\n", 152 pr_info("CPU: moved %sTCM%d %dk to %08x, enabled\n",
156 type ? "I" : "D", 153 type ? "I" : "D",
157 bank, 154 bank,
158 tcm_size, 155 tcm_size,
159 (tcm_region & 0xfffff000U)); 156 (tcm_region & 0xfffff000U));
157 return 0;
160} 158}
161 159
162/* We expect to find what is configured for the platform */
163#define DTCM_EXPECTED (DTCM_END - DTCM_OFFSET + 1)
164#define ITCM_EXPECTED (ITCM_END - ITCM_OFFSET + 1)
165
166/* 160/*
167 * This initializes the TCM memory 161 * This initializes the TCM memory
168 */ 162 */
@@ -170,40 +164,51 @@ void __init tcm_init(void)
170{ 164{
171 u32 tcm_status = read_cpuid_tcmstatus(); 165 u32 tcm_status = read_cpuid_tcmstatus();
172 u8 dtcm_banks = (tcm_status >> 16) & 0x03; 166 u8 dtcm_banks = (tcm_status >> 16) & 0x03;
173 u32 dtcm_banksize = DTCM_EXPECTED / dtcm_banks;
174 u8 itcm_banks = (tcm_status & 0x03); 167 u8 itcm_banks = (tcm_status & 0x03);
175 u32 itcm_banksize = ITCM_EXPECTED / itcm_banks;
176 char *start; 168 char *start;
177 char *end; 169 char *end;
178 char *ram; 170 char *ram;
171 int ret;
179 int i; 172 int i;
180 173
181 /* Setup DTCM if present */ 174 /* Setup DTCM if present */
182 for (i = 0; i < dtcm_banks; i++) { 175 if (dtcm_banks > 0) {
183 setup_tcm_bank(0, i, dtcm_banks, 176 for (i = 0; i < dtcm_banks; i++) {
184 DTCM_OFFSET + (i * dtcm_banksize), 177 ret = setup_tcm_bank(0, i, dtcm_banks, &dtcm_end);
185 dtcm_banksize); 178 if (ret)
179 return;
180 }
181 dtcm_res.end = dtcm_end - 1;
186 request_resource(&iomem_resource, &dtcm_res); 182 request_resource(&iomem_resource, &dtcm_res);
183 dtcm_iomap[0].length = dtcm_end - DTCM_OFFSET;
187 iotable_init(dtcm_iomap, 1); 184 iotable_init(dtcm_iomap, 1);
188 /* Copy data from RAM to DTCM */ 185 /* Copy data from RAM to DTCM */
189 start = &__sdtcm_data; 186 start = &__sdtcm_data;
190 end = &__edtcm_data; 187 end = &__edtcm_data;
191 ram = &__dtcm_start; 188 ram = &__dtcm_start;
189 /* This means you compiled more code than fits into DTCM */
190 BUG_ON((end - start) > (dtcm_end - DTCM_OFFSET));
192 memcpy(start, ram, (end-start)); 191 memcpy(start, ram, (end-start));
193 pr_debug("CPU DTCM: copied data from %p - %p\n", start, end); 192 pr_debug("CPU DTCM: copied data from %p - %p\n", start, end);
194 } 193 }
195 194
196 /* Setup ITCM if present */ 195 /* Setup ITCM if present */
197 for (i = 0; i < itcm_banks; i++) { 196 if (itcm_banks > 0) {
198 setup_tcm_bank(1, i, itcm_banks, 197 for (i = 0; i < itcm_banks; i++) {
199 ITCM_OFFSET + (i * itcm_banksize), 198 ret = setup_tcm_bank(1, i, itcm_banks, &itcm_end);
200 itcm_banksize); 199 if (ret)
200 return;
201 }
202 itcm_res.end = itcm_end - 1;
201 request_resource(&iomem_resource, &itcm_res); 203 request_resource(&iomem_resource, &itcm_res);
204 itcm_iomap[0].length = itcm_end - ITCM_OFFSET;
202 iotable_init(itcm_iomap, 1); 205 iotable_init(itcm_iomap, 1);
203 /* Copy code from RAM to ITCM */ 206 /* Copy code from RAM to ITCM */
204 start = &__sitcm_text; 207 start = &__sitcm_text;
205 end = &__eitcm_text; 208 end = &__eitcm_text;
206 ram = &__itcm_start; 209 ram = &__itcm_start;
210 /* This means you compiled more code than fits into ITCM */
211 BUG_ON((end - start) > (itcm_end - ITCM_OFFSET));
207 memcpy(start, ram, (end-start)); 212 memcpy(start, ram, (end-start));
208 pr_debug("CPU ITCM: copied code from %p - %p\n", start, end); 213 pr_debug("CPU ITCM: copied code from %p - %p\n", start, end);
209 } 214 }
@@ -232,9 +237,9 @@ static int __init setup_tcm_pool(void)
232 237
233 /* Add the rest of DTCM to the TCM pool */ 238 /* Add the rest of DTCM to the TCM pool */
234 if (tcm_status & (0x03 << 16)) { 239 if (tcm_status & (0x03 << 16)) {
235 if (dtcm_pool_start < DTCM_END) { 240 if (dtcm_pool_start < dtcm_end) {
236 ret = gen_pool_add(tcm_pool, dtcm_pool_start, 241 ret = gen_pool_add(tcm_pool, dtcm_pool_start,
237 DTCM_END - dtcm_pool_start + 1, -1); 242 dtcm_end - dtcm_pool_start, -1);
238 if (ret) { 243 if (ret) {
239 pr_err("CPU DTCM: could not add DTCM " \ 244 pr_err("CPU DTCM: could not add DTCM " \
240 "remainder to pool!\n"); 245 "remainder to pool!\n");
@@ -242,16 +247,16 @@ static int __init setup_tcm_pool(void)
242 } 247 }
243 pr_debug("CPU DTCM: Added %08x bytes @ %08x to " \ 248 pr_debug("CPU DTCM: Added %08x bytes @ %08x to " \
244 "the TCM memory pool\n", 249 "the TCM memory pool\n",
245 DTCM_END - dtcm_pool_start + 1, 250 dtcm_end - dtcm_pool_start,
246 dtcm_pool_start); 251 dtcm_pool_start);
247 } 252 }
248 } 253 }
249 254
250 /* Add the rest of ITCM to the TCM pool */ 255 /* Add the rest of ITCM to the TCM pool */
251 if (tcm_status & 0x03) { 256 if (tcm_status & 0x03) {
252 if (itcm_pool_start < ITCM_END) { 257 if (itcm_pool_start < itcm_end) {
253 ret = gen_pool_add(tcm_pool, itcm_pool_start, 258 ret = gen_pool_add(tcm_pool, itcm_pool_start,
254 ITCM_END - itcm_pool_start + 1, -1); 259 itcm_end - itcm_pool_start, -1);
255 if (ret) { 260 if (ret) {
256 pr_err("CPU ITCM: could not add ITCM " \ 261 pr_err("CPU ITCM: could not add ITCM " \
257 "remainder to pool!\n"); 262 "remainder to pool!\n");
@@ -259,7 +264,7 @@ static int __init setup_tcm_pool(void)
259 } 264 }
260 pr_debug("CPU ITCM: Added %08x bytes @ %08x to " \ 265 pr_debug("CPU ITCM: Added %08x bytes @ %08x to " \
261 "the TCM memory pool\n", 266 "the TCM memory pool\n",
262 ITCM_END - itcm_pool_start + 1, 267 itcm_end - itcm_pool_start,
263 itcm_pool_start); 268 itcm_pool_start);
264 } 269 }
265 } 270 }
diff --git a/arch/arm/mach-u300/include/mach/memory.h b/arch/arm/mach-u300/include/mach/memory.h
index ab000df7fc03..bf134bcc129d 100644
--- a/arch/arm/mach-u300/include/mach/memory.h
+++ b/arch/arm/mach-u300/include/mach/memory.h
@@ -35,14 +35,6 @@
35#endif 35#endif
36 36
37/* 37/*
38 * TCM memory whereabouts
39 */
40#define ITCM_OFFSET 0xffff2000
41#define ITCM_END 0xffff3fff
42#define DTCM_OFFSET 0xffff4000
43#define DTCM_END 0xffff5fff
44
45/*
46 * We enable a real big DMA buffer if need be. 38 * We enable a real big DMA buffer if need be.
47 */ 39 */
48#define CONSISTENT_DMA_SIZE SZ_4M 40#define CONSISTENT_DMA_SIZE SZ_4M
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 526af48b1271..e00404e6f45b 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -529,6 +529,11 @@ void __init mem_init(void)
529{ 529{
530 unsigned long reserved_pages, free_pages; 530 unsigned long reserved_pages, free_pages;
531 int i, node; 531 int i, node;
532#ifdef CONFIG_HAVE_TCM
533 /* These pointers are filled in on TCM detection */
534 extern u32 dtcm_end;
535 extern u32 itcm_end;
536#endif
532 537
533#ifndef CONFIG_DISCONTIGMEM 538#ifndef CONFIG_DISCONTIGMEM
534 max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map; 539 max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
@@ -612,13 +617,9 @@ void __init mem_init(void)
612 printk(KERN_NOTICE "Virtual kernel memory layout:\n" 617 printk(KERN_NOTICE "Virtual kernel memory layout:\n"
613 " vector : 0x%08lx - 0x%08lx (%4ld kB)\n" 618 " vector : 0x%08lx - 0x%08lx (%4ld kB)\n"
614#ifdef CONFIG_HAVE_TCM 619#ifdef CONFIG_HAVE_TCM
615#ifdef DTCM_OFFSET
616 " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n" 620 " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
617#endif
618#ifdef ITCM_OFFSET
619 " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n" 621 " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
620#endif 622#endif
621#endif
622 " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" 623 " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
623#ifdef CONFIG_MMU 624#ifdef CONFIG_MMU
624 " DMA : 0x%08lx - 0x%08lx (%4ld MB)\n" 625 " DMA : 0x%08lx - 0x%08lx (%4ld MB)\n"
@@ -636,12 +637,8 @@ void __init mem_init(void)
636 MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) + 637 MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) +
637 (PAGE_SIZE)), 638 (PAGE_SIZE)),
638#ifdef CONFIG_HAVE_TCM 639#ifdef CONFIG_HAVE_TCM
639#ifdef DTCM_OFFSET 640 MLK(DTCM_OFFSET, (unsigned long) dtcm_end),
640 MLK(UL(DTCM_OFFSET), UL(DTCM_END + 1)), 641 MLK(ITCM_OFFSET, (unsigned long) itcm_end),
641#endif
642#ifdef ITCM_OFFSET
643 MLK(UL(ITCM_OFFSET), UL(ITCM_END + 1)),
644#endif
645#endif 642#endif
646 MLK(FIXADDR_START, FIXADDR_TOP), 643 MLK(FIXADDR_START, FIXADDR_TOP),
647#ifdef CONFIG_MMU 644#ifdef CONFIG_MMU