David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2009 Sunplus Core Technology Co., Ltd. |
| 4 | * Chen Liqin <liqin.chen@sunplusct.com> |
| 5 | * Lennox Wu <lennox.wu@sunplusct.com> |
| 6 | * Copyright (C) 2012 Regents of the University of California |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/mm.h> |
| 11 | #include <linux/memblock.h> |
| 12 | #include <linux/sched.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13 | #include <linux/console.h> |
| 14 | #include <linux/screen_info.h> |
| 15 | #include <linux/of_fdt.h> |
| 16 | #include <linux/of_platform.h> |
| 17 | #include <linux/sched/task.h> |
| 18 | #include <linux/swiotlb.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 19 | #include <linux/smp.h> |
| 20 | #include <linux/efi.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 21 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 22 | #include <asm/cpu_ops.h> |
| 23 | #include <asm/early_ioremap.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 24 | #include <asm/setup.h> |
| 25 | #include <asm/sections.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 26 | #include <asm/sbi.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 27 | #include <asm/tlbflush.h> |
| 28 | #include <asm/thread_info.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 29 | #include <asm/kasan.h> |
| 30 | #include <asm/efi.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 31 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 32 | #include "head.h" |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 33 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 34 | #if defined(CONFIG_DUMMY_CONSOLE) || defined(CONFIG_EFI) |
| 35 | struct screen_info screen_info __section(".data") = { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 36 | .orig_video_lines = 30, |
| 37 | .orig_video_cols = 80, |
| 38 | .orig_video_mode = 0, |
| 39 | .orig_video_ega_bx = 0, |
| 40 | .orig_video_isVGA = 1, |
| 41 | .orig_video_points = 8 |
| 42 | }; |
| 43 | #endif |
| 44 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 45 | /* |
| 46 | * The lucky hart to first increment this variable will boot the other cores. |
| 47 | * This is used before the kernel initializes the BSS so it can't be in the |
| 48 | * BSS. |
| 49 | */ |
| 50 | atomic_t hart_lottery __section(".sdata"); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 51 | unsigned long boot_cpu_hartid; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 52 | static DEFINE_PER_CPU(struct cpu, cpu_devices); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 53 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 54 | static void __init parse_dtb(void) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 55 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 56 | /* Early scan of device tree from init memory */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 57 | if (early_init_dt_scan(dtb_early_va)) |
| 58 | return; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 59 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 60 | pr_err("No DTB passed to the kernel\n"); |
| 61 | #ifdef CONFIG_CMDLINE_FORCE |
| 62 | strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); |
| 63 | pr_info("Forcing kernel command line to: %s\n", boot_command_line); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 64 | #endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void __init setup_arch(char **cmdline_p) |
| 68 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 69 | parse_dtb(); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 70 | init_mm.start_code = (unsigned long) _stext; |
| 71 | init_mm.end_code = (unsigned long) _etext; |
| 72 | init_mm.end_data = (unsigned long) _edata; |
| 73 | init_mm.brk = (unsigned long) _end; |
| 74 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 75 | *cmdline_p = boot_command_line; |
| 76 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 77 | early_ioremap_setup(); |
| 78 | jump_label_init(); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 79 | parse_early_param(); |
| 80 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 81 | efi_init(); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 82 | setup_bootmem(); |
| 83 | paging_init(); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 84 | #if IS_ENABLED(CONFIG_BUILTIN_DTB) |
| 85 | unflatten_and_copy_device_tree(); |
| 86 | #else |
| 87 | if (early_init_dt_verify(__va(dtb_early_pa))) |
| 88 | unflatten_device_tree(); |
| 89 | else |
| 90 | pr_err("No DTB found in kernel mappings\n"); |
| 91 | #endif |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 92 | |
| 93 | #ifdef CONFIG_SWIOTLB |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 94 | swiotlb_init(1); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 95 | #endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 96 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 97 | #ifdef CONFIG_KASAN |
| 98 | kasan_init(); |
| 99 | #endif |
| 100 | |
| 101 | #if IS_ENABLED(CONFIG_RISCV_SBI) |
| 102 | sbi_init(); |
| 103 | #endif |
| 104 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 105 | #ifdef CONFIG_SMP |
| 106 | setup_smp(); |
| 107 | #endif |
| 108 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 109 | riscv_fill_hwcap(); |
| 110 | } |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 111 | |
| 112 | static int __init topology_init(void) |
| 113 | { |
| 114 | int i; |
| 115 | |
| 116 | for_each_possible_cpu(i) { |
| 117 | struct cpu *cpu = &per_cpu(cpu_devices, i); |
| 118 | |
| 119 | cpu->hotpluggable = cpu_has_hotplug(i); |
| 120 | register_cpu(cpu, i); |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | subsys_initcall(topology_init); |