Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Mike Frysinger | 550d553 | 2008-02-02 15:55:37 +0800 | [diff] [blame] | 2 | * arch/blackfin/kernel/setup.c |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Mike Frysinger | 550d553 | 2008-02-02 15:55:37 +0800 | [diff] [blame] | 4 | * Copyright 2004-2006 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 5 | * |
Mike Frysinger | 550d553 | 2008-02-02 15:55:37 +0800 | [diff] [blame] | 6 | * Enter bugs at http://blackfin.uclinux.org/ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 7 | * |
Mike Frysinger | 550d553 | 2008-02-02 15:55:37 +0800 | [diff] [blame] | 8 | * Licensed under the GPL-2 or later. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/delay.h> |
| 12 | #include <linux/console.h> |
| 13 | #include <linux/bootmem.h> |
| 14 | #include <linux/seq_file.h> |
| 15 | #include <linux/cpu.h> |
| 16 | #include <linux/module.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 17 | #include <linux/tty.h> |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 18 | #include <linux/pfn.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 19 | |
| 20 | #include <linux/ext2_fs.h> |
| 21 | #include <linux/cramfs_fs.h> |
| 22 | #include <linux/romfs_fs.h> |
| 23 | |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 24 | #include <asm/cplb.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 25 | #include <asm/cacheflush.h> |
| 26 | #include <asm/blackfin.h> |
| 27 | #include <asm/cplbinit.h> |
Mike Frysinger | 1754a5d | 2007-11-23 11:28:11 +0800 | [diff] [blame] | 28 | #include <asm/div64.h> |
Bernd Schmidt | 7adfb58 | 2007-06-21 11:34:16 +0800 | [diff] [blame] | 29 | #include <asm/fixed_code.h> |
Robin Getz | ce3afa1 | 2007-10-09 17:28:36 +0800 | [diff] [blame] | 30 | #include <asm/early_printk.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 31 | |
Michael Hennerich | 6cda2e9 | 2008-02-02 15:10:51 +0800 | [diff] [blame] | 32 | static DEFINE_PER_CPU(struct cpu, cpu_devices); |
| 33 | |
Mike Frysinger | a9c59c2 | 2007-05-21 18:09:32 +0800 | [diff] [blame] | 34 | u16 _bfin_swrst; |
| 35 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 36 | unsigned long memory_start, memory_end, physical_mem_end; |
| 37 | unsigned long reserved_mem_dcache_on; |
| 38 | unsigned long reserved_mem_icache_on; |
| 39 | EXPORT_SYMBOL(memory_start); |
| 40 | EXPORT_SYMBOL(memory_end); |
| 41 | EXPORT_SYMBOL(physical_mem_end); |
| 42 | EXPORT_SYMBOL(_ramend); |
| 43 | |
| 44 | #ifdef CONFIG_MTD_UCLINUX |
| 45 | unsigned long memory_mtd_end, memory_mtd_start, mtd_size; |
| 46 | unsigned long _ebss; |
| 47 | EXPORT_SYMBOL(memory_mtd_end); |
| 48 | EXPORT_SYMBOL(memory_mtd_start); |
| 49 | EXPORT_SYMBOL(mtd_size); |
| 50 | #endif |
| 51 | |
Mike Frysinger | 5e10b4a | 2007-06-11 16:44:09 +0800 | [diff] [blame] | 52 | char __initdata command_line[COMMAND_LINE_SIZE]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 53 | |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 54 | /* boot memmap, for parsing "memmap=" */ |
| 55 | #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */ |
| 56 | #define BFIN_MEMMAP_RAM 1 |
| 57 | #define BFIN_MEMMAP_RESERVED 2 |
| 58 | struct bfin_memmap { |
| 59 | int nr_map; |
| 60 | struct bfin_memmap_entry { |
| 61 | unsigned long long addr; /* start of memory segment */ |
| 62 | unsigned long long size; |
| 63 | unsigned long type; |
| 64 | } map[BFIN_MEMMAP_MAX]; |
| 65 | } bfin_memmap __initdata; |
| 66 | |
| 67 | /* for memmap sanitization */ |
| 68 | struct change_member { |
| 69 | struct bfin_memmap_entry *pentry; /* pointer to original entry */ |
| 70 | unsigned long long addr; /* address for this change point */ |
| 71 | }; |
| 72 | static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata; |
| 73 | static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata; |
| 74 | static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata; |
| 75 | static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata; |
| 76 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 77 | void __init bf53x_cache_init(void) |
| 78 | { |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 79 | #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 80 | generate_cpl_tables(); |
| 81 | #endif |
| 82 | |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 83 | #ifdef CONFIG_BFIN_ICACHE |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 84 | bfin_icache_init(); |
| 85 | printk(KERN_INFO "Instruction Cache Enabled\n"); |
| 86 | #endif |
| 87 | |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 88 | #ifdef CONFIG_BFIN_DCACHE |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 89 | bfin_dcache_init(); |
| 90 | printk(KERN_INFO "Data Cache Enabled" |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 91 | # if defined CONFIG_BFIN_WB |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 92 | " (write-back)" |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 93 | # elif defined CONFIG_BFIN_WT |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 94 | " (write-through)" |
| 95 | # endif |
| 96 | "\n"); |
| 97 | #endif |
| 98 | } |
| 99 | |
Mike Frysinger | 52a0781 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 100 | void __init bf53x_relocate_l1_mem(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 101 | { |
| 102 | unsigned long l1_code_length; |
| 103 | unsigned long l1_data_a_length; |
| 104 | unsigned long l1_data_b_length; |
| 105 | |
| 106 | l1_code_length = _etext_l1 - _stext_l1; |
| 107 | if (l1_code_length > L1_CODE_LENGTH) |
| 108 | l1_code_length = L1_CODE_LENGTH; |
| 109 | /* cannot complain as printk is not available as yet. |
| 110 | * But we can continue booting and complain later! |
| 111 | */ |
| 112 | |
| 113 | /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */ |
| 114 | dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length); |
| 115 | |
| 116 | l1_data_a_length = _ebss_l1 - _sdata_l1; |
| 117 | if (l1_data_a_length > L1_DATA_A_LENGTH) |
| 118 | l1_data_a_length = L1_DATA_A_LENGTH; |
| 119 | |
| 120 | /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */ |
| 121 | dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length); |
| 122 | |
| 123 | l1_data_b_length = _ebss_b_l1 - _sdata_b_l1; |
| 124 | if (l1_data_b_length > L1_DATA_B_LENGTH) |
| 125 | l1_data_b_length = L1_DATA_B_LENGTH; |
| 126 | |
| 127 | /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */ |
| 128 | dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length + |
| 129 | l1_data_a_length, l1_data_b_length); |
| 130 | |
| 131 | } |
| 132 | |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 133 | /* add_memory_region to memmap */ |
| 134 | static void __init add_memory_region(unsigned long long start, |
| 135 | unsigned long long size, int type) |
| 136 | { |
| 137 | int i; |
| 138 | |
| 139 | i = bfin_memmap.nr_map; |
| 140 | |
| 141 | if (i == BFIN_MEMMAP_MAX) { |
| 142 | printk(KERN_ERR "Ooops! Too many entries in the memory map!\n"); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | bfin_memmap.map[i].addr = start; |
| 147 | bfin_memmap.map[i].size = size; |
| 148 | bfin_memmap.map[i].type = type; |
| 149 | bfin_memmap.nr_map++; |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * Sanitize the boot memmap, removing overlaps. |
| 154 | */ |
| 155 | static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map) |
| 156 | { |
| 157 | struct change_member *change_tmp; |
| 158 | unsigned long current_type, last_type; |
| 159 | unsigned long long last_addr; |
| 160 | int chgidx, still_changing; |
| 161 | int overlap_entries; |
| 162 | int new_entry; |
| 163 | int old_nr, new_nr, chg_nr; |
| 164 | int i; |
| 165 | |
| 166 | /* |
| 167 | Visually we're performing the following (1,2,3,4 = memory types) |
| 168 | |
| 169 | Sample memory map (w/overlaps): |
| 170 | ____22__________________ |
| 171 | ______________________4_ |
| 172 | ____1111________________ |
| 173 | _44_____________________ |
| 174 | 11111111________________ |
| 175 | ____________________33__ |
| 176 | ___________44___________ |
| 177 | __________33333_________ |
| 178 | ______________22________ |
| 179 | ___________________2222_ |
| 180 | _________111111111______ |
| 181 | _____________________11_ |
| 182 | _________________4______ |
| 183 | |
| 184 | Sanitized equivalent (no overlap): |
| 185 | 1_______________________ |
| 186 | _44_____________________ |
| 187 | ___1____________________ |
| 188 | ____22__________________ |
| 189 | ______11________________ |
| 190 | _________1______________ |
| 191 | __________3_____________ |
| 192 | ___________44___________ |
| 193 | _____________33_________ |
| 194 | _______________2________ |
| 195 | ________________1_______ |
| 196 | _________________4______ |
| 197 | ___________________2____ |
| 198 | ____________________33__ |
| 199 | ______________________4_ |
| 200 | */ |
| 201 | /* if there's only one memory region, don't bother */ |
| 202 | if (*pnr_map < 2) |
| 203 | return -1; |
| 204 | |
| 205 | old_nr = *pnr_map; |
| 206 | |
| 207 | /* bail out if we find any unreasonable addresses in memmap */ |
| 208 | for (i = 0; i < old_nr; i++) |
| 209 | if (map[i].addr + map[i].size < map[i].addr) |
| 210 | return -1; |
| 211 | |
| 212 | /* create pointers for initial change-point information (for sorting) */ |
| 213 | for (i = 0; i < 2*old_nr; i++) |
| 214 | change_point[i] = &change_point_list[i]; |
| 215 | |
| 216 | /* record all known change-points (starting and ending addresses), |
| 217 | omitting those that are for empty memory regions */ |
| 218 | chgidx = 0; |
| 219 | for (i = 0; i < old_nr; i++) { |
| 220 | if (map[i].size != 0) { |
| 221 | change_point[chgidx]->addr = map[i].addr; |
| 222 | change_point[chgidx++]->pentry = &map[i]; |
| 223 | change_point[chgidx]->addr = map[i].addr + map[i].size; |
| 224 | change_point[chgidx++]->pentry = &map[i]; |
| 225 | } |
| 226 | } |
| 227 | chg_nr = chgidx; /* true number of change-points */ |
| 228 | |
| 229 | /* sort change-point list by memory addresses (low -> high) */ |
| 230 | still_changing = 1; |
| 231 | while (still_changing) { |
| 232 | still_changing = 0; |
| 233 | for (i = 1; i < chg_nr; i++) { |
| 234 | /* if <current_addr> > <last_addr>, swap */ |
| 235 | /* or, if current=<start_addr> & last=<end_addr>, swap */ |
| 236 | if ((change_point[i]->addr < change_point[i-1]->addr) || |
| 237 | ((change_point[i]->addr == change_point[i-1]->addr) && |
| 238 | (change_point[i]->addr == change_point[i]->pentry->addr) && |
| 239 | (change_point[i-1]->addr != change_point[i-1]->pentry->addr)) |
| 240 | ) { |
| 241 | change_tmp = change_point[i]; |
| 242 | change_point[i] = change_point[i-1]; |
| 243 | change_point[i-1] = change_tmp; |
| 244 | still_changing = 1; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /* create a new memmap, removing overlaps */ |
| 250 | overlap_entries = 0; /* number of entries in the overlap table */ |
| 251 | new_entry = 0; /* index for creating new memmap entries */ |
| 252 | last_type = 0; /* start with undefined memory type */ |
| 253 | last_addr = 0; /* start with 0 as last starting address */ |
| 254 | /* loop through change-points, determining affect on the new memmap */ |
| 255 | for (chgidx = 0; chgidx < chg_nr; chgidx++) { |
| 256 | /* keep track of all overlapping memmap entries */ |
| 257 | if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) { |
| 258 | /* add map entry to overlap list (> 1 entry implies an overlap) */ |
| 259 | overlap_list[overlap_entries++] = change_point[chgidx]->pentry; |
| 260 | } else { |
| 261 | /* remove entry from list (order independent, so swap with last) */ |
| 262 | for (i = 0; i < overlap_entries; i++) { |
| 263 | if (overlap_list[i] == change_point[chgidx]->pentry) |
| 264 | overlap_list[i] = overlap_list[overlap_entries-1]; |
| 265 | } |
| 266 | overlap_entries--; |
| 267 | } |
| 268 | /* if there are overlapping entries, decide which "type" to use */ |
| 269 | /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */ |
| 270 | current_type = 0; |
| 271 | for (i = 0; i < overlap_entries; i++) |
| 272 | if (overlap_list[i]->type > current_type) |
| 273 | current_type = overlap_list[i]->type; |
| 274 | /* continue building up new memmap based on this information */ |
| 275 | if (current_type != last_type) { |
| 276 | if (last_type != 0) { |
| 277 | new_map[new_entry].size = |
| 278 | change_point[chgidx]->addr - last_addr; |
| 279 | /* move forward only if the new size was non-zero */ |
| 280 | if (new_map[new_entry].size != 0) |
| 281 | if (++new_entry >= BFIN_MEMMAP_MAX) |
| 282 | break; /* no more space left for new entries */ |
| 283 | } |
| 284 | if (current_type != 0) { |
| 285 | new_map[new_entry].addr = change_point[chgidx]->addr; |
| 286 | new_map[new_entry].type = current_type; |
| 287 | last_addr = change_point[chgidx]->addr; |
| 288 | } |
| 289 | last_type = current_type; |
| 290 | } |
| 291 | } |
| 292 | new_nr = new_entry; /* retain count for new entries */ |
| 293 | |
| 294 | /* copy new mapping into original location */ |
| 295 | memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry)); |
| 296 | *pnr_map = new_nr; |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static void __init print_memory_map(char *who) |
| 302 | { |
| 303 | int i; |
| 304 | |
| 305 | for (i = 0; i < bfin_memmap.nr_map; i++) { |
| 306 | printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who, |
| 307 | bfin_memmap.map[i].addr, |
| 308 | bfin_memmap.map[i].addr + bfin_memmap.map[i].size); |
| 309 | switch (bfin_memmap.map[i].type) { |
| 310 | case BFIN_MEMMAP_RAM: |
| 311 | printk("(usable)\n"); |
| 312 | break; |
| 313 | case BFIN_MEMMAP_RESERVED: |
| 314 | printk("(reserved)\n"); |
| 315 | break; |
| 316 | default: printk("type %lu\n", bfin_memmap.map[i].type); |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | static __init int parse_memmap(char *arg) |
| 323 | { |
| 324 | unsigned long long start_at, mem_size; |
| 325 | |
| 326 | if (!arg) |
| 327 | return -EINVAL; |
| 328 | |
| 329 | mem_size = memparse(arg, &arg); |
| 330 | if (*arg == '@') { |
| 331 | start_at = memparse(arg+1, &arg); |
| 332 | add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM); |
| 333 | } else if (*arg == '$') { |
| 334 | start_at = memparse(arg+1, &arg); |
| 335 | add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED); |
| 336 | } |
| 337 | |
| 338 | return 0; |
| 339 | } |
| 340 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 341 | /* |
| 342 | * Initial parsing of the command line. Currently, we support: |
| 343 | * - Controlling the linux memory size: mem=xxx[KMG] |
| 344 | * - Controlling the physical memory size: max_mem=xxx[KMG][$][#] |
| 345 | * $ -> reserved memory is dcacheable |
| 346 | * # -> reserved memory is icacheable |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 347 | * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region |
| 348 | * @ from <start> to <start>+<mem>, type RAM |
| 349 | * $ from <start> to <start>+<mem>, type RESERVED |
| 350 | * |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 351 | */ |
| 352 | static __init void parse_cmdline_early(char *cmdline_p) |
| 353 | { |
| 354 | char c = ' ', *to = cmdline_p; |
| 355 | unsigned int memsize; |
| 356 | for (;;) { |
| 357 | if (c == ' ') { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 358 | if (!memcmp(to, "mem=", 4)) { |
| 359 | to += 4; |
| 360 | memsize = memparse(to, &to); |
| 361 | if (memsize) |
| 362 | _ramend = memsize; |
| 363 | |
| 364 | } else if (!memcmp(to, "max_mem=", 8)) { |
| 365 | to += 8; |
| 366 | memsize = memparse(to, &to); |
| 367 | if (memsize) { |
| 368 | physical_mem_end = memsize; |
| 369 | if (*to != ' ') { |
| 370 | if (*to == '$' |
| 371 | || *(to + 1) == '$') |
| 372 | reserved_mem_dcache_on = |
| 373 | 1; |
| 374 | if (*to == '#' |
| 375 | || *(to + 1) == '#') |
| 376 | reserved_mem_icache_on = |
| 377 | 1; |
| 378 | } |
| 379 | } |
Robin Getz | ce3afa1 | 2007-10-09 17:28:36 +0800 | [diff] [blame] | 380 | } else if (!memcmp(to, "earlyprintk=", 12)) { |
| 381 | to += 12; |
| 382 | setup_early_printk(to); |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 383 | } else if (!memcmp(to, "memmap=", 7)) { |
| 384 | to += 7; |
| 385 | parse_memmap(to); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 386 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 387 | } |
| 388 | c = *(to++); |
| 389 | if (!c) |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 394 | /* |
| 395 | * Setup memory defaults from user config. |
| 396 | * The physical memory layout looks like: |
| 397 | * |
| 398 | * [_rambase, _ramstart]: kernel image |
| 399 | * [memory_start, memory_end]: dynamic memory managed by kernel |
| 400 | * [memory_end, _ramend]: reserved memory |
| 401 | * [meory_mtd_start(memory_end), |
| 402 | * memory_mtd_start + mtd_size]: rootfs (if any) |
| 403 | * [_ramend - DMA_UNCACHED_REGION, |
| 404 | * _ramend]: uncached DMA region |
| 405 | * [_ramend, physical_mem_end]: memory not managed by kernel |
| 406 | * |
| 407 | */ |
| 408 | static __init void memory_setup(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 409 | { |
Mike Frysinger | c0eab3b | 2008-02-02 15:36:11 +0800 | [diff] [blame] | 410 | #ifdef CONFIG_MTD_UCLINUX |
| 411 | unsigned long mtd_phys = 0; |
| 412 | #endif |
| 413 | |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 414 | _rambase = (unsigned long)_stext; |
Mike Frysinger | b7627ac | 2008-02-02 15:53:17 +0800 | [diff] [blame] | 415 | _ramstart = (unsigned long)_end; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 416 | |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 417 | if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) { |
| 418 | console_init(); |
| 419 | panic("DMA region exceeds memory limit: %lu.\n", |
| 420 | _ramend - _ramstart); |
Mike Frysinger | 1aafd90 | 2007-07-25 11:19:14 +0800 | [diff] [blame] | 421 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 422 | memory_end = _ramend - DMA_UNCACHED_REGION; |
| 423 | |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 424 | #ifdef CONFIG_MPU |
| 425 | /* Round up to multiple of 4MB. */ |
| 426 | memory_start = (_ramstart + 0x3fffff) & ~0x3fffff; |
| 427 | #else |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 428 | memory_start = PAGE_ALIGN(_ramstart); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 429 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 430 | |
| 431 | #if defined(CONFIG_MTD_UCLINUX) |
| 432 | /* generic memory mapped MTD driver */ |
| 433 | memory_mtd_end = memory_end; |
| 434 | |
| 435 | mtd_phys = _ramstart; |
| 436 | mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8))); |
| 437 | |
| 438 | # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS) |
| 439 | if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC) |
| 440 | mtd_size = |
| 441 | PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10); |
| 442 | # endif |
| 443 | |
| 444 | # if defined(CONFIG_CRAMFS) |
| 445 | if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC) |
| 446 | mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4))); |
| 447 | # endif |
| 448 | |
| 449 | # if defined(CONFIG_ROMFS_FS) |
| 450 | if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0 |
| 451 | && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1) |
| 452 | mtd_size = |
| 453 | PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2])); |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 454 | # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 455 | /* Due to a Hardware Anomaly we need to limit the size of usable |
| 456 | * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on |
| 457 | * 05000263 - Hardware loop corrupted when taking an ICPLB exception |
| 458 | */ |
| 459 | # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO)) |
| 460 | if (memory_end >= 56 * 1024 * 1024) |
| 461 | memory_end = 56 * 1024 * 1024; |
| 462 | # else |
| 463 | if (memory_end >= 60 * 1024 * 1024) |
| 464 | memory_end = 60 * 1024 * 1024; |
| 465 | # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */ |
| 466 | # endif /* ANOMALY_05000263 */ |
| 467 | # endif /* CONFIG_ROMFS_FS */ |
| 468 | |
| 469 | memory_end -= mtd_size; |
| 470 | |
| 471 | if (mtd_size == 0) { |
| 472 | console_init(); |
| 473 | panic("Don't boot kernel without rootfs attached.\n"); |
| 474 | } |
| 475 | |
| 476 | /* Relocate MTD image to the top of memory after the uncached memory area */ |
Mike Frysinger | b7627ac | 2008-02-02 15:53:17 +0800 | [diff] [blame] | 477 | dma_memcpy((char *)memory_end, _end, mtd_size); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 478 | |
| 479 | memory_mtd_start = memory_end; |
| 480 | _ebss = memory_mtd_start; /* define _ebss for compatible */ |
| 481 | #endif /* CONFIG_MTD_UCLINUX */ |
| 482 | |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 483 | #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 484 | /* Due to a Hardware Anomaly we need to limit the size of usable |
| 485 | * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on |
| 486 | * 05000263 - Hardware loop corrupted when taking an ICPLB exception |
| 487 | */ |
| 488 | #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO)) |
| 489 | if (memory_end >= 56 * 1024 * 1024) |
| 490 | memory_end = 56 * 1024 * 1024; |
| 491 | #else |
| 492 | if (memory_end >= 60 * 1024 * 1024) |
| 493 | memory_end = 60 * 1024 * 1024; |
| 494 | #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */ |
| 495 | printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20); |
| 496 | #endif /* ANOMALY_05000263 */ |
| 497 | |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 498 | #ifdef CONFIG_MPU |
| 499 | page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32; |
| 500 | page_mask_order = get_order(3 * page_mask_nelts * sizeof(long)); |
| 501 | #endif |
| 502 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 503 | #if !defined(CONFIG_MTD_UCLINUX) |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 504 | /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/ |
| 505 | memory_end -= SIZE_4K; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 506 | #endif |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 507 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 508 | init_mm.start_code = (unsigned long)_stext; |
| 509 | init_mm.end_code = (unsigned long)_etext; |
| 510 | init_mm.end_data = (unsigned long)_edata; |
| 511 | init_mm.brk = (unsigned long)0; |
| 512 | |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 513 | printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20); |
| 514 | printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20); |
| 515 | |
Mike Frysinger | b7627ac | 2008-02-02 15:53:17 +0800 | [diff] [blame] | 516 | printk(KERN_INFO "Memory map:\n" |
Mike Frysinger | 8929ecf8 | 2008-02-22 16:35:20 +0800 | [diff] [blame^] | 517 | KERN_INFO " fixedcode = 0x%p-0x%p\n" |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 518 | KERN_INFO " text = 0x%p-0x%p\n" |
| 519 | KERN_INFO " rodata = 0x%p-0x%p\n" |
Mike Frysinger | b7627ac | 2008-02-02 15:53:17 +0800 | [diff] [blame] | 520 | KERN_INFO " bss = 0x%p-0x%p\n" |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 521 | KERN_INFO " data = 0x%p-0x%p\n" |
| 522 | KERN_INFO " stack = 0x%p-0x%p\n" |
| 523 | KERN_INFO " init = 0x%p-0x%p\n" |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 524 | KERN_INFO " available = 0x%p-0x%p\n" |
| 525 | #ifdef CONFIG_MTD_UCLINUX |
| 526 | KERN_INFO " rootfs = 0x%p-0x%p\n" |
| 527 | #endif |
| 528 | #if DMA_UNCACHED_REGION > 0 |
| 529 | KERN_INFO " DMA Zone = 0x%p-0x%p\n" |
| 530 | #endif |
Mike Frysinger | 8929ecf8 | 2008-02-22 16:35:20 +0800 | [diff] [blame^] | 531 | , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END, |
| 532 | _stext, _etext, |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 533 | __start_rodata, __end_rodata, |
Mike Frysinger | b7627ac | 2008-02-02 15:53:17 +0800 | [diff] [blame] | 534 | __bss_start, __bss_stop, |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 535 | _sdata, _edata, |
| 536 | (void *)&init_thread_union, |
| 537 | (void *)((int)(&init_thread_union) + 0x2000), |
Mike Frysinger | b7627ac | 2008-02-02 15:53:17 +0800 | [diff] [blame] | 538 | __init_begin, __init_end, |
| 539 | (void *)_ramstart, (void *)memory_end |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 540 | #ifdef CONFIG_MTD_UCLINUX |
| 541 | , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size) |
| 542 | #endif |
| 543 | #if DMA_UNCACHED_REGION > 0 |
| 544 | , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend) |
| 545 | #endif |
| 546 | ); |
| 547 | } |
| 548 | |
| 549 | static __init void setup_bootmem_allocator(void) |
| 550 | { |
| 551 | int bootmap_size; |
| 552 | int i; |
| 553 | unsigned long min_pfn, max_pfn; |
| 554 | unsigned long curr_pfn, last_pfn, size; |
| 555 | |
| 556 | /* mark memory between memory_start and memory_end usable */ |
| 557 | add_memory_region(memory_start, |
| 558 | memory_end - memory_start, BFIN_MEMMAP_RAM); |
| 559 | /* sanity check for overlap */ |
| 560 | sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map); |
| 561 | print_memory_map("boot memmap"); |
| 562 | |
| 563 | min_pfn = PAGE_OFFSET >> PAGE_SHIFT; |
| 564 | max_pfn = memory_end >> PAGE_SHIFT; |
| 565 | |
| 566 | /* |
| 567 | * give all the memory to the bootmap allocator, tell it to put the |
| 568 | * boot mem_map at the start of memory. |
| 569 | */ |
| 570 | bootmap_size = init_bootmem_node(NODE_DATA(0), |
| 571 | memory_start >> PAGE_SHIFT, /* map goes here */ |
| 572 | min_pfn, max_pfn); |
| 573 | |
| 574 | /* register the memmap regions with the bootmem allocator */ |
| 575 | for (i = 0; i < bfin_memmap.nr_map; i++) { |
| 576 | /* |
| 577 | * Reserve usable memory |
| 578 | */ |
| 579 | if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM) |
| 580 | continue; |
| 581 | /* |
| 582 | * We are rounding up the start address of usable memory: |
| 583 | */ |
| 584 | curr_pfn = PFN_UP(bfin_memmap.map[i].addr); |
| 585 | if (curr_pfn >= max_pfn) |
| 586 | continue; |
| 587 | /* |
| 588 | * ... and at the end of the usable range downwards: |
| 589 | */ |
| 590 | last_pfn = PFN_DOWN(bfin_memmap.map[i].addr + |
| 591 | bfin_memmap.map[i].size); |
| 592 | |
| 593 | if (last_pfn > max_pfn) |
| 594 | last_pfn = max_pfn; |
| 595 | |
| 596 | /* |
| 597 | * .. finally, did all the rounding and playing |
| 598 | * around just make the area go away? |
| 599 | */ |
| 600 | if (last_pfn <= curr_pfn) |
| 601 | continue; |
| 602 | |
| 603 | size = last_pfn - curr_pfn; |
| 604 | free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size)); |
| 605 | } |
| 606 | |
| 607 | /* reserve memory before memory_start, including bootmap */ |
| 608 | reserve_bootmem(PAGE_OFFSET, |
| 609 | memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET, |
| 610 | BOOTMEM_DEFAULT); |
| 611 | } |
| 612 | |
| 613 | void __init setup_arch(char **cmdline_p) |
| 614 | { |
| 615 | unsigned long l1_length, sclk, cclk; |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 616 | |
| 617 | #ifdef CONFIG_DUMMY_CONSOLE |
| 618 | conswitchp = &dummy_con; |
| 619 | #endif |
| 620 | |
| 621 | #if defined(CONFIG_CMDLINE_BOOL) |
| 622 | strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line)); |
| 623 | command_line[sizeof(command_line) - 1] = 0; |
| 624 | #endif |
| 625 | |
| 626 | /* Keep a copy of command line */ |
| 627 | *cmdline_p = &command_line[0]; |
| 628 | memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE); |
| 629 | boot_command_line[COMMAND_LINE_SIZE - 1] = '\0'; |
| 630 | |
| 631 | /* setup memory defaults from the user config */ |
| 632 | physical_mem_end = 0; |
| 633 | _ramend = CONFIG_MEM_SIZE * 1024 * 1024; |
| 634 | |
| 635 | memset(&bfin_memmap, 0, sizeof(bfin_memmap)); |
| 636 | |
| 637 | parse_cmdline_early(&command_line[0]); |
| 638 | |
| 639 | if (physical_mem_end == 0) |
| 640 | physical_mem_end = _ramend; |
| 641 | |
| 642 | memory_setup(); |
| 643 | |
| 644 | cclk = get_cclk(); |
| 645 | sclk = get_sclk(); |
| 646 | |
| 647 | #if !defined(CONFIG_BFIN_KERNEL_CLOCK) |
| 648 | if (ANOMALY_05000273 && cclk == sclk) |
| 649 | panic("ANOMALY 05000273, SCLK can not be same as CCLK"); |
| 650 | #endif |
| 651 | |
| 652 | #ifdef BF561_FAMILY |
| 653 | if (ANOMALY_05000266) { |
| 654 | bfin_read_IMDMA_D0_IRQ_STATUS(); |
| 655 | bfin_read_IMDMA_D1_IRQ_STATUS(); |
| 656 | } |
| 657 | #endif |
| 658 | printk(KERN_INFO "Hardware Trace "); |
| 659 | if (bfin_read_TBUFCTL() & 0x1) |
| 660 | printk("Active "); |
| 661 | else |
| 662 | printk("Off "); |
| 663 | if (bfin_read_TBUFCTL() & 0x2) |
| 664 | printk("and Enabled\n"); |
| 665 | else |
| 666 | printk("and Disabled\n"); |
| 667 | |
| 668 | #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH) |
| 669 | /* we need to initialize the Flashrom device here since we might |
| 670 | * do things with flash early on in the boot |
| 671 | */ |
| 672 | flash_probe(); |
| 673 | #endif |
| 674 | |
Robin Getz | 7728ec3 | 2007-10-29 18:12:15 +0800 | [diff] [blame] | 675 | _bfin_swrst = bfin_read_SWRST(); |
| 676 | |
| 677 | if (_bfin_swrst & RESET_DOUBLE) |
| 678 | printk(KERN_INFO "Recovering from Double Fault event\n"); |
| 679 | else if (_bfin_swrst & RESET_WDOG) |
| 680 | printk(KERN_INFO "Recovering from Watchdog event\n"); |
| 681 | else if (_bfin_swrst & RESET_SOFTWARE) |
| 682 | printk(KERN_NOTICE "Reset caused by Software reset\n"); |
| 683 | |
Mike Frysinger | 550d553 | 2008-02-02 15:55:37 +0800 | [diff] [blame] | 684 | printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n"); |
Jie Zhang | de3025f | 2007-06-25 18:04:12 +0800 | [diff] [blame] | 685 | if (bfin_compiled_revid() == 0xffff) |
| 686 | printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU); |
| 687 | else if (bfin_compiled_revid() == -1) |
| 688 | printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU); |
| 689 | else |
| 690 | printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid()); |
| 691 | if (bfin_revid() != bfin_compiled_revid()) { |
| 692 | if (bfin_compiled_revid() == -1) |
| 693 | printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n", |
| 694 | bfin_revid()); |
| 695 | else if (bfin_compiled_revid() != 0xffff) |
| 696 | printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n", |
| 697 | bfin_compiled_revid(), bfin_revid()); |
| 698 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 699 | if (bfin_revid() < SUPPORTED_REVID) |
| 700 | printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n", |
| 701 | CPU, bfin_revid()); |
| 702 | printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n"); |
| 703 | |
Mike Frysinger | b5c0e2e | 2007-09-12 17:31:59 +0800 | [diff] [blame] | 704 | printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n", |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 705 | cclk / 1000000, sclk / 1000000); |
| 706 | |
Mike Frysinger | 1aafd90 | 2007-07-25 11:19:14 +0800 | [diff] [blame] | 707 | if (ANOMALY_05000273 && (cclk >> 1) <= sclk) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 708 | printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 709 | |
Yi Li | 856783b | 2008-02-09 02:26:01 +0800 | [diff] [blame] | 710 | setup_bootmem_allocator(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 711 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 712 | paging_init(); |
| 713 | |
| 714 | /* check the size of the l1 area */ |
| 715 | l1_length = _etext_l1 - _stext_l1; |
| 716 | if (l1_length > L1_CODE_LENGTH) |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 717 | panic("L1 code memory overflow\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 718 | |
| 719 | l1_length = _ebss_l1 - _sdata_l1; |
| 720 | if (l1_length > L1_DATA_A_LENGTH) |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 721 | panic("L1 data memory overflow\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 722 | |
Bernd Schmidt | 7adfb58 | 2007-06-21 11:34:16 +0800 | [diff] [blame] | 723 | /* Copy atomic sequences to their fixed location, and sanity check that |
| 724 | these locations are the ones that we advertise to userspace. */ |
| 725 | memcpy((void *)FIXED_CODE_START, &fixed_code_start, |
| 726 | FIXED_CODE_END - FIXED_CODE_START); |
| 727 | BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start |
| 728 | != SIGRETURN_STUB - FIXED_CODE_START); |
| 729 | BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start |
| 730 | != ATOMIC_XCHG32 - FIXED_CODE_START); |
| 731 | BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start |
| 732 | != ATOMIC_CAS32 - FIXED_CODE_START); |
| 733 | BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start |
| 734 | != ATOMIC_ADD32 - FIXED_CODE_START); |
| 735 | BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start |
| 736 | != ATOMIC_SUB32 - FIXED_CODE_START); |
| 737 | BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start |
| 738 | != ATOMIC_IOR32 - FIXED_CODE_START); |
| 739 | BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start |
| 740 | != ATOMIC_AND32 - FIXED_CODE_START); |
| 741 | BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start |
| 742 | != ATOMIC_XOR32 - FIXED_CODE_START); |
Robin Getz | 9f336a5 | 2007-10-29 18:23:28 +0800 | [diff] [blame] | 743 | BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start |
| 744 | != SAFE_USER_INSTRUCTION - FIXED_CODE_START); |
Bernd Schmidt | 29440a2 | 2007-07-12 16:25:29 +0800 | [diff] [blame] | 745 | |
Bernd Schmidt | 8be80ed | 2007-07-25 14:44:49 +0800 | [diff] [blame] | 746 | init_exception_vectors(); |
Bernd Schmidt | 29440a2 | 2007-07-12 16:25:29 +0800 | [diff] [blame] | 747 | bf53x_cache_init(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 750 | static int __init topology_init(void) |
| 751 | { |
Michael Hennerich | 6cda2e9 | 2008-02-02 15:10:51 +0800 | [diff] [blame] | 752 | int cpu; |
| 753 | |
| 754 | for_each_possible_cpu(cpu) { |
| 755 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 756 | |
| 757 | register_cpu(c, cpu); |
| 758 | } |
| 759 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 760 | return 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | subsys_initcall(topology_init); |
| 764 | |
Mike Frysinger | 52a0781 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 765 | static u_long get_vco(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 766 | { |
| 767 | u_long msel; |
| 768 | u_long vco; |
| 769 | |
| 770 | msel = (bfin_read_PLL_CTL() >> 9) & 0x3F; |
| 771 | if (0 == msel) |
| 772 | msel = 64; |
| 773 | |
| 774 | vco = CONFIG_CLKIN_HZ; |
| 775 | vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */ |
| 776 | vco = msel * vco; |
| 777 | return vco; |
| 778 | } |
| 779 | |
Mike Frysinger | 2f6cf7bf | 2007-10-21 22:59:49 +0800 | [diff] [blame] | 780 | /* Get the Core clock */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 781 | u_long get_cclk(void) |
| 782 | { |
| 783 | u_long csel, ssel; |
| 784 | if (bfin_read_PLL_STAT() & 0x1) |
| 785 | return CONFIG_CLKIN_HZ; |
| 786 | |
| 787 | ssel = bfin_read_PLL_DIV(); |
| 788 | csel = ((ssel >> 4) & 0x03); |
| 789 | ssel &= 0xf; |
| 790 | if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */ |
| 791 | return get_vco() / ssel; |
| 792 | return get_vco() >> csel; |
| 793 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 794 | EXPORT_SYMBOL(get_cclk); |
| 795 | |
| 796 | /* Get the System clock */ |
| 797 | u_long get_sclk(void) |
| 798 | { |
| 799 | u_long ssel; |
| 800 | |
| 801 | if (bfin_read_PLL_STAT() & 0x1) |
| 802 | return CONFIG_CLKIN_HZ; |
| 803 | |
| 804 | ssel = (bfin_read_PLL_DIV() & 0xf); |
| 805 | if (0 == ssel) { |
| 806 | printk(KERN_WARNING "Invalid System Clock\n"); |
| 807 | ssel = 1; |
| 808 | } |
| 809 | |
| 810 | return get_vco() / ssel; |
| 811 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 812 | EXPORT_SYMBOL(get_sclk); |
| 813 | |
Mike Frysinger | 2f6cf7bf | 2007-10-21 22:59:49 +0800 | [diff] [blame] | 814 | unsigned long sclk_to_usecs(unsigned long sclk) |
| 815 | { |
Mike Frysinger | 1754a5d | 2007-11-23 11:28:11 +0800 | [diff] [blame] | 816 | u64 tmp = USEC_PER_SEC * (u64)sclk; |
| 817 | do_div(tmp, get_sclk()); |
| 818 | return tmp; |
Mike Frysinger | 2f6cf7bf | 2007-10-21 22:59:49 +0800 | [diff] [blame] | 819 | } |
| 820 | EXPORT_SYMBOL(sclk_to_usecs); |
| 821 | |
| 822 | unsigned long usecs_to_sclk(unsigned long usecs) |
| 823 | { |
Mike Frysinger | 1754a5d | 2007-11-23 11:28:11 +0800 | [diff] [blame] | 824 | u64 tmp = get_sclk() * (u64)usecs; |
| 825 | do_div(tmp, USEC_PER_SEC); |
| 826 | return tmp; |
Mike Frysinger | 2f6cf7bf | 2007-10-21 22:59:49 +0800 | [diff] [blame] | 827 | } |
| 828 | EXPORT_SYMBOL(usecs_to_sclk); |
| 829 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 830 | /* |
| 831 | * Get CPU information for use by the procfs. |
| 832 | */ |
| 833 | static int show_cpuinfo(struct seq_file *m, void *v) |
| 834 | { |
Mike Frysinger | 066954a | 2007-10-21 22:36:06 +0800 | [diff] [blame] | 835 | char *cpu, *mmu, *fpu, *vendor, *cache; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 836 | uint32_t revid; |
| 837 | |
| 838 | u_long cclk = 0, sclk = 0; |
| 839 | u_int dcache_size = 0, dsup_banks = 0; |
| 840 | |
| 841 | cpu = CPU; |
| 842 | mmu = "none"; |
| 843 | fpu = "none"; |
| 844 | revid = bfin_revid(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 845 | |
| 846 | cclk = get_cclk(); |
| 847 | sclk = get_sclk(); |
| 848 | |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 849 | switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) { |
Mike Frysinger | 066954a | 2007-10-21 22:36:06 +0800 | [diff] [blame] | 850 | case 0xca: |
| 851 | vendor = "Analog Devices"; |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 852 | break; |
| 853 | default: |
Mike Frysinger | 066954a | 2007-10-21 22:36:06 +0800 | [diff] [blame] | 854 | vendor = "unknown"; |
| 855 | break; |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 856 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 857 | |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 858 | seq_printf(m, "processor\t: %d\n" |
| 859 | "vendor_id\t: %s\n" |
| 860 | "cpu family\t: 0x%x\n" |
| 861 | "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n" |
| 862 | "stepping\t: %d\n", |
| 863 | 0, |
| 864 | vendor, |
| 865 | (bfin_read_CHIPID() & CHIPID_FAMILY), |
| 866 | cpu, cclk/1000000, sclk/1000000, |
| 867 | revid); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 868 | |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 869 | seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n", |
| 870 | cclk/1000000, cclk%1000000, |
| 871 | sclk/1000000, sclk%1000000); |
| 872 | seq_printf(m, "bogomips\t: %lu.%02lu\n" |
| 873 | "Calibration\t: %lu loops\n", |
| 874 | (loops_per_jiffy * HZ) / 500000, |
| 875 | ((loops_per_jiffy * HZ) / 5000) % 100, |
| 876 | (loops_per_jiffy * HZ)); |
| 877 | |
| 878 | /* Check Cache configutation */ |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 879 | switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) { |
| 880 | case ACACHE_BSRAM: |
Mike Frysinger | 066954a | 2007-10-21 22:36:06 +0800 | [diff] [blame] | 881 | cache = "dbank-A/B\t: cache/sram"; |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 882 | dcache_size = 16; |
| 883 | dsup_banks = 1; |
| 884 | break; |
| 885 | case ACACHE_BCACHE: |
Mike Frysinger | 066954a | 2007-10-21 22:36:06 +0800 | [diff] [blame] | 886 | cache = "dbank-A/B\t: cache/cache"; |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 887 | dcache_size = 32; |
| 888 | dsup_banks = 2; |
| 889 | break; |
| 890 | case ASRAM_BSRAM: |
Mike Frysinger | 066954a | 2007-10-21 22:36:06 +0800 | [diff] [blame] | 891 | cache = "dbank-A/B\t: sram/sram"; |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 892 | dcache_size = 0; |
| 893 | dsup_banks = 0; |
| 894 | break; |
| 895 | default: |
Mike Frysinger | 066954a | 2007-10-21 22:36:06 +0800 | [diff] [blame] | 896 | cache = "unknown"; |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 897 | dcache_size = 0; |
| 898 | dsup_banks = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 899 | break; |
| 900 | } |
| 901 | |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 902 | /* Is it turned on? */ |
| 903 | if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE))) |
| 904 | dcache_size = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 905 | |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 906 | seq_printf(m, "cache size\t: %d KB(L1 icache) " |
| 907 | "%d KB(L1 dcache-%s) %d KB(L2 cache)\n", |
| 908 | BFIN_ICACHESIZE / 1024, dcache_size, |
| 909 | #if defined CONFIG_BFIN_WB |
| 910 | "wb" |
| 911 | #elif defined CONFIG_BFIN_WT |
| 912 | "wt" |
| 913 | #endif |
Mike Frysinger | da27abb | 2007-10-22 10:55:35 +0800 | [diff] [blame] | 914 | "", 0); |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 915 | |
| 916 | seq_printf(m, "%s\n", cache); |
| 917 | |
| 918 | seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n", |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 919 | BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 920 | seq_printf(m, |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 921 | "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n", |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 922 | dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS, |
| 923 | BFIN_DLINES); |
| 924 | #ifdef CONFIG_BFIN_ICACHE_LOCK |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 925 | switch (read_iloc()) { |
| 926 | case WAY0_L: |
| 927 | seq_printf(m, "Way0 Locked-Down\n"); |
| 928 | break; |
| 929 | case WAY1_L: |
| 930 | seq_printf(m, "Way1 Locked-Down\n"); |
| 931 | break; |
| 932 | case WAY01_L: |
| 933 | seq_printf(m, "Way0,Way1 Locked-Down\n"); |
| 934 | break; |
| 935 | case WAY2_L: |
| 936 | seq_printf(m, "Way2 Locked-Down\n"); |
| 937 | break; |
| 938 | case WAY02_L: |
| 939 | seq_printf(m, "Way0,Way2 Locked-Down\n"); |
| 940 | break; |
| 941 | case WAY12_L: |
| 942 | seq_printf(m, "Way1,Way2 Locked-Down\n"); |
| 943 | break; |
| 944 | case WAY012_L: |
| 945 | seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n"); |
| 946 | break; |
| 947 | case WAY3_L: |
| 948 | seq_printf(m, "Way3 Locked-Down\n"); |
| 949 | break; |
| 950 | case WAY03_L: |
| 951 | seq_printf(m, "Way0,Way3 Locked-Down\n"); |
| 952 | break; |
| 953 | case WAY13_L: |
| 954 | seq_printf(m, "Way1,Way3 Locked-Down\n"); |
| 955 | break; |
| 956 | case WAY013_L: |
| 957 | seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n"); |
| 958 | break; |
| 959 | case WAY32_L: |
| 960 | seq_printf(m, "Way3,Way2 Locked-Down\n"); |
| 961 | break; |
| 962 | case WAY320_L: |
| 963 | seq_printf(m, "Way3,Way2,Way0 Locked-Down\n"); |
| 964 | break; |
| 965 | case WAY321_L: |
| 966 | seq_printf(m, "Way3,Way2,Way1 Locked-Down\n"); |
| 967 | break; |
| 968 | case WAYALL_L: |
| 969 | seq_printf(m, "All Ways are locked\n"); |
| 970 | break; |
| 971 | default: |
| 972 | seq_printf(m, "No Ways are locked\n"); |
| 973 | } |
| 974 | #endif |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 975 | |
Mike Frysinger | 066954a | 2007-10-21 22:36:06 +0800 | [diff] [blame] | 976 | seq_printf(m, "board name\t: %s\n", bfin_board_name); |
Robin Getz | 73b0c0b | 2007-10-21 17:03:31 +0800 | [diff] [blame] | 977 | seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n", |
| 978 | physical_mem_end >> 10, (void *)0, (void *)physical_mem_end); |
| 979 | seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n", |
| 980 | ((int)memory_end - (int)_stext) >> 10, |
| 981 | _stext, |
| 982 | (void *)memory_end); |
| 983 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | static void *c_start(struct seq_file *m, loff_t *pos) |
| 988 | { |
| 989 | return *pos < NR_CPUS ? ((void *)0x12345678) : NULL; |
| 990 | } |
| 991 | |
| 992 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) |
| 993 | { |
| 994 | ++*pos; |
| 995 | return c_start(m, pos); |
| 996 | } |
| 997 | |
| 998 | static void c_stop(struct seq_file *m, void *v) |
| 999 | { |
| 1000 | } |
| 1001 | |
Jan Engelhardt | 03a4482 | 2008-02-08 04:21:19 -0800 | [diff] [blame] | 1002 | const struct seq_operations cpuinfo_op = { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1003 | .start = c_start, |
| 1004 | .next = c_next, |
| 1005 | .stop = c_stop, |
| 1006 | .show = show_cpuinfo, |
| 1007 | }; |
| 1008 | |
Mike Frysinger | 5e10b4a | 2007-06-11 16:44:09 +0800 | [diff] [blame] | 1009 | void __init cmdline_init(const char *r0) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1010 | { |
| 1011 | if (r0) |
Mike Frysinger | 52a0781 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 1012 | strncpy(command_line, r0, COMMAND_LINE_SIZE); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1013 | } |