diff options
Diffstat (limited to 'arch/xtensa/kernel/setup.c')
| -rw-r--r-- | arch/xtensa/kernel/setup.c | 279 |
1 files changed, 247 insertions, 32 deletions
diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c index b237988ba6d7..24c1a57abb40 100644 --- a/arch/xtensa/kernel/setup.c +++ b/arch/xtensa/kernel/setup.c | |||
| @@ -22,6 +22,11 @@ | |||
| 22 | #include <linux/bootmem.h> | 22 | #include <linux/bootmem.h> |
| 23 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
| 24 | 24 | ||
| 25 | #ifdef CONFIG_OF | ||
| 26 | #include <linux/of_fdt.h> | ||
| 27 | #include <linux/of_platform.h> | ||
| 28 | #endif | ||
| 29 | |||
| 25 | #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE) | 30 | #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE) |
| 26 | # include <linux/console.h> | 31 | # include <linux/console.h> |
| 27 | #endif | 32 | #endif |
| @@ -42,6 +47,7 @@ | |||
| 42 | #include <asm/page.h> | 47 | #include <asm/page.h> |
| 43 | #include <asm/setup.h> | 48 | #include <asm/setup.h> |
| 44 | #include <asm/param.h> | 49 | #include <asm/param.h> |
| 50 | #include <asm/traps.h> | ||
| 45 | 51 | ||
| 46 | #include <platform/hardware.h> | 52 | #include <platform/hardware.h> |
| 47 | 53 | ||
| @@ -64,6 +70,11 @@ int initrd_is_mapped = 0; | |||
| 64 | extern int initrd_below_start_ok; | 70 | extern int initrd_below_start_ok; |
| 65 | #endif | 71 | #endif |
| 66 | 72 | ||
| 73 | #ifdef CONFIG_OF | ||
| 74 | extern u32 __dtb_start[]; | ||
| 75 | void *dtb_start = __dtb_start; | ||
| 76 | #endif | ||
| 77 | |||
| 67 | unsigned char aux_device_present; | 78 | unsigned char aux_device_present; |
| 68 | extern unsigned long loops_per_jiffy; | 79 | extern unsigned long loops_per_jiffy; |
| 69 | 80 | ||
| @@ -83,6 +94,8 @@ extern void init_mmu(void); | |||
| 83 | static inline void init_mmu(void) { } | 94 | static inline void init_mmu(void) { } |
| 84 | #endif | 95 | #endif |
| 85 | 96 | ||
| 97 | extern int mem_reserve(unsigned long, unsigned long, int); | ||
| 98 | extern void bootmem_init(void); | ||
| 86 | extern void zones_init(void); | 99 | extern void zones_init(void); |
| 87 | 100 | ||
| 88 | /* | 101 | /* |
| @@ -104,28 +117,33 @@ typedef struct tagtable { | |||
| 104 | 117 | ||
| 105 | /* parse current tag */ | 118 | /* parse current tag */ |
| 106 | 119 | ||
| 107 | static int __init parse_tag_mem(const bp_tag_t *tag) | 120 | static int __init add_sysmem_bank(unsigned long type, unsigned long start, |
| 121 | unsigned long end) | ||
| 108 | { | 122 | { |
| 109 | meminfo_t *mi = (meminfo_t*)(tag->data); | ||
| 110 | |||
| 111 | if (mi->type != MEMORY_TYPE_CONVENTIONAL) | ||
| 112 | return -1; | ||
| 113 | |||
| 114 | if (sysmem.nr_banks >= SYSMEM_BANKS_MAX) { | 123 | if (sysmem.nr_banks >= SYSMEM_BANKS_MAX) { |
| 115 | printk(KERN_WARNING | 124 | printk(KERN_WARNING |
| 116 | "Ignoring memory bank 0x%08lx size %ldKB\n", | 125 | "Ignoring memory bank 0x%08lx size %ldKB\n", |
| 117 | (unsigned long)mi->start, | 126 | start, end - start); |
| 118 | (unsigned long)mi->end - (unsigned long)mi->start); | ||
| 119 | return -EINVAL; | 127 | return -EINVAL; |
| 120 | } | 128 | } |
| 121 | sysmem.bank[sysmem.nr_banks].type = mi->type; | 129 | sysmem.bank[sysmem.nr_banks].type = type; |
| 122 | sysmem.bank[sysmem.nr_banks].start = PAGE_ALIGN(mi->start); | 130 | sysmem.bank[sysmem.nr_banks].start = PAGE_ALIGN(start); |
| 123 | sysmem.bank[sysmem.nr_banks].end = mi->end & PAGE_MASK; | 131 | sysmem.bank[sysmem.nr_banks].end = end & PAGE_MASK; |
| 124 | sysmem.nr_banks++; | 132 | sysmem.nr_banks++; |
| 125 | 133 | ||
| 126 | return 0; | 134 | return 0; |
| 127 | } | 135 | } |
| 128 | 136 | ||
| 137 | static int __init parse_tag_mem(const bp_tag_t *tag) | ||
| 138 | { | ||
| 139 | meminfo_t *mi = (meminfo_t *)(tag->data); | ||
| 140 | |||
| 141 | if (mi->type != MEMORY_TYPE_CONVENTIONAL) | ||
| 142 | return -1; | ||
| 143 | |||
| 144 | return add_sysmem_bank(mi->type, mi->start, mi->end); | ||
| 145 | } | ||
| 146 | |||
| 129 | __tagtable(BP_TAG_MEMORY, parse_tag_mem); | 147 | __tagtable(BP_TAG_MEMORY, parse_tag_mem); |
| 130 | 148 | ||
| 131 | #ifdef CONFIG_BLK_DEV_INITRD | 149 | #ifdef CONFIG_BLK_DEV_INITRD |
| @@ -142,12 +160,31 @@ static int __init parse_tag_initrd(const bp_tag_t* tag) | |||
| 142 | 160 | ||
| 143 | __tagtable(BP_TAG_INITRD, parse_tag_initrd); | 161 | __tagtable(BP_TAG_INITRD, parse_tag_initrd); |
| 144 | 162 | ||
| 163 | #ifdef CONFIG_OF | ||
| 164 | |||
| 165 | static int __init parse_tag_fdt(const bp_tag_t *tag) | ||
| 166 | { | ||
| 167 | dtb_start = (void *)(tag->data[0]); | ||
| 168 | return 0; | ||
| 169 | } | ||
| 170 | |||
| 171 | __tagtable(BP_TAG_FDT, parse_tag_fdt); | ||
| 172 | |||
| 173 | void __init early_init_dt_setup_initrd_arch(unsigned long start, | ||
| 174 | unsigned long end) | ||
| 175 | { | ||
| 176 | initrd_start = (void *)__va(start); | ||
| 177 | initrd_end = (void *)__va(end); | ||
| 178 | initrd_below_start_ok = 1; | ||
| 179 | } | ||
| 180 | |||
| 181 | #endif /* CONFIG_OF */ | ||
| 182 | |||
| 145 | #endif /* CONFIG_BLK_DEV_INITRD */ | 183 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 146 | 184 | ||
| 147 | static int __init parse_tag_cmdline(const bp_tag_t* tag) | 185 | static int __init parse_tag_cmdline(const bp_tag_t* tag) |
| 148 | { | 186 | { |
| 149 | strncpy(command_line, (char*)(tag->data), COMMAND_LINE_SIZE); | 187 | strlcpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE); |
| 150 | command_line[COMMAND_LINE_SIZE - 1] = '\0'; | ||
| 151 | return 0; | 188 | return 0; |
| 152 | } | 189 | } |
| 153 | 190 | ||
| @@ -185,6 +222,58 @@ static int __init parse_bootparam(const bp_tag_t* tag) | |||
| 185 | return 0; | 222 | return 0; |
| 186 | } | 223 | } |
| 187 | 224 | ||
| 225 | #ifdef CONFIG_OF | ||
| 226 | |||
| 227 | void __init early_init_dt_add_memory_arch(u64 base, u64 size) | ||
| 228 | { | ||
| 229 | size &= PAGE_MASK; | ||
| 230 | add_sysmem_bank(MEMORY_TYPE_CONVENTIONAL, base, base + size); | ||
| 231 | } | ||
| 232 | |||
| 233 | void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align) | ||
| 234 | { | ||
| 235 | return __alloc_bootmem(size, align, 0); | ||
| 236 | } | ||
| 237 | |||
| 238 | void __init early_init_devtree(void *params) | ||
| 239 | { | ||
| 240 | /* Setup flat device-tree pointer */ | ||
| 241 | initial_boot_params = params; | ||
| 242 | |||
| 243 | /* Retrieve various informations from the /chosen node of the | ||
| 244 | * device-tree, including the platform type, initrd location and | ||
| 245 | * size, TCE reserve, and more ... | ||
| 246 | */ | ||
| 247 | if (!command_line[0]) | ||
| 248 | of_scan_flat_dt(early_init_dt_scan_chosen, command_line); | ||
| 249 | |||
| 250 | /* Scan memory nodes and rebuild MEMBLOCKs */ | ||
| 251 | of_scan_flat_dt(early_init_dt_scan_root, NULL); | ||
| 252 | if (sysmem.nr_banks == 0) | ||
| 253 | of_scan_flat_dt(early_init_dt_scan_memory, NULL); | ||
| 254 | } | ||
| 255 | |||
| 256 | static void __init copy_devtree(void) | ||
| 257 | { | ||
| 258 | void *alloc = early_init_dt_alloc_memory_arch( | ||
| 259 | be32_to_cpu(initial_boot_params->totalsize), 0); | ||
| 260 | if (alloc) { | ||
| 261 | memcpy(alloc, initial_boot_params, | ||
| 262 | be32_to_cpu(initial_boot_params->totalsize)); | ||
| 263 | initial_boot_params = alloc; | ||
| 264 | } | ||
| 265 | } | ||
| 266 | |||
| 267 | static int __init xtensa_device_probe(void) | ||
| 268 | { | ||
| 269 | of_platform_populate(NULL, NULL, NULL, NULL); | ||
| 270 | return 0; | ||
| 271 | } | ||
| 272 | |||
| 273 | device_initcall(xtensa_device_probe); | ||
| 274 | |||
| 275 | #endif /* CONFIG_OF */ | ||
| 276 | |||
| 188 | /* | 277 | /* |
| 189 | * Initialize architecture. (Early stage) | 278 | * Initialize architecture. (Early stage) |
| 190 | */ | 279 | */ |
| @@ -193,14 +282,14 @@ void __init init_arch(bp_tag_t *bp_start) | |||
| 193 | { | 282 | { |
| 194 | sysmem.nr_banks = 0; | 283 | sysmem.nr_banks = 0; |
| 195 | 284 | ||
| 196 | #ifdef CONFIG_CMDLINE_BOOL | ||
| 197 | strcpy(command_line, default_command_line); | ||
| 198 | #endif | ||
| 199 | |||
| 200 | /* Parse boot parameters */ | 285 | /* Parse boot parameters */ |
| 201 | 286 | ||
| 202 | if (bp_start) | 287 | if (bp_start) |
| 203 | parse_bootparam(bp_start); | 288 | parse_bootparam(bp_start); |
| 289 | |||
| 290 | #ifdef CONFIG_OF | ||
| 291 | early_init_devtree(dtb_start); | ||
| 292 | #endif | ||
| 204 | 293 | ||
| 205 | if (sysmem.nr_banks == 0) { | 294 | if (sysmem.nr_banks == 0) { |
| 206 | sysmem.nr_banks = 1; | 295 | sysmem.nr_banks = 1; |
| @@ -209,6 +298,11 @@ void __init init_arch(bp_tag_t *bp_start) | |||
| 209 | + PLATFORM_DEFAULT_MEM_SIZE; | 298 | + PLATFORM_DEFAULT_MEM_SIZE; |
| 210 | } | 299 | } |
| 211 | 300 | ||
| 301 | #ifdef CONFIG_CMDLINE_BOOL | ||
| 302 | if (!command_line[0]) | ||
| 303 | strlcpy(command_line, default_command_line, COMMAND_LINE_SIZE); | ||
| 304 | #endif | ||
| 305 | |||
| 212 | /* Early hook for platforms */ | 306 | /* Early hook for platforms */ |
| 213 | 307 | ||
| 214 | platform_init(bp_start); | 308 | platform_init(bp_start); |
| @@ -235,15 +329,130 @@ extern char _UserExceptionVector_text_end; | |||
| 235 | extern char _DoubleExceptionVector_literal_start; | 329 | extern char _DoubleExceptionVector_literal_start; |
| 236 | extern char _DoubleExceptionVector_text_end; | 330 | extern char _DoubleExceptionVector_text_end; |
| 237 | 331 | ||
| 238 | void __init setup_arch(char **cmdline_p) | 332 | |
| 333 | #ifdef CONFIG_S32C1I_SELFTEST | ||
| 334 | #if XCHAL_HAVE_S32C1I | ||
| 335 | |||
| 336 | static int __initdata rcw_word, rcw_probe_pc, rcw_exc; | ||
| 337 | |||
| 338 | /* | ||
| 339 | * Basic atomic compare-and-swap, that records PC of S32C1I for probing. | ||
| 340 | * | ||
| 341 | * If *v == cmp, set *v = set. Return previous *v. | ||
| 342 | */ | ||
| 343 | static inline int probed_compare_swap(int *v, int cmp, int set) | ||
| 344 | { | ||
| 345 | int tmp; | ||
| 346 | |||
| 347 | __asm__ __volatile__( | ||
| 348 | " movi %1, 1f\n" | ||
| 349 | " s32i %1, %4, 0\n" | ||
| 350 | " wsr %2, scompare1\n" | ||
| 351 | "1: s32c1i %0, %3, 0\n" | ||
| 352 | : "=a" (set), "=&a" (tmp) | ||
| 353 | : "a" (cmp), "a" (v), "a" (&rcw_probe_pc), "0" (set) | ||
| 354 | : "memory" | ||
| 355 | ); | ||
| 356 | return set; | ||
| 357 | } | ||
| 358 | |||
| 359 | /* Handle probed exception */ | ||
| 360 | |||
| 361 | void __init do_probed_exception(struct pt_regs *regs, unsigned long exccause) | ||
| 362 | { | ||
| 363 | if (regs->pc == rcw_probe_pc) { /* exception on s32c1i ? */ | ||
| 364 | regs->pc += 3; /* skip the s32c1i instruction */ | ||
| 365 | rcw_exc = exccause; | ||
| 366 | } else { | ||
| 367 | do_unhandled(regs, exccause); | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | /* Simple test of S32C1I (soc bringup assist) */ | ||
| 372 | |||
| 373 | void __init check_s32c1i(void) | ||
| 374 | { | ||
| 375 | int n, cause1, cause2; | ||
| 376 | void *handbus, *handdata, *handaddr; /* temporarily saved handlers */ | ||
| 377 | |||
| 378 | rcw_probe_pc = 0; | ||
| 379 | handbus = trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR, | ||
| 380 | do_probed_exception); | ||
| 381 | handdata = trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR, | ||
| 382 | do_probed_exception); | ||
| 383 | handaddr = trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR, | ||
| 384 | do_probed_exception); | ||
| 385 | |||
| 386 | /* First try an S32C1I that does not store: */ | ||
| 387 | rcw_exc = 0; | ||
| 388 | rcw_word = 1; | ||
| 389 | n = probed_compare_swap(&rcw_word, 0, 2); | ||
| 390 | cause1 = rcw_exc; | ||
| 391 | |||
| 392 | /* took exception? */ | ||
| 393 | if (cause1 != 0) { | ||
| 394 | /* unclean exception? */ | ||
| 395 | if (n != 2 || rcw_word != 1) | ||
| 396 | panic("S32C1I exception error"); | ||
| 397 | } else if (rcw_word != 1 || n != 1) { | ||
| 398 | panic("S32C1I compare error"); | ||
| 399 | } | ||
| 400 | |||
| 401 | /* Then an S32C1I that stores: */ | ||
| 402 | rcw_exc = 0; | ||
| 403 | rcw_word = 0x1234567; | ||
| 404 | n = probed_compare_swap(&rcw_word, 0x1234567, 0xabcde); | ||
| 405 | cause2 = rcw_exc; | ||
| 406 | |||
| 407 | if (cause2 != 0) { | ||
| 408 | /* unclean exception? */ | ||
| 409 | if (n != 0xabcde || rcw_word != 0x1234567) | ||
| 410 | panic("S32C1I exception error (b)"); | ||
| 411 | } else if (rcw_word != 0xabcde || n != 0x1234567) { | ||
| 412 | panic("S32C1I store error"); | ||
| 413 | } | ||
| 414 | |||
| 415 | /* Verify consistency of exceptions: */ | ||
| 416 | if (cause1 || cause2) { | ||
| 417 | pr_warn("S32C1I took exception %d, %d\n", cause1, cause2); | ||
| 418 | /* If emulation of S32C1I upon bus error gets implemented, | ||
| 419 | we can get rid of this panic for single core (not SMP) */ | ||
| 420 | panic("S32C1I exceptions not currently supported"); | ||
| 421 | } | ||
| 422 | if (cause1 != cause2) | ||
| 423 | panic("inconsistent S32C1I exceptions"); | ||
| 424 | |||
| 425 | trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR, handbus); | ||
| 426 | trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR, handdata); | ||
| 427 | trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR, handaddr); | ||
| 428 | } | ||
| 429 | |||
| 430 | #else /* XCHAL_HAVE_S32C1I */ | ||
| 431 | |||
| 432 | /* This condition should not occur with a commercially deployed processor. | ||
| 433 | Display reminder for early engr test or demo chips / FPGA bitstreams */ | ||
| 434 | void __init check_s32c1i(void) | ||
| 435 | { | ||
| 436 | pr_warn("Processor configuration lacks atomic compare-and-swap support!\n"); | ||
| 437 | } | ||
| 438 | |||
| 439 | #endif /* XCHAL_HAVE_S32C1I */ | ||
| 440 | #else /* CONFIG_S32C1I_SELFTEST */ | ||
| 441 | |||
| 442 | void __init check_s32c1i(void) | ||
| 239 | { | 443 | { |
| 240 | extern int mem_reserve(unsigned long, unsigned long, int); | 444 | } |
| 241 | extern void bootmem_init(void); | 445 | |
| 446 | #endif /* CONFIG_S32C1I_SELFTEST */ | ||
| 242 | 447 | ||
| 243 | memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE); | 448 | |
| 244 | boot_command_line[COMMAND_LINE_SIZE-1] = '\0'; | 449 | void __init setup_arch(char **cmdline_p) |
| 450 | { | ||
| 451 | strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE); | ||
| 245 | *cmdline_p = command_line; | 452 | *cmdline_p = command_line; |
| 246 | 453 | ||
| 454 | check_s32c1i(); | ||
| 455 | |||
| 247 | /* Reserve some memory regions */ | 456 | /* Reserve some memory regions */ |
| 248 | 457 | ||
| 249 | #ifdef CONFIG_BLK_DEV_INITRD | 458 | #ifdef CONFIG_BLK_DEV_INITRD |
| @@ -251,7 +460,7 @@ void __init setup_arch(char **cmdline_p) | |||
| 251 | initrd_is_mapped = mem_reserve(__pa(initrd_start), | 460 | initrd_is_mapped = mem_reserve(__pa(initrd_start), |
| 252 | __pa(initrd_end), 0); | 461 | __pa(initrd_end), 0); |
| 253 | initrd_below_start_ok = 1; | 462 | initrd_below_start_ok = 1; |
| 254 | } else { | 463 | } else { |
| 255 | initrd_start = 0; | 464 | initrd_start = 0; |
| 256 | } | 465 | } |
| 257 | #endif | 466 | #endif |
| @@ -275,8 +484,12 @@ void __init setup_arch(char **cmdline_p) | |||
| 275 | 484 | ||
| 276 | bootmem_init(); | 485 | bootmem_init(); |
| 277 | 486 | ||
| 278 | platform_setup(cmdline_p); | 487 | #ifdef CONFIG_OF |
| 488 | copy_devtree(); | ||
| 489 | unflatten_device_tree(); | ||
| 490 | #endif | ||
| 279 | 491 | ||
| 492 | platform_setup(cmdline_p); | ||
| 280 | 493 | ||
| 281 | paging_init(); | 494 | paging_init(); |
| 282 | zones_init(); | 495 | zones_init(); |
| @@ -326,7 +539,7 @@ c_show(struct seq_file *f, void *slot) | |||
| 326 | "core ID\t\t: " XCHAL_CORE_ID "\n" | 539 | "core ID\t\t: " XCHAL_CORE_ID "\n" |
| 327 | "build ID\t: 0x%x\n" | 540 | "build ID\t: 0x%x\n" |
| 328 | "byte order\t: %s\n" | 541 | "byte order\t: %s\n" |
| 329 | "cpu MHz\t\t: %lu.%02lu\n" | 542 | "cpu MHz\t\t: %lu.%02lu\n" |
| 330 | "bogomips\t: %lu.%02lu\n", | 543 | "bogomips\t: %lu.%02lu\n", |
| 331 | XCHAL_BUILD_UNIQUE_ID, | 544 | XCHAL_BUILD_UNIQUE_ID, |
| 332 | XCHAL_HAVE_BE ? "big" : "little", | 545 | XCHAL_HAVE_BE ? "big" : "little", |
| @@ -381,6 +594,9 @@ c_show(struct seq_file *f, void *slot) | |||
| 381 | #if XCHAL_HAVE_FP | 594 | #if XCHAL_HAVE_FP |
| 382 | "fpu " | 595 | "fpu " |
| 383 | #endif | 596 | #endif |
| 597 | #if XCHAL_HAVE_S32C1I | ||
| 598 | "s32c1i " | ||
| 599 | #endif | ||
| 384 | "\n"); | 600 | "\n"); |
| 385 | 601 | ||
| 386 | /* Registers. */ | 602 | /* Registers. */ |
| @@ -412,7 +628,7 @@ c_show(struct seq_file *f, void *slot) | |||
| 412 | "icache size\t: %d\n" | 628 | "icache size\t: %d\n" |
| 413 | "icache flags\t: " | 629 | "icache flags\t: " |
| 414 | #if XCHAL_ICACHE_LINE_LOCKABLE | 630 | #if XCHAL_ICACHE_LINE_LOCKABLE |
| 415 | "lock" | 631 | "lock " |
| 416 | #endif | 632 | #endif |
| 417 | "\n" | 633 | "\n" |
| 418 | "dcache line size: %d\n" | 634 | "dcache line size: %d\n" |
| @@ -420,10 +636,10 @@ c_show(struct seq_file *f, void *slot) | |||
| 420 | "dcache size\t: %d\n" | 636 | "dcache size\t: %d\n" |
| 421 | "dcache flags\t: " | 637 | "dcache flags\t: " |
| 422 | #if XCHAL_DCACHE_IS_WRITEBACK | 638 | #if XCHAL_DCACHE_IS_WRITEBACK |
| 423 | "writeback" | 639 | "writeback " |
| 424 | #endif | 640 | #endif |
| 425 | #if XCHAL_DCACHE_LINE_LOCKABLE | 641 | #if XCHAL_DCACHE_LINE_LOCKABLE |
| 426 | "lock" | 642 | "lock " |
| 427 | #endif | 643 | #endif |
| 428 | "\n", | 644 | "\n", |
| 429 | XCHAL_ICACHE_LINESIZE, | 645 | XCHAL_ICACHE_LINESIZE, |
| @@ -465,4 +681,3 @@ const struct seq_operations cpuinfo_op = | |||
| 465 | }; | 681 | }; |
| 466 | 682 | ||
| 467 | #endif /* CONFIG_PROC_FS */ | 683 | #endif /* CONFIG_PROC_FS */ |
| 468 | |||
