Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2 | /* |
| 3 | * Common prep/pmac/chrp boot and setup code. |
| 4 | */ |
| 5 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 6 | #include <linux/module.h> |
| 7 | #include <linux/string.h> |
| 8 | #include <linux/sched.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/reboot.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/initrd.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 14 | #include <linux/tty.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 15 | #include <linux/seq_file.h> |
| 16 | #include <linux/root_dev.h> |
| 17 | #include <linux/cpu.h> |
| 18 | #include <linux/console.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 19 | #include <linux/memblock.h> |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame] | 20 | #include <linux/export.h> |
Finn Thain | a156c7b | 2019-01-15 15:18:56 +1100 | [diff] [blame] | 21 | #include <linux/nvram.h> |
Mike Rapoport | 65fddcf | 2020-06-08 21:32:42 -0700 | [diff] [blame] | 22 | #include <linux/pgtable.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 23 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 24 | #include <asm/io.h> |
| 25 | #include <asm/prom.h> |
| 26 | #include <asm/processor.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 27 | #include <asm/setup.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 28 | #include <asm/smp.h> |
| 29 | #include <asm/elf.h> |
| 30 | #include <asm/cputable.h> |
| 31 | #include <asm/bootx.h> |
| 32 | #include <asm/btext.h> |
| 33 | #include <asm/machdep.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 34 | #include <linux/uaccess.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 35 | #include <asm/pmac_feature.h> |
| 36 | #include <asm/sections.h> |
| 37 | #include <asm/nvram.h> |
| 38 | #include <asm/xmon.h> |
Kumar Gala | 6d7f58b | 2005-10-25 23:57:33 -0500 | [diff] [blame] | 39 | #include <asm/time.h> |
Benjamin Herrenschmidt | 463ce0e | 2005-11-23 17:56:06 +1100 | [diff] [blame] | 40 | #include <asm/serial.h> |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 41 | #include <asm/udbg.h> |
LEROY Christophe | 1cd0389 | 2015-09-16 12:04:51 +0200 | [diff] [blame] | 42 | #include <asm/code-patching.h> |
Kevin Hao | b92a226 | 2016-07-23 14:42:40 +0530 | [diff] [blame] | 43 | #include <asm/cpu_has_feature.h> |
Mathieu Malaterre | e82d70cf9 | 2018-03-08 22:31:59 +1100 | [diff] [blame] | 44 | #include <asm/asm-prototypes.h> |
Christophe Leroy | db0a2b6 | 2018-07-05 16:24:51 +0000 | [diff] [blame] | 45 | #include <asm/kdump.h> |
Christophe Leroy | 2c86cd1 | 2018-07-05 16:25:01 +0000 | [diff] [blame] | 46 | #include <asm/feature-fixups.h> |
Christophe Leroy | 265c349 | 2019-09-12 13:49:43 +0000 | [diff] [blame] | 47 | #include <asm/early_ioremap.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 48 | |
Mathieu Malaterre | f2c6d0d | 2018-06-22 21:26:53 +0200 | [diff] [blame] | 49 | #include "setup.h" |
| 50 | |
Paul Mackerras | 03501da | 2005-10-26 17:11:18 +1000 | [diff] [blame] | 51 | #define DBG(fmt...) |
| 52 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 53 | extern void bootx_init(unsigned long r4, unsigned long phys); |
| 54 | |
Paul Mackerras | 80579e1 | 2005-10-27 22:42:04 +1000 | [diff] [blame] | 55 | int boot_cpuid_phys; |
Andrew Gabbasov | 9974eec | 2011-07-16 03:22:13 +0000 | [diff] [blame] | 56 | EXPORT_SYMBOL_GPL(boot_cpuid_phys); |
Paul Mackerras | 80579e1 | 2005-10-27 22:42:04 +1000 | [diff] [blame] | 57 | |
Nathan Lynch | 13a9801 | 2008-12-10 14:28:41 +0000 | [diff] [blame] | 58 | int smp_hw_index[NR_CPUS]; |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame] | 59 | EXPORT_SYMBOL(smp_hw_index); |
Nathan Lynch | 13a9801 | 2008-12-10 14:28:41 +0000 | [diff] [blame] | 60 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 61 | unsigned int DMA_MODE_READ; |
| 62 | unsigned int DMA_MODE_WRITE; |
| 63 | |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame] | 64 | EXPORT_SYMBOL(DMA_MODE_READ); |
| 65 | EXPORT_SYMBOL(DMA_MODE_WRITE); |
| 66 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 67 | /* |
Benjamin Herrenschmidt | bd7c93c | 2016-07-05 15:03:45 +1000 | [diff] [blame] | 68 | * This is run before start_kernel(), the kernel has been relocated |
| 69 | * and we are running with enough of the MMU enabled to have our |
| 70 | * proper kernel virtual addresses |
| 71 | * |
Benjamin Herrenschmidt | f9cc1d1 | 2016-08-10 17:32:38 +1000 | [diff] [blame] | 72 | * We do the initial parsing of the flat device-tree and prepares |
| 73 | * for the MMU to be fully initialized. |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 74 | */ |
Scott Wood | 6dece0eb | 2011-07-25 11:29:33 +0000 | [diff] [blame] | 75 | notrace void __init machine_init(u64 dt_ptr) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 76 | { |
Jordan Niethe | 94afd06 | 2020-05-06 13:40:31 +1000 | [diff] [blame] | 77 | struct ppc_inst *addr = (struct ppc_inst *)patch_site_addr(&patch__memset_nocache); |
| 78 | struct ppc_inst insn; |
Christophe Leroy | ad1b012 | 2017-08-23 16:54:38 +0200 | [diff] [blame] | 79 | |
Benjamin Herrenschmidt | 97f6e0c | 2016-08-10 17:27:34 +1000 | [diff] [blame] | 80 | /* Configure static keys first, now that we're relocated. */ |
| 81 | setup_feature_keys(); |
| 82 | |
Christophe Leroy | 925ac14 | 2020-05-19 05:48:58 +0000 | [diff] [blame] | 83 | early_ioremap_init(); |
Christophe Leroy | 265c349 | 2019-09-12 13:49:43 +0000 | [diff] [blame] | 84 | |
David Gibson | 719c91c | 2007-02-13 15:54:22 +1100 | [diff] [blame] | 85 | /* Enable early debugging if any specified (see udbg.h) */ |
| 86 | udbg_early_init(); |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 87 | |
Jordan Niethe | 7534625 | 2020-05-06 13:40:26 +1000 | [diff] [blame] | 88 | patch_instruction_site(&patch__memcpy_nocache, ppc_inst(PPC_INST_NOP)); |
Christophe Leroy | ad1b012 | 2017-08-23 16:54:38 +0200 | [diff] [blame] | 89 | |
Jordan Niethe | 7c95d88 | 2020-05-06 13:40:25 +1000 | [diff] [blame] | 90 | create_cond_branch(&insn, addr, branch_target(addr), 0x820000); |
Christophe Leroy | ad1b012 | 2017-08-23 16:54:38 +0200 | [diff] [blame] | 91 | patch_instruction(addr, insn); /* replace b by bne cr0 */ |
LEROY Christophe | 1cd0389 | 2015-09-16 12:04:51 +0200 | [diff] [blame] | 92 | |
Benjamin Herrenschmidt | 51d3082 | 2005-11-23 17:57:25 +1100 | [diff] [blame] | 93 | /* Do some early initialization based on the flat device tree */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 94 | early_init_devtree(__va(dt_ptr)); |
| 95 | |
Dave Kleikamp | 91b191c | 2011-07-04 18:38:03 +0000 | [diff] [blame] | 96 | early_init_mmu(); |
| 97 | |
Dale Farnsworth | f8f50b1 | 2008-12-17 10:09:26 +0000 | [diff] [blame] | 98 | setup_kdump_trampoline(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 99 | } |
| 100 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 101 | /* Checks "l2cr=xxxx" command-line option */ |
Mathieu Malaterre | d15a261 | 2018-03-07 21:32:55 +0100 | [diff] [blame] | 102 | static int __init ppc_setup_l2cr(char *str) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 103 | { |
| 104 | if (cpu_has_feature(CPU_FTR_L2CR)) { |
| 105 | unsigned long val = simple_strtoul(str, NULL, 0); |
| 106 | printk(KERN_INFO "l2cr set to %lx\n", val); |
| 107 | _set_L2CR(0); /* force invalidate by disable cache */ |
| 108 | _set_L2CR(val); /* and enable it */ |
| 109 | } |
| 110 | return 1; |
| 111 | } |
| 112 | __setup("l2cr=", ppc_setup_l2cr); |
| 113 | |
Robert Brose | a78bfbf | 2008-03-29 07:20:23 +1100 | [diff] [blame] | 114 | /* Checks "l3cr=xxxx" command-line option */ |
Mathieu Malaterre | d15a261 | 2018-03-07 21:32:55 +0100 | [diff] [blame] | 115 | static int __init ppc_setup_l3cr(char *str) |
Robert Brose | a78bfbf | 2008-03-29 07:20:23 +1100 | [diff] [blame] | 116 | { |
| 117 | if (cpu_has_feature(CPU_FTR_L3CR)) { |
| 118 | unsigned long val = simple_strtoul(str, NULL, 0); |
| 119 | printk(KERN_INFO "l3cr set to %lx\n", val); |
| 120 | _set_L3CR(val); /* and enable it */ |
| 121 | } |
| 122 | return 1; |
| 123 | } |
| 124 | __setup("l3cr=", ppc_setup_l3cr); |
| 125 | |
Mathieu Malaterre | d15a261 | 2018-03-07 21:32:55 +0100 | [diff] [blame] | 126 | static int __init ppc_init(void) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 127 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 128 | /* clear the progress line */ |
Giuliano Pochini | 5e41763 | 2007-03-26 21:40:28 -0800 | [diff] [blame] | 129 | if (ppc_md.progress) |
| 130 | ppc_md.progress(" ", 0xffff); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 131 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 132 | /* call platform init */ |
| 133 | if (ppc_md.init != NULL) { |
| 134 | ppc_md.init(); |
| 135 | } |
| 136 | return 0; |
| 137 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 138 | arch_initcall(ppc_init); |
| 139 | |
Christophe Leroy | c8e409a | 2019-01-31 10:08:44 +0000 | [diff] [blame] | 140 | static void *__init alloc_stack(void) |
| 141 | { |
Christophe Leroy | 63289e7 | 2019-12-21 08:32:28 +0000 | [diff] [blame] | 142 | void *ptr = memblock_alloc(THREAD_SIZE, THREAD_ALIGN); |
Christophe Leroy | c8e409a | 2019-01-31 10:08:44 +0000 | [diff] [blame] | 143 | |
| 144 | if (!ptr) |
| 145 | panic("cannot allocate %d bytes for stack at %pS\n", |
| 146 | THREAD_SIZE, (void *)_RET_IP_); |
| 147 | |
| 148 | return ptr; |
| 149 | } |
| 150 | |
Benjamin Herrenschmidt | b1923ca | 2016-07-05 15:07:51 +1000 | [diff] [blame] | 151 | void __init irqstack_early_init(void) |
Kumar Gala | 8521882 | 2008-04-28 16:21:22 +1000 | [diff] [blame] | 152 | { |
| 153 | unsigned int i; |
| 154 | |
Christophe Leroy | 547db12 | 2019-12-21 08:32:30 +0000 | [diff] [blame] | 155 | if (IS_ENABLED(CONFIG_VMAP_STACK)) |
| 156 | return; |
| 157 | |
Kumar Gala | 8521882 | 2008-04-28 16:21:22 +1000 | [diff] [blame] | 158 | /* interrupt stacks must be in lowmem, we get that for free on ppc32 |
Benjamin Herrenschmidt | e63075a | 2010-07-06 15:39:01 -0700 | [diff] [blame] | 159 | * as the memblock is limited to lowmem by default */ |
Kumar Gala | 8521882 | 2008-04-28 16:21:22 +1000 | [diff] [blame] | 160 | for_each_possible_cpu(i) { |
Christophe Leroy | c8e409a | 2019-01-31 10:08:44 +0000 | [diff] [blame] | 161 | softirq_ctx[i] = alloc_stack(); |
| 162 | hardirq_ctx[i] = alloc_stack(); |
Kumar Gala | 8521882 | 2008-04-28 16:21:22 +1000 | [diff] [blame] | 163 | } |
| 164 | } |
Kumar Gala | 8521882 | 2008-04-28 16:21:22 +1000 | [diff] [blame] | 165 | |
Christophe Leroy | 3978eb7 | 2019-12-21 08:32:29 +0000 | [diff] [blame] | 166 | #ifdef CONFIG_VMAP_STACK |
| 167 | void *emergency_ctx[NR_CPUS] __ro_after_init; |
| 168 | |
| 169 | void __init emergency_stack_init(void) |
| 170 | { |
| 171 | unsigned int i; |
| 172 | |
| 173 | for_each_possible_cpu(i) |
| 174 | emergency_ctx[i] = alloc_stack(); |
| 175 | } |
| 176 | #endif |
| 177 | |
Kumar Gala | bcf0b08 | 2008-04-30 03:49:55 -0500 | [diff] [blame] | 178 | #if defined(CONFIG_BOOKE) || defined(CONFIG_40x) |
Benjamin Herrenschmidt | b1923ca | 2016-07-05 15:07:51 +1000 | [diff] [blame] | 179 | void __init exc_lvl_early_init(void) |
Kumar Gala | bcf0b08 | 2008-04-30 03:49:55 -0500 | [diff] [blame] | 180 | { |
Dave Kleikamp | 3e7f45a | 2010-08-18 06:44:25 +0000 | [diff] [blame] | 181 | unsigned int i, hw_cpu; |
Kumar Gala | bcf0b08 | 2008-04-30 03:49:55 -0500 | [diff] [blame] | 182 | |
| 183 | /* interrupt stacks must be in lowmem, we get that for free on ppc32 |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 184 | * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */ |
Kumar Gala | bcf0b08 | 2008-04-30 03:49:55 -0500 | [diff] [blame] | 185 | for_each_possible_cpu(i) { |
Kevin Hao | 04a3411 | 2014-01-29 18:24:54 +0800 | [diff] [blame] | 186 | #ifdef CONFIG_SMP |
Dave Kleikamp | 3e7f45a | 2010-08-18 06:44:25 +0000 | [diff] [blame] | 187 | hw_cpu = get_hard_smp_processor_id(i); |
Kevin Hao | 04a3411 | 2014-01-29 18:24:54 +0800 | [diff] [blame] | 188 | #else |
| 189 | hw_cpu = 0; |
| 190 | #endif |
| 191 | |
Christophe Leroy | c8e409a | 2019-01-31 10:08:44 +0000 | [diff] [blame] | 192 | critirq_ctx[hw_cpu] = alloc_stack(); |
Kumar Gala | bcf0b08 | 2008-04-30 03:49:55 -0500 | [diff] [blame] | 193 | #ifdef CONFIG_BOOKE |
Christophe Leroy | c8e409a | 2019-01-31 10:08:44 +0000 | [diff] [blame] | 194 | dbgirq_ctx[hw_cpu] = alloc_stack(); |
| 195 | mcheckirq_ctx[hw_cpu] = alloc_stack(); |
Kumar Gala | bcf0b08 | 2008-04-30 03:49:55 -0500 | [diff] [blame] | 196 | #endif |
| 197 | } |
| 198 | } |
Kumar Gala | bcf0b08 | 2008-04-30 03:49:55 -0500 | [diff] [blame] | 199 | #endif |
| 200 | |
Benjamin Herrenschmidt | b1923ca | 2016-07-05 15:07:51 +1000 | [diff] [blame] | 201 | void __init setup_power_save(void) |
Benjamin Herrenschmidt | 5657138 | 2016-07-05 15:04:05 +1000 | [diff] [blame] | 202 | { |
Christophe Leroy | d7cceda | 2018-11-17 10:24:56 +0000 | [diff] [blame] | 203 | #ifdef CONFIG_PPC_BOOK3S_32 |
Benjamin Herrenschmidt | 5657138 | 2016-07-05 15:04:05 +1000 | [diff] [blame] | 204 | if (cpu_has_feature(CPU_FTR_CAN_DOZE) || |
| 205 | cpu_has_feature(CPU_FTR_CAN_NAP)) |
| 206 | ppc_md.power_save = ppc6xx_idle; |
| 207 | #endif |
| 208 | |
| 209 | #ifdef CONFIG_E500 |
| 210 | if (cpu_has_feature(CPU_FTR_CAN_DOZE) || |
| 211 | cpu_has_feature(CPU_FTR_CAN_NAP)) |
| 212 | ppc_md.power_save = e500_idle; |
| 213 | #endif |
| 214 | } |
| 215 | |
Benjamin Herrenschmidt | b1923ca | 2016-07-05 15:07:51 +1000 | [diff] [blame] | 216 | __init void initialize_cache_info(void) |
Benjamin Herrenschmidt | 8f212cb | 2016-07-05 15:04:10 +1000 | [diff] [blame] | 217 | { |
| 218 | /* |
| 219 | * Set cache line size based on type of cpu as a default. |
| 220 | * Systems with OF can look in the properties on the cpu node(s) |
| 221 | * for a possibly more accurate value. |
| 222 | */ |
| 223 | dcache_bsize = cur_cpu_spec->dcache_bsize; |
| 224 | icache_bsize = cur_cpu_spec->icache_bsize; |
| 225 | ucache_bsize = 0; |
Christophe Leroy | e0291f1 | 2019-08-26 15:52:18 +0000 | [diff] [blame] | 226 | if (IS_ENABLED(CONFIG_PPC_BOOK3S_601) || IS_ENABLED(CONFIG_E200)) |
Benjamin Herrenschmidt | 8f212cb | 2016-07-05 15:04:10 +1000 | [diff] [blame] | 227 | ucache_bsize = icache_bsize = dcache_bsize; |
| 228 | } |