Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Procedures for interfacing to Open Firmware. |
| 3 | * |
| 4 | * Paul Mackerras August 1996. |
| 5 | * Copyright (C) 1996-2005 Paul Mackerras. |
| 6 | * |
| 7 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. |
| 8 | * {engebret|bergner}@us.ibm.com |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version |
| 13 | * 2 of the License, or (at your option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #undef DEBUG_PROM |
| 17 | |
Daniel Axtens | 054f367 | 2017-07-12 14:36:04 -0700 | [diff] [blame] | 18 | /* we cannot use FORTIFY as it brings in new symbols */ |
| 19 | #define __NO_FORTIFY |
| 20 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 21 | #include <stdarg.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/threads.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/proc_fs.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/initrd.h> |
| 32 | #include <linux/bitops.h> |
| 33 | #include <asm/prom.h> |
| 34 | #include <asm/rtas.h> |
| 35 | #include <asm/page.h> |
| 36 | #include <asm/processor.h> |
| 37 | #include <asm/irq.h> |
| 38 | #include <asm/io.h> |
| 39 | #include <asm/smp.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 40 | #include <asm/mmu.h> |
| 41 | #include <asm/pgtable.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 42 | #include <asm/iommu.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 43 | #include <asm/btext.h> |
| 44 | #include <asm/sections.h> |
| 45 | #include <asm/machdep.h> |
Daniel Axtens | 0545d54 | 2016-09-06 15:32:43 +1000 | [diff] [blame] | 46 | #include <asm/asm-prototypes.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 47 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 48 | #include <linux/linux_logo.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 49 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 50 | /* All of prom_init bss lives here */ |
| 51 | #define __prombss __initdata |
| 52 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 53 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 54 | * Eventually bump that one up |
| 55 | */ |
| 56 | #define DEVTREE_CHUNK_SIZE 0x100000 |
| 57 | |
| 58 | /* |
| 59 | * This is the size of the local memory reserve map that gets copied |
| 60 | * into the boot params passed to the kernel. That size is totally |
| 61 | * flexible as the kernel just reads the list until it encounters an |
| 62 | * entry with size 0, so it can be changed without breaking binary |
| 63 | * compatibility |
| 64 | */ |
| 65 | #define MEM_RESERVE_MAP_SIZE 8 |
| 66 | |
| 67 | /* |
| 68 | * prom_init() is called very early on, before the kernel text |
| 69 | * and data have been mapped to KERNELBASE. At this point the code |
| 70 | * is running at whatever address it has been loaded at. |
| 71 | * On ppc32 we compile with -mrelocatable, which means that references |
| 72 | * to extern and static variables get relocated automatically. |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 73 | * ppc64 objects are always relocatable, we just need to relocate the |
| 74 | * TOC. |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 75 | * |
| 76 | * Because OF may have mapped I/O devices into the area starting at |
| 77 | * KERNELBASE, particularly on CHRP machines, we can't safely call |
| 78 | * OF once the kernel has been mapped to KERNELBASE. Therefore all |
| 79 | * OF calls must be done within prom_init(). |
| 80 | * |
| 81 | * ADDR is used in calls to call_prom. The 4th and following |
| 82 | * arguments to call_prom should be 32-bit values. |
| 83 | * On ppc64, 64 bit values are truncated to 32 bits (and |
| 84 | * fortunately don't get interpreted as two arguments). |
| 85 | */ |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 86 | #define ADDR(x) (u32)(unsigned long)(x) |
| 87 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 88 | #ifdef CONFIG_PPC64 |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 89 | #define OF_WORKAROUNDS 0 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 90 | #else |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 91 | #define OF_WORKAROUNDS of_workarounds |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 92 | static int of_workarounds __prombss; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 93 | #endif |
| 94 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 95 | #define OF_WA_CLAIM 1 /* do phys/virt claim separately, then map */ |
| 96 | #define OF_WA_LONGTRAIL 2 /* work around longtrail bugs */ |
| 97 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 98 | #define PROM_BUG() do { \ |
| 99 | prom_printf("kernel BUG at %s line 0x%x!\n", \ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 100 | __FILE__, __LINE__); \ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 101 | __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \ |
| 102 | } while (0) |
| 103 | |
| 104 | #ifdef DEBUG_PROM |
| 105 | #define prom_debug(x...) prom_printf(x) |
| 106 | #else |
Mathieu Malaterre | 85aa4b9 | 2018-04-23 21:36:38 +0200 | [diff] [blame] | 107 | #define prom_debug(x...) do { } while (0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 108 | #endif |
| 109 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 110 | |
| 111 | typedef u32 prom_arg_t; |
| 112 | |
| 113 | struct prom_args { |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 114 | __be32 service; |
| 115 | __be32 nargs; |
| 116 | __be32 nret; |
| 117 | __be32 args[10]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | struct prom_t { |
| 121 | ihandle root; |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 122 | phandle chosen; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 123 | int cpu; |
| 124 | ihandle stdout; |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 125 | ihandle mmumap; |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 126 | ihandle memory; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | struct mem_map_entry { |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 130 | __be64 base; |
| 131 | __be64 size; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 132 | }; |
| 133 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 134 | typedef __be32 cell_t; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 135 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 136 | extern void __start(unsigned long r3, unsigned long r4, unsigned long r5, |
| 137 | unsigned long r6, unsigned long r7, unsigned long r8, |
| 138 | unsigned long r9); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 139 | |
| 140 | #ifdef CONFIG_PPC64 |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 141 | extern int enter_prom(struct prom_args *args, unsigned long entry); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 142 | #else |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 143 | static inline int enter_prom(struct prom_args *args, unsigned long entry) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 144 | { |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 145 | return ((int (*)(struct prom_args *))entry)(args); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 146 | } |
| 147 | #endif |
| 148 | |
| 149 | extern void copy_and_flush(unsigned long dest, unsigned long src, |
| 150 | unsigned long size, unsigned long offset); |
| 151 | |
| 152 | /* prom structure */ |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 153 | static struct prom_t __prombss prom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 154 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 155 | static unsigned long __prombss prom_entry; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 156 | |
| 157 | #define PROM_SCRATCH_SIZE 256 |
| 158 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 159 | static char __prombss of_stdout_device[256]; |
| 160 | static char __prombss prom_scratch[PROM_SCRATCH_SIZE]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 161 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 162 | static unsigned long __prombss dt_header_start; |
| 163 | static unsigned long __prombss dt_struct_start, dt_struct_end; |
| 164 | static unsigned long __prombss dt_string_start, dt_string_end; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 165 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 166 | static unsigned long __prombss prom_initrd_start, prom_initrd_end; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 167 | |
| 168 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 169 | static int __prombss prom_iommu_force_on; |
| 170 | static int __prombss prom_iommu_off; |
| 171 | static unsigned long __prombss prom_tce_alloc_start; |
| 172 | static unsigned long __prombss prom_tce_alloc_end; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 173 | #endif |
| 174 | |
Benjamin Herrenschmidt | c886087 | 2018-10-15 13:49:54 +1100 | [diff] [blame^] | 175 | #ifdef CONFIG_PPC_PSERIES |
| 176 | static bool prom_radix_disable __prombss; |
| 177 | #endif |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 178 | |
| 179 | struct platform_support { |
| 180 | bool hash_mmu; |
| 181 | bool radix_mmu; |
| 182 | bool radix_gtse; |
Cédric Le Goater | ac5e5a5 | 2017-08-30 21:46:16 +0200 | [diff] [blame] | 183 | bool xive; |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 184 | }; |
| 185 | |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 186 | /* Platforms codes are now obsolete in the kernel. Now only used within this |
| 187 | * file and ultimately gone too. Feel free to change them if you need, they |
| 188 | * are not shared with anything outside of this file anymore |
| 189 | */ |
| 190 | #define PLATFORM_PSERIES 0x0100 |
| 191 | #define PLATFORM_PSERIES_LPAR 0x0101 |
| 192 | #define PLATFORM_LPAR 0x0001 |
| 193 | #define PLATFORM_POWERMAC 0x0400 |
| 194 | #define PLATFORM_GENERIC 0x0500 |
| 195 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 196 | static int __prombss of_platform; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 197 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 198 | static char __prombss prom_cmd_line[COMMAND_LINE_SIZE]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 199 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 200 | static unsigned long __prombss prom_memory_limit; |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 201 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 202 | static unsigned long __prombss alloc_top; |
| 203 | static unsigned long __prombss alloc_top_high; |
| 204 | static unsigned long __prombss alloc_bottom; |
| 205 | static unsigned long __prombss rmo_top; |
| 206 | static unsigned long __prombss ram_top; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 207 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 208 | static struct mem_map_entry __prombss mem_reserve_map[MEM_RESERVE_MAP_SIZE]; |
| 209 | static int __prombss mem_reserve_cnt; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 210 | |
Benjamin Herrenschmidt | e63334e | 2018-10-15 13:49:52 +1100 | [diff] [blame] | 211 | static cell_t __prombss regbuf[1024]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 212 | |
Benjamin Herrenschmidt | dbe78b4 | 2013-09-25 14:02:50 +1000 | [diff] [blame] | 213 | static bool rtas_has_query_cpu_stopped; |
| 214 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 215 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 216 | /* |
| 217 | * Error results ... some OF calls will return "-1" on error, some |
| 218 | * will return 0, some will return either. To simplify, here are |
| 219 | * macros to use with any ihandle or phandle return value to check if |
| 220 | * it is valid |
| 221 | */ |
| 222 | |
| 223 | #define PROM_ERROR (-1u) |
| 224 | #define PHANDLE_VALID(p) ((p) != 0 && (p) != PROM_ERROR) |
| 225 | #define IHANDLE_VALID(i) ((i) != 0 && (i) != PROM_ERROR) |
| 226 | |
| 227 | |
| 228 | /* This is the one and *ONLY* place where we actually call open |
| 229 | * firmware. |
| 230 | */ |
| 231 | |
| 232 | static int __init call_prom(const char *service, int nargs, int nret, ...) |
| 233 | { |
| 234 | int i; |
| 235 | struct prom_args args; |
| 236 | va_list list; |
| 237 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 238 | args.service = cpu_to_be32(ADDR(service)); |
| 239 | args.nargs = cpu_to_be32(nargs); |
| 240 | args.nret = cpu_to_be32(nret); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 241 | |
| 242 | va_start(list, nret); |
| 243 | for (i = 0; i < nargs; i++) |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 244 | args.args[i] = cpu_to_be32(va_arg(list, prom_arg_t)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 245 | va_end(list); |
| 246 | |
| 247 | for (i = 0; i < nret; i++) |
| 248 | args.args[nargs+i] = 0; |
| 249 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 250 | if (enter_prom(&args, prom_entry) < 0) |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 251 | return PROM_ERROR; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 252 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 253 | return (nret > 0) ? be32_to_cpu(args.args[nargs]) : 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static int __init call_prom_ret(const char *service, int nargs, int nret, |
| 257 | prom_arg_t *rets, ...) |
| 258 | { |
| 259 | int i; |
| 260 | struct prom_args args; |
| 261 | va_list list; |
| 262 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 263 | args.service = cpu_to_be32(ADDR(service)); |
| 264 | args.nargs = cpu_to_be32(nargs); |
| 265 | args.nret = cpu_to_be32(nret); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 266 | |
| 267 | va_start(list, rets); |
| 268 | for (i = 0; i < nargs; i++) |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 269 | args.args[i] = cpu_to_be32(va_arg(list, prom_arg_t)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 270 | va_end(list); |
| 271 | |
| 272 | for (i = 0; i < nret; i++) |
Olaf Hering | ed1189b7 | 2005-11-29 14:04:05 +0100 | [diff] [blame] | 273 | args.args[nargs+i] = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 274 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 275 | if (enter_prom(&args, prom_entry) < 0) |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 276 | return PROM_ERROR; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 277 | |
| 278 | if (rets != NULL) |
| 279 | for (i = 1; i < nret; ++i) |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 280 | rets[i-1] = be32_to_cpu(args.args[nargs+i]); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 281 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 282 | return (nret > 0) ? be32_to_cpu(args.args[nargs]) : 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 286 | static void __init prom_print(const char *msg) |
| 287 | { |
| 288 | const char *p, *q; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 289 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 290 | if (prom.stdout == 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 291 | return; |
| 292 | |
| 293 | for (p = msg; *p != 0; p = q) { |
| 294 | for (q = p; *q != 0 && *q != '\n'; ++q) |
| 295 | ; |
| 296 | if (q > p) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 297 | call_prom("write", 3, 1, prom.stdout, p, q - p); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 298 | if (*q == 0) |
| 299 | break; |
| 300 | ++q; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 301 | call_prom("write", 3, 1, prom.stdout, ADDR("\r\n"), 2); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
| 305 | |
Mathieu Malaterre | 8af1da4 | 2018-05-29 21:20:01 +0200 | [diff] [blame] | 306 | /* |
| 307 | * Both prom_print_hex & prom_print_dec takes an unsigned long as input so that |
| 308 | * we do not need __udivdi3 or __umoddi3 on 32bits. |
| 309 | */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 310 | static void __init prom_print_hex(unsigned long val) |
| 311 | { |
| 312 | int i, nibbles = sizeof(val)*2; |
| 313 | char buf[sizeof(val)*2+1]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 314 | |
| 315 | for (i = nibbles-1; i >= 0; i--) { |
| 316 | buf[i] = (val & 0xf) + '0'; |
| 317 | if (buf[i] > '9') |
| 318 | buf[i] += ('a'-'0'-10); |
| 319 | val >>= 4; |
| 320 | } |
| 321 | buf[nibbles] = '\0'; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 322 | call_prom("write", 3, 1, prom.stdout, buf, nibbles); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 323 | } |
| 324 | |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 325 | /* max number of decimal digits in an unsigned long */ |
| 326 | #define UL_DIGITS 21 |
| 327 | static void __init prom_print_dec(unsigned long val) |
| 328 | { |
| 329 | int i, size; |
| 330 | char buf[UL_DIGITS+1]; |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 331 | |
| 332 | for (i = UL_DIGITS-1; i >= 0; i--) { |
| 333 | buf[i] = (val % 10) + '0'; |
| 334 | val = val/10; |
| 335 | if (val == 0) |
| 336 | break; |
| 337 | } |
| 338 | /* shift stuff down */ |
| 339 | size = UL_DIGITS - i; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 340 | call_prom("write", 3, 1, prom.stdout, buf+i, size); |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 341 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 342 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 343 | __printf(1, 2) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 344 | static void __init prom_printf(const char *format, ...) |
| 345 | { |
| 346 | const char *p, *q, *s; |
| 347 | va_list args; |
| 348 | unsigned long v; |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 349 | long vs; |
Mathieu Malaterre | 8af1da4 | 2018-05-29 21:20:01 +0200 | [diff] [blame] | 350 | int n = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 351 | |
| 352 | va_start(args, format); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 353 | for (p = format; *p != 0; p = q) { |
| 354 | for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q) |
| 355 | ; |
| 356 | if (q > p) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 357 | call_prom("write", 3, 1, prom.stdout, p, q - p); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 358 | if (*q == 0) |
| 359 | break; |
| 360 | if (*q == '\n') { |
| 361 | ++q; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 362 | call_prom("write", 3, 1, prom.stdout, |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 363 | ADDR("\r\n"), 2); |
| 364 | continue; |
| 365 | } |
| 366 | ++q; |
| 367 | if (*q == 0) |
| 368 | break; |
Mathieu Malaterre | 8af1da4 | 2018-05-29 21:20:01 +0200 | [diff] [blame] | 369 | while (*q == 'l') { |
| 370 | ++q; |
| 371 | ++n; |
| 372 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 373 | switch (*q) { |
| 374 | case 's': |
| 375 | ++q; |
| 376 | s = va_arg(args, const char *); |
| 377 | prom_print(s); |
| 378 | break; |
| 379 | case 'x': |
| 380 | ++q; |
Mathieu Malaterre | 8af1da4 | 2018-05-29 21:20:01 +0200 | [diff] [blame] | 381 | switch (n) { |
| 382 | case 0: |
| 383 | v = va_arg(args, unsigned int); |
| 384 | break; |
| 385 | case 1: |
| 386 | v = va_arg(args, unsigned long); |
| 387 | break; |
| 388 | case 2: |
| 389 | default: |
| 390 | v = va_arg(args, unsigned long long); |
| 391 | break; |
| 392 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 393 | prom_print_hex(v); |
| 394 | break; |
Mathieu Malaterre | 8af1da4 | 2018-05-29 21:20:01 +0200 | [diff] [blame] | 395 | case 'u': |
| 396 | ++q; |
| 397 | switch (n) { |
| 398 | case 0: |
| 399 | v = va_arg(args, unsigned int); |
| 400 | break; |
| 401 | case 1: |
| 402 | v = va_arg(args, unsigned long); |
| 403 | break; |
| 404 | case 2: |
| 405 | default: |
| 406 | v = va_arg(args, unsigned long long); |
| 407 | break; |
| 408 | } |
| 409 | prom_print_dec(v); |
| 410 | break; |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 411 | case 'd': |
| 412 | ++q; |
Mathieu Malaterre | 8af1da4 | 2018-05-29 21:20:01 +0200 | [diff] [blame] | 413 | switch (n) { |
| 414 | case 0: |
| 415 | vs = va_arg(args, int); |
| 416 | break; |
| 417 | case 1: |
| 418 | vs = va_arg(args, long); |
| 419 | break; |
| 420 | case 2: |
| 421 | default: |
| 422 | vs = va_arg(args, long long); |
| 423 | break; |
| 424 | } |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 425 | if (vs < 0) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 426 | prom_print("-"); |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 427 | vs = -vs; |
| 428 | } |
| 429 | prom_print_dec(vs); |
| 430 | break; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 431 | } |
| 432 | } |
Daniel Axtens | 1b855e1 | 2015-12-17 19:41:00 +1100 | [diff] [blame] | 433 | va_end(args); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 437 | static unsigned int __init prom_claim(unsigned long virt, unsigned long size, |
| 438 | unsigned long align) |
| 439 | { |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 440 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 441 | if (align == 0 && (OF_WORKAROUNDS & OF_WA_CLAIM)) { |
| 442 | /* |
| 443 | * Old OF requires we claim physical and virtual separately |
| 444 | * and then map explicitly (assuming virtual mode) |
| 445 | */ |
| 446 | int ret; |
| 447 | prom_arg_t result; |
| 448 | |
| 449 | ret = call_prom_ret("call-method", 5, 2, &result, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 450 | ADDR("claim"), prom.memory, |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 451 | align, size, virt); |
| 452 | if (ret != 0 || result == -1) |
| 453 | return -1; |
| 454 | ret = call_prom_ret("call-method", 5, 2, &result, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 455 | ADDR("claim"), prom.mmumap, |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 456 | align, size, virt); |
| 457 | if (ret != 0) { |
| 458 | call_prom("call-method", 4, 1, ADDR("release"), |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 459 | prom.memory, size, virt); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 460 | return -1; |
| 461 | } |
| 462 | /* the 0x12 is M (coherence) + PP == read/write */ |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 463 | call_prom("call-method", 6, 1, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 464 | ADDR("map"), prom.mmumap, 0x12, size, virt, virt); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 465 | return virt; |
| 466 | } |
| 467 | return call_prom("claim", 3, 1, (prom_arg_t)virt, (prom_arg_t)size, |
| 468 | (prom_arg_t)align); |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 469 | } |
| 470 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 471 | static void __init __attribute__((noreturn)) prom_panic(const char *reason) |
| 472 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 473 | prom_print(reason); |
Olaf Hering | add60ef | 2006-03-23 22:03:57 +0100 | [diff] [blame] | 474 | /* Do not call exit because it clears the screen on pmac |
| 475 | * it also causes some sort of double-fault on early pmacs */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 476 | if (of_platform == PLATFORM_POWERMAC) |
Olaf Hering | add60ef | 2006-03-23 22:03:57 +0100 | [diff] [blame] | 477 | asm("trap\n"); |
| 478 | |
Stephen Rothwell | 1d9a473 | 2012-03-21 18:23:27 +0000 | [diff] [blame] | 479 | /* ToDo: should put up an SRC here on pSeries */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 480 | call_prom("exit", 0, 0); |
| 481 | |
| 482 | for (;;) /* should never get here */ |
| 483 | ; |
| 484 | } |
| 485 | |
| 486 | |
| 487 | static int __init prom_next_node(phandle *nodep) |
| 488 | { |
| 489 | phandle node; |
| 490 | |
| 491 | if ((node = *nodep) != 0 |
| 492 | && (*nodep = call_prom("child", 1, 1, node)) != 0) |
| 493 | return 1; |
| 494 | if ((*nodep = call_prom("peer", 1, 1, node)) != 0) |
| 495 | return 1; |
| 496 | for (;;) { |
| 497 | if ((node = call_prom("parent", 1, 1, node)) == 0) |
| 498 | return 0; |
| 499 | if ((*nodep = call_prom("peer", 1, 1, node)) != 0) |
| 500 | return 1; |
| 501 | } |
| 502 | } |
| 503 | |
Tobias Klauser | 60d862e | 2016-11-17 17:20:24 +0100 | [diff] [blame] | 504 | static inline int prom_getprop(phandle node, const char *pname, |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 505 | void *value, size_t valuelen) |
| 506 | { |
| 507 | return call_prom("getprop", 4, 1, node, ADDR(pname), |
| 508 | (u32)(unsigned long) value, (u32) valuelen); |
| 509 | } |
| 510 | |
Tobias Klauser | 60d862e | 2016-11-17 17:20:24 +0100 | [diff] [blame] | 511 | static inline int prom_getproplen(phandle node, const char *pname) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 512 | { |
| 513 | return call_prom("getproplen", 2, 1, node, ADDR(pname)); |
| 514 | } |
| 515 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 516 | static void add_string(char **str, const char *q) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 517 | { |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 518 | char *p = *str; |
| 519 | |
| 520 | while (*q) |
| 521 | *p++ = *q++; |
| 522 | *p++ = ' '; |
| 523 | *str = p; |
| 524 | } |
| 525 | |
| 526 | static char *tohex(unsigned int x) |
| 527 | { |
| 528 | static char digits[] = "0123456789abcdef"; |
| 529 | static char result[9]; |
| 530 | int i; |
| 531 | |
| 532 | result[8] = 0; |
| 533 | i = 8; |
| 534 | do { |
| 535 | --i; |
| 536 | result[i] = digits[x & 0xf]; |
| 537 | x >>= 4; |
| 538 | } while (x != 0 && i > 0); |
| 539 | return &result[i]; |
| 540 | } |
| 541 | |
| 542 | static int __init prom_setprop(phandle node, const char *nodename, |
| 543 | const char *pname, void *value, size_t valuelen) |
| 544 | { |
| 545 | char cmd[256], *p; |
| 546 | |
| 547 | if (!(OF_WORKAROUNDS & OF_WA_LONGTRAIL)) |
| 548 | return call_prom("setprop", 4, 1, node, ADDR(pname), |
| 549 | (u32)(unsigned long) value, (u32) valuelen); |
| 550 | |
| 551 | /* gah... setprop doesn't work on longtrail, have to use interpret */ |
| 552 | p = cmd; |
| 553 | add_string(&p, "dev"); |
| 554 | add_string(&p, nodename); |
| 555 | add_string(&p, tohex((u32)(unsigned long) value)); |
| 556 | add_string(&p, tohex(valuelen)); |
| 557 | add_string(&p, tohex(ADDR(pname))); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 558 | add_string(&p, tohex(strlen(pname))); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 559 | add_string(&p, "property"); |
| 560 | *p = 0; |
| 561 | return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 562 | } |
| 563 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 564 | /* We can't use the standard versions because of relocation headaches. */ |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 565 | #define isxdigit(c) (('0' <= (c) && (c) <= '9') \ |
| 566 | || ('a' <= (c) && (c) <= 'f') \ |
| 567 | || ('A' <= (c) && (c) <= 'F')) |
| 568 | |
| 569 | #define isdigit(c) ('0' <= (c) && (c) <= '9') |
| 570 | #define islower(c) ('a' <= (c) && (c) <= 'z') |
| 571 | #define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c)) |
| 572 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 573 | static unsigned long prom_strtoul(const char *cp, const char **endp) |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 574 | { |
| 575 | unsigned long result = 0, base = 10, value; |
| 576 | |
| 577 | if (*cp == '0') { |
| 578 | base = 8; |
| 579 | cp++; |
| 580 | if (toupper(*cp) == 'X') { |
| 581 | cp++; |
| 582 | base = 16; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | while (isxdigit(*cp) && |
| 587 | (value = isdigit(*cp) ? *cp - '0' : toupper(*cp) - 'A' + 10) < base) { |
| 588 | result = result * base + value; |
| 589 | cp++; |
| 590 | } |
| 591 | |
| 592 | if (endp) |
| 593 | *endp = cp; |
| 594 | |
| 595 | return result; |
| 596 | } |
| 597 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 598 | static unsigned long prom_memparse(const char *ptr, const char **retptr) |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 599 | { |
| 600 | unsigned long ret = prom_strtoul(ptr, retptr); |
| 601 | int shift = 0; |
| 602 | |
| 603 | /* |
| 604 | * We can't use a switch here because GCC *may* generate a |
| 605 | * jump table which won't work, because we're not running at |
| 606 | * the address we're linked at. |
| 607 | */ |
| 608 | if ('G' == **retptr || 'g' == **retptr) |
| 609 | shift = 30; |
| 610 | |
| 611 | if ('M' == **retptr || 'm' == **retptr) |
| 612 | shift = 20; |
| 613 | |
| 614 | if ('K' == **retptr || 'k' == **retptr) |
| 615 | shift = 10; |
| 616 | |
| 617 | if (shift) { |
| 618 | ret <<= shift; |
| 619 | (*retptr)++; |
| 620 | } |
| 621 | |
| 622 | return ret; |
| 623 | } |
| 624 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 625 | /* |
| 626 | * Early parsing of the command line passed to the kernel, used for |
| 627 | * "mem=x" and the options that affect the iommu |
| 628 | */ |
| 629 | static void __init early_cmdline_parse(void) |
| 630 | { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 631 | const char *opt; |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 632 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 633 | char *p; |
Mathieu Malaterre | eab00a2 | 2018-04-04 22:08:35 +0200 | [diff] [blame] | 634 | int l __maybe_unused = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 635 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 636 | prom_cmd_line[0] = 0; |
| 637 | p = prom_cmd_line; |
| 638 | if ((long)prom.chosen > 0) |
| 639 | l = prom_getprop(prom.chosen, "bootargs", p, COMMAND_LINE_SIZE-1); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 640 | #ifdef CONFIG_CMDLINE |
Amos Waterland | 0e4aa9c | 2006-06-12 23:45:02 -0400 | [diff] [blame] | 641 | if (l <= 0 || p[0] == '\0') /* dbl check */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 642 | strlcpy(prom_cmd_line, |
| 643 | CONFIG_CMDLINE, sizeof(prom_cmd_line)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 644 | #endif /* CONFIG_CMDLINE */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 645 | prom_printf("command line: %s\n", prom_cmd_line); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 646 | |
| 647 | #ifdef CONFIG_PPC64 |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 648 | opt = strstr(prom_cmd_line, "iommu="); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 649 | if (opt) { |
| 650 | prom_printf("iommu opt is: %s\n", opt); |
| 651 | opt += 6; |
| 652 | while (*opt && *opt == ' ') |
| 653 | opt++; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 654 | if (!strncmp(opt, "off", 3)) |
| 655 | prom_iommu_off = 1; |
| 656 | else if (!strncmp(opt, "force", 5)) |
| 657 | prom_iommu_force_on = 1; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 658 | } |
| 659 | #endif |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 660 | opt = strstr(prom_cmd_line, "mem="); |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 661 | if (opt) { |
| 662 | opt += 4; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 663 | prom_memory_limit = prom_memparse(opt, (const char **)&opt); |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 664 | #ifdef CONFIG_PPC64 |
| 665 | /* Align to 16 MB == size of ppc64 large page */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 666 | prom_memory_limit = ALIGN(prom_memory_limit, 0x1000000); |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 667 | #endif |
| 668 | } |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 669 | |
Benjamin Herrenschmidt | c886087 | 2018-10-15 13:49:54 +1100 | [diff] [blame^] | 670 | #ifdef CONFIG_PPC_PSERIES |
| 671 | prom_radix_disable = !IS_ENABLED(CONFIG_PPC_RADIX_MMU_DEFAULT); |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 672 | opt = strstr(prom_cmd_line, "disable_radix"); |
| 673 | if (opt) { |
Aneesh Kumar K.V | 7a22d63 | 2018-03-30 17:39:02 +0530 | [diff] [blame] | 674 | opt += 13; |
| 675 | if (*opt && *opt == '=') { |
| 676 | bool val; |
| 677 | |
| 678 | if (kstrtobool(++opt, &val)) |
| 679 | prom_radix_disable = false; |
| 680 | else |
| 681 | prom_radix_disable = val; |
| 682 | } else |
| 683 | prom_radix_disable = true; |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 684 | } |
Aneesh Kumar K.V | 7a22d63 | 2018-03-30 17:39:02 +0530 | [diff] [blame] | 685 | if (prom_radix_disable) |
| 686 | prom_debug("Radix disabled from cmdline\n"); |
Benjamin Herrenschmidt | c886087 | 2018-10-15 13:49:54 +1100 | [diff] [blame^] | 687 | #endif /* CONFIG_PPC_PSERIES */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 688 | } |
| 689 | |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 690 | #ifdef CONFIG_PPC_PSERIES |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 691 | /* |
Nathan Fontenot | 530b5e1 | 2013-04-24 05:53:10 +0000 | [diff] [blame] | 692 | * The architecture vector has an array of PVR mask/value pairs, |
| 693 | * followed by # option vectors - 1, followed by the option vectors. |
| 694 | * |
| 695 | * See prom.h for the definition of the bits specified in the |
| 696 | * architecture vector. |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 697 | */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 698 | |
Michael Ellerman | e8a4fd0 | 2014-08-29 17:01:43 +1000 | [diff] [blame] | 699 | /* Firmware expects the value to be n - 1, where n is the # of vectors */ |
| 700 | #define NUM_VECTORS(n) ((n) - 1) |
| 701 | |
| 702 | /* |
| 703 | * Firmware expects 1 + n - 2, where n is the length of the option vector in |
| 704 | * bytes. The 1 accounts for the length byte itself, the - 2 .. ? |
| 705 | */ |
| 706 | #define VECTOR_LENGTH(n) (1 + (n) - 2) |
| 707 | |
Michael Ellerman | d03d1d6 | 2016-11-18 23:15:41 +1100 | [diff] [blame] | 708 | struct option_vector1 { |
| 709 | u8 byte1; |
| 710 | u8 arch_versions; |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 711 | u8 arch_versions3; |
Michael Ellerman | d03d1d6 | 2016-11-18 23:15:41 +1100 | [diff] [blame] | 712 | } __packed; |
| 713 | |
| 714 | struct option_vector2 { |
| 715 | u8 byte1; |
| 716 | __be16 reserved; |
| 717 | __be32 real_base; |
| 718 | __be32 real_size; |
| 719 | __be32 virt_base; |
| 720 | __be32 virt_size; |
| 721 | __be32 load_base; |
| 722 | __be32 min_rma; |
| 723 | __be32 min_load; |
| 724 | u8 min_rma_percent; |
| 725 | u8 max_pft_size; |
| 726 | } __packed; |
| 727 | |
| 728 | struct option_vector3 { |
| 729 | u8 byte1; |
| 730 | u8 byte2; |
| 731 | } __packed; |
| 732 | |
| 733 | struct option_vector4 { |
| 734 | u8 byte1; |
| 735 | u8 min_vp_cap; |
| 736 | } __packed; |
| 737 | |
| 738 | struct option_vector5 { |
| 739 | u8 byte1; |
| 740 | u8 byte2; |
| 741 | u8 byte3; |
| 742 | u8 cmo; |
| 743 | u8 associativity; |
| 744 | u8 bin_opts; |
| 745 | u8 micro_checkpoint; |
| 746 | u8 reserved0; |
| 747 | __be32 max_cpus; |
| 748 | __be16 papr_level; |
| 749 | __be16 reserved1; |
| 750 | u8 platform_facilities; |
| 751 | u8 reserved2; |
| 752 | __be16 reserved3; |
| 753 | u8 subprocessors; |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 754 | u8 byte22; |
| 755 | u8 intarch; |
| 756 | u8 mmu; |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 757 | u8 hash_ext; |
| 758 | u8 radix_ext; |
Michael Ellerman | d03d1d6 | 2016-11-18 23:15:41 +1100 | [diff] [blame] | 759 | } __packed; |
| 760 | |
| 761 | struct option_vector6 { |
| 762 | u8 reserved; |
| 763 | u8 secondary_pteg; |
| 764 | u8 os_name; |
| 765 | } __packed; |
| 766 | |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 767 | struct ibm_arch_vec { |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 768 | struct { u32 mask, val; } pvrs[12]; |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 769 | |
| 770 | u8 num_vectors; |
| 771 | |
| 772 | u8 vec1_len; |
| 773 | struct option_vector1 vec1; |
| 774 | |
| 775 | u8 vec2_len; |
| 776 | struct option_vector2 vec2; |
| 777 | |
| 778 | u8 vec3_len; |
| 779 | struct option_vector3 vec3; |
| 780 | |
| 781 | u8 vec4_len; |
| 782 | struct option_vector4 vec4; |
| 783 | |
| 784 | u8 vec5_len; |
| 785 | struct option_vector5 vec5; |
| 786 | |
| 787 | u8 vec6_len; |
| 788 | struct option_vector6 vec6; |
| 789 | } __packed; |
| 790 | |
| 791 | struct ibm_arch_vec __cacheline_aligned ibm_architecture_vec = { |
| 792 | .pvrs = { |
| 793 | { |
| 794 | .mask = cpu_to_be32(0xfffe0000), /* POWER5/POWER5+ */ |
| 795 | .val = cpu_to_be32(0x003a0000), |
| 796 | }, |
| 797 | { |
| 798 | .mask = cpu_to_be32(0xffff0000), /* POWER6 */ |
| 799 | .val = cpu_to_be32(0x003e0000), |
| 800 | }, |
| 801 | { |
| 802 | .mask = cpu_to_be32(0xffff0000), /* POWER7 */ |
| 803 | .val = cpu_to_be32(0x003f0000), |
| 804 | }, |
| 805 | { |
| 806 | .mask = cpu_to_be32(0xffff0000), /* POWER8E */ |
| 807 | .val = cpu_to_be32(0x004b0000), |
| 808 | }, |
| 809 | { |
| 810 | .mask = cpu_to_be32(0xffff0000), /* POWER8NVL */ |
| 811 | .val = cpu_to_be32(0x004c0000), |
| 812 | }, |
| 813 | { |
| 814 | .mask = cpu_to_be32(0xffff0000), /* POWER8 */ |
| 815 | .val = cpu_to_be32(0x004d0000), |
| 816 | }, |
| 817 | { |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 818 | .mask = cpu_to_be32(0xffff0000), /* POWER9 */ |
| 819 | .val = cpu_to_be32(0x004e0000), |
| 820 | }, |
| 821 | { |
| 822 | .mask = cpu_to_be32(0xffffffff), /* all 3.00-compliant */ |
| 823 | .val = cpu_to_be32(0x0f000005), |
| 824 | }, |
| 825 | { |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 826 | .mask = cpu_to_be32(0xffffffff), /* all 2.07-compliant */ |
| 827 | .val = cpu_to_be32(0x0f000004), |
| 828 | }, |
| 829 | { |
| 830 | .mask = cpu_to_be32(0xffffffff), /* all 2.06-compliant */ |
| 831 | .val = cpu_to_be32(0x0f000003), |
| 832 | }, |
| 833 | { |
| 834 | .mask = cpu_to_be32(0xffffffff), /* all 2.05-compliant */ |
| 835 | .val = cpu_to_be32(0x0f000002), |
| 836 | }, |
| 837 | { |
| 838 | .mask = cpu_to_be32(0xfffffffe), /* all 2.04-compliant and earlier */ |
| 839 | .val = cpu_to_be32(0x0f000001), |
| 840 | }, |
| 841 | }, |
| 842 | |
| 843 | .num_vectors = NUM_VECTORS(6), |
| 844 | |
| 845 | .vec1_len = VECTOR_LENGTH(sizeof(struct option_vector1)), |
| 846 | .vec1 = { |
| 847 | .byte1 = 0, |
| 848 | .arch_versions = OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 | |
| 849 | OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06 | OV1_PPC_2_07, |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 850 | .arch_versions3 = OV1_PPC_3_00, |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 851 | }, |
| 852 | |
| 853 | .vec2_len = VECTOR_LENGTH(sizeof(struct option_vector2)), |
| 854 | /* option vector 2: Open Firmware options supported */ |
| 855 | .vec2 = { |
| 856 | .byte1 = OV2_REAL_MODE, |
| 857 | .reserved = 0, |
| 858 | .real_base = cpu_to_be32(0xffffffff), |
| 859 | .real_size = cpu_to_be32(0xffffffff), |
| 860 | .virt_base = cpu_to_be32(0xffffffff), |
| 861 | .virt_size = cpu_to_be32(0xffffffff), |
| 862 | .load_base = cpu_to_be32(0xffffffff), |
Sukadev Bhattiprolu | 687da8f | 2017-03-27 19:43:14 -0400 | [diff] [blame] | 863 | .min_rma = cpu_to_be32(512), /* 512MB min RMA */ |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 864 | .min_load = cpu_to_be32(0xffffffff), /* full client load */ |
| 865 | .min_rma_percent = 0, /* min RMA percentage of total RAM */ |
| 866 | .max_pft_size = 48, /* max log_2(hash table size) */ |
| 867 | }, |
| 868 | |
| 869 | .vec3_len = VECTOR_LENGTH(sizeof(struct option_vector3)), |
| 870 | /* option vector 3: processor options supported */ |
| 871 | .vec3 = { |
| 872 | .byte1 = 0, /* don't ignore, don't halt */ |
| 873 | .byte2 = OV3_FP | OV3_VMX | OV3_DFP, |
| 874 | }, |
| 875 | |
| 876 | .vec4_len = VECTOR_LENGTH(sizeof(struct option_vector4)), |
| 877 | /* option vector 4: IBM PAPR implementation */ |
| 878 | .vec4 = { |
| 879 | .byte1 = 0, /* don't halt */ |
| 880 | .min_vp_cap = OV4_MIN_ENT_CAP, /* minimum VP entitled capacity */ |
| 881 | }, |
| 882 | |
| 883 | .vec5_len = VECTOR_LENGTH(sizeof(struct option_vector5)), |
| 884 | /* option vector 5: PAPR/OF options */ |
| 885 | .vec5 = { |
| 886 | .byte1 = 0, /* don't ignore, don't halt */ |
| 887 | .byte2 = OV5_FEAT(OV5_LPAR) | OV5_FEAT(OV5_SPLPAR) | OV5_FEAT(OV5_LARGE_PAGES) | |
| 888 | OV5_FEAT(OV5_DRCONF_MEMORY) | OV5_FEAT(OV5_DONATE_DEDICATE_CPU) | |
| 889 | #ifdef CONFIG_PCI_MSI |
| 890 | /* PCIe/MSI support. Without MSI full PCIe is not supported */ |
| 891 | OV5_FEAT(OV5_MSI), |
| 892 | #else |
| 893 | 0, |
| 894 | #endif |
| 895 | .byte3 = 0, |
| 896 | .cmo = |
| 897 | #ifdef CONFIG_PPC_SMLPAR |
| 898 | OV5_FEAT(OV5_CMO) | OV5_FEAT(OV5_XCMO), |
| 899 | #else |
| 900 | 0, |
| 901 | #endif |
| 902 | .associativity = OV5_FEAT(OV5_TYPE1_AFFINITY) | OV5_FEAT(OV5_PRRN), |
Michael Roth | 3dbbaf2 | 2017-02-20 19:12:18 -0600 | [diff] [blame] | 903 | .bin_opts = OV5_FEAT(OV5_RESIZE_HPT) | OV5_FEAT(OV5_HP_EVT), |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 904 | .micro_checkpoint = 0, |
| 905 | .reserved0 = 0, |
| 906 | .max_cpus = cpu_to_be32(NR_CPUS), /* number of cores supported */ |
| 907 | .papr_level = 0, |
| 908 | .reserved1 = 0, |
| 909 | .platform_facilities = OV5_FEAT(OV5_PFO_HW_RNG) | OV5_FEAT(OV5_PFO_HW_ENCR) | OV5_FEAT(OV5_PFO_HW_842), |
| 910 | .reserved2 = 0, |
| 911 | .reserved3 = 0, |
| 912 | .subprocessors = 1, |
Nathan Fontenot | 0c38ed6 | 2017-12-01 10:48:03 -0600 | [diff] [blame] | 913 | .byte22 = OV5_FEAT(OV5_DRMEM_V2), |
Paul Mackerras | cc3d294 | 2017-01-30 21:21:36 +1100 | [diff] [blame] | 914 | .intarch = 0, |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 915 | .mmu = 0, |
| 916 | .hash_ext = 0, |
| 917 | .radix_ext = 0, |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 918 | }, |
| 919 | |
| 920 | /* option vector 6: IBM PAPR hints */ |
| 921 | .vec6_len = VECTOR_LENGTH(sizeof(struct option_vector6)), |
| 922 | .vec6 = { |
| 923 | .reserved = 0, |
| 924 | .secondary_pteg = 0, |
| 925 | .os_name = OV6_LINUX, |
| 926 | }, |
| 927 | }; |
| 928 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 929 | /* Old method - ELF header with PT_NOTE sections only works on BE */ |
| 930 | #ifdef __BIG_ENDIAN__ |
Benjamin Herrenschmidt | 30c69ca | 2018-05-31 14:33:40 +1000 | [diff] [blame] | 931 | static const struct fake_elf { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 932 | Elf32_Ehdr elfhdr; |
| 933 | Elf32_Phdr phdr[2]; |
| 934 | struct chrpnote { |
| 935 | u32 namesz; |
| 936 | u32 descsz; |
| 937 | u32 type; |
| 938 | char name[8]; /* "PowerPC" */ |
| 939 | struct chrpdesc { |
| 940 | u32 real_mode; |
| 941 | u32 real_base; |
| 942 | u32 real_size; |
| 943 | u32 virt_base; |
| 944 | u32 virt_size; |
| 945 | u32 load_base; |
| 946 | } chrpdesc; |
| 947 | } chrpnote; |
| 948 | struct rpanote { |
| 949 | u32 namesz; |
| 950 | u32 descsz; |
| 951 | u32 type; |
| 952 | char name[24]; /* "IBM,RPA-Client-Config" */ |
| 953 | struct rpadesc { |
| 954 | u32 lpar_affinity; |
| 955 | u32 min_rmo_size; |
| 956 | u32 min_rmo_percent; |
| 957 | u32 max_pft_size; |
| 958 | u32 splpar; |
| 959 | u32 min_load; |
| 960 | u32 new_mem_def; |
| 961 | u32 ignore_me; |
| 962 | } rpadesc; |
| 963 | } rpanote; |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 964 | } fake_elf = { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 965 | .elfhdr = { |
| 966 | .e_ident = { 0x7f, 'E', 'L', 'F', |
| 967 | ELFCLASS32, ELFDATA2MSB, EV_CURRENT }, |
| 968 | .e_type = ET_EXEC, /* yeah right */ |
| 969 | .e_machine = EM_PPC, |
| 970 | .e_version = EV_CURRENT, |
| 971 | .e_phoff = offsetof(struct fake_elf, phdr), |
| 972 | .e_phentsize = sizeof(Elf32_Phdr), |
| 973 | .e_phnum = 2 |
| 974 | }, |
| 975 | .phdr = { |
| 976 | [0] = { |
| 977 | .p_type = PT_NOTE, |
| 978 | .p_offset = offsetof(struct fake_elf, chrpnote), |
| 979 | .p_filesz = sizeof(struct chrpnote) |
| 980 | }, [1] = { |
| 981 | .p_type = PT_NOTE, |
| 982 | .p_offset = offsetof(struct fake_elf, rpanote), |
| 983 | .p_filesz = sizeof(struct rpanote) |
| 984 | } |
| 985 | }, |
| 986 | .chrpnote = { |
| 987 | .namesz = sizeof("PowerPC"), |
| 988 | .descsz = sizeof(struct chrpdesc), |
| 989 | .type = 0x1275, |
| 990 | .name = "PowerPC", |
| 991 | .chrpdesc = { |
| 992 | .real_mode = ~0U, /* ~0 means "don't care" */ |
| 993 | .real_base = ~0U, |
| 994 | .real_size = ~0U, |
| 995 | .virt_base = ~0U, |
| 996 | .virt_size = ~0U, |
| 997 | .load_base = ~0U |
| 998 | }, |
| 999 | }, |
| 1000 | .rpanote = { |
| 1001 | .namesz = sizeof("IBM,RPA-Client-Config"), |
| 1002 | .descsz = sizeof(struct rpadesc), |
| 1003 | .type = 0x12759999, |
| 1004 | .name = "IBM,RPA-Client-Config", |
| 1005 | .rpadesc = { |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 1006 | .lpar_affinity = 0, |
| 1007 | .min_rmo_size = 64, /* in megabytes */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1008 | .min_rmo_percent = 0, |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 1009 | .max_pft_size = 48, /* 2^48 bytes max PFT size */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1010 | .splpar = 1, |
| 1011 | .min_load = ~0U, |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 1012 | .new_mem_def = 0 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | }; |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1016 | #endif /* __BIG_ENDIAN__ */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1017 | |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 1018 | static int __init prom_count_smt_threads(void) |
| 1019 | { |
| 1020 | phandle node; |
| 1021 | char type[64]; |
| 1022 | unsigned int plen; |
| 1023 | |
| 1024 | /* Pick up th first CPU node we can find */ |
| 1025 | for (node = 0; prom_next_node(&node); ) { |
| 1026 | type[0] = 0; |
| 1027 | prom_getprop(node, "device_type", type, sizeof(type)); |
| 1028 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1029 | if (strcmp(type, "cpu")) |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 1030 | continue; |
| 1031 | /* |
| 1032 | * There is an entry for each smt thread, each entry being |
| 1033 | * 4 bytes long. All cpus should have the same number of |
| 1034 | * smt threads, so return after finding the first. |
| 1035 | */ |
| 1036 | plen = prom_getproplen(node, "ibm,ppc-interrupt-server#s"); |
| 1037 | if (plen == PROM_ERROR) |
| 1038 | break; |
| 1039 | plen >>= 2; |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 1040 | prom_debug("Found %lu smt threads per core\n", (unsigned long)plen); |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 1041 | |
| 1042 | /* Sanity check */ |
| 1043 | if (plen < 1 || plen > 64) { |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 1044 | prom_printf("Threads per core %lu out of bounds, assuming 1\n", |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 1045 | (unsigned long)plen); |
| 1046 | return 1; |
| 1047 | } |
| 1048 | return plen; |
| 1049 | } |
| 1050 | prom_debug("No threads found, assuming 1 per core\n"); |
| 1051 | |
| 1052 | return 1; |
| 1053 | |
| 1054 | } |
| 1055 | |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1056 | static void __init prom_parse_mmu_model(u8 val, |
| 1057 | struct platform_support *support) |
| 1058 | { |
| 1059 | switch (val) { |
| 1060 | case OV5_FEAT(OV5_MMU_DYNAMIC): |
| 1061 | case OV5_FEAT(OV5_MMU_EITHER): /* Either Available */ |
| 1062 | prom_debug("MMU - either supported\n"); |
| 1063 | support->radix_mmu = !prom_radix_disable; |
| 1064 | support->hash_mmu = true; |
| 1065 | break; |
| 1066 | case OV5_FEAT(OV5_MMU_RADIX): /* Only Radix */ |
| 1067 | prom_debug("MMU - radix only\n"); |
| 1068 | if (prom_radix_disable) { |
| 1069 | /* |
| 1070 | * If we __have__ to do radix, we're better off ignoring |
| 1071 | * the command line rather than not booting. |
| 1072 | */ |
| 1073 | prom_printf("WARNING: Ignoring cmdline option disable_radix\n"); |
| 1074 | } |
| 1075 | support->radix_mmu = true; |
| 1076 | break; |
| 1077 | case OV5_FEAT(OV5_MMU_HASH): |
| 1078 | prom_debug("MMU - hash only\n"); |
| 1079 | support->hash_mmu = true; |
| 1080 | break; |
| 1081 | default: |
| 1082 | prom_debug("Unknown mmu support option: 0x%x\n", val); |
| 1083 | break; |
| 1084 | } |
| 1085 | } |
| 1086 | |
Cédric Le Goater | ac5e5a5 | 2017-08-30 21:46:16 +0200 | [diff] [blame] | 1087 | static void __init prom_parse_xive_model(u8 val, |
| 1088 | struct platform_support *support) |
| 1089 | { |
| 1090 | switch (val) { |
| 1091 | case OV5_FEAT(OV5_XIVE_EITHER): /* Either Available */ |
| 1092 | prom_debug("XIVE - either mode supported\n"); |
| 1093 | support->xive = true; |
| 1094 | break; |
| 1095 | case OV5_FEAT(OV5_XIVE_EXPLOIT): /* Only Exploitation mode */ |
| 1096 | prom_debug("XIVE - exploitation mode supported\n"); |
| 1097 | support->xive = true; |
| 1098 | break; |
| 1099 | case OV5_FEAT(OV5_XIVE_LEGACY): /* Only Legacy mode */ |
| 1100 | prom_debug("XIVE - legacy mode supported\n"); |
| 1101 | break; |
| 1102 | default: |
| 1103 | prom_debug("Unknown xive support option: 0x%x\n", val); |
| 1104 | break; |
| 1105 | } |
| 1106 | } |
| 1107 | |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1108 | static void __init prom_parse_platform_support(u8 index, u8 val, |
| 1109 | struct platform_support *support) |
| 1110 | { |
| 1111 | switch (index) { |
| 1112 | case OV5_INDX(OV5_MMU_SUPPORT): /* MMU Model */ |
| 1113 | prom_parse_mmu_model(val & OV5_FEAT(OV5_MMU_SUPPORT), support); |
| 1114 | break; |
| 1115 | case OV5_INDX(OV5_RADIX_GTSE): /* Radix Extensions */ |
| 1116 | if (val & OV5_FEAT(OV5_RADIX_GTSE)) { |
| 1117 | prom_debug("Radix - GTSE supported\n"); |
| 1118 | support->radix_gtse = true; |
| 1119 | } |
| 1120 | break; |
Cédric Le Goater | ac5e5a5 | 2017-08-30 21:46:16 +0200 | [diff] [blame] | 1121 | case OV5_INDX(OV5_XIVE_SUPPORT): /* Interrupt mode */ |
| 1122 | prom_parse_xive_model(val & OV5_FEAT(OV5_XIVE_SUPPORT), |
| 1123 | support); |
| 1124 | break; |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | static void __init prom_check_platform_support(void) |
| 1129 | { |
| 1130 | struct platform_support supported = { |
| 1131 | .hash_mmu = false, |
| 1132 | .radix_mmu = false, |
Cédric Le Goater | ac5e5a5 | 2017-08-30 21:46:16 +0200 | [diff] [blame] | 1133 | .radix_gtse = false, |
| 1134 | .xive = false |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1135 | }; |
| 1136 | int prop_len = prom_getproplen(prom.chosen, |
| 1137 | "ibm,arch-vec-5-platform-support"); |
| 1138 | if (prop_len > 1) { |
| 1139 | int i; |
Suraj Jitindar Singh | ab91239 | 2018-09-05 12:09:50 +1000 | [diff] [blame] | 1140 | u8 vec[8]; |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1141 | prom_debug("Found ibm,arch-vec-5-platform-support, len: %d\n", |
| 1142 | prop_len); |
Suraj Jitindar Singh | ab91239 | 2018-09-05 12:09:50 +1000 | [diff] [blame] | 1143 | if (prop_len > sizeof(vec)) |
| 1144 | prom_printf("WARNING: ibm,arch-vec-5-platform-support longer than expected (len: %d)\n", |
| 1145 | prop_len); |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1146 | prom_getprop(prom.chosen, "ibm,arch-vec-5-platform-support", |
| 1147 | &vec, sizeof(vec)); |
Suraj Jitindar Singh | ab91239 | 2018-09-05 12:09:50 +1000 | [diff] [blame] | 1148 | for (i = 0; i < sizeof(vec); i += 2) { |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1149 | prom_debug("%d: index = 0x%x val = 0x%x\n", i / 2 |
| 1150 | , vec[i] |
| 1151 | , vec[i + 1]); |
| 1152 | prom_parse_platform_support(vec[i], vec[i + 1], |
| 1153 | &supported); |
| 1154 | } |
| 1155 | } |
| 1156 | |
Alexey Kardashevskiy | 79b4686 | 2018-01-09 16:45:20 +1100 | [diff] [blame] | 1157 | if (supported.radix_mmu && supported.radix_gtse && |
| 1158 | IS_ENABLED(CONFIG_PPC_RADIX_MMU)) { |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1159 | /* Radix preferred - but we require GTSE for now */ |
| 1160 | prom_debug("Asking for radix with GTSE\n"); |
| 1161 | ibm_architecture_vec.vec5.mmu = OV5_FEAT(OV5_MMU_RADIX); |
| 1162 | ibm_architecture_vec.vec5.radix_ext = OV5_FEAT(OV5_RADIX_GTSE); |
| 1163 | } else if (supported.hash_mmu) { |
| 1164 | /* Default to hash mmu (if we can) */ |
| 1165 | prom_debug("Asking for hash\n"); |
| 1166 | ibm_architecture_vec.vec5.mmu = OV5_FEAT(OV5_MMU_HASH); |
| 1167 | } else { |
| 1168 | /* We're probably on a legacy hypervisor */ |
| 1169 | prom_debug("Assuming legacy hash support\n"); |
| 1170 | } |
Cédric Le Goater | ac5e5a5 | 2017-08-30 21:46:16 +0200 | [diff] [blame] | 1171 | |
| 1172 | if (supported.xive) { |
| 1173 | prom_debug("Asking for XIVE\n"); |
| 1174 | ibm_architecture_vec.vec5.intarch = OV5_FEAT(OV5_XIVE_EXPLOIT); |
| 1175 | } |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1176 | } |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 1177 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1178 | static void __init prom_send_capabilities(void) |
| 1179 | { |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1180 | ihandle root; |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 1181 | prom_arg_t ret; |
Laurent Dufour | dbd0c5d | 2013-09-17 11:52:48 +0200 | [diff] [blame] | 1182 | u32 cores; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1183 | |
Suraj Jitindar Singh | 014d02c | 2017-02-28 17:03:48 +1100 | [diff] [blame] | 1184 | /* Check ibm,arch-vec-5-platform-support and fixup vec5 if required */ |
| 1185 | prom_check_platform_support(); |
| 1186 | |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 1187 | root = call_prom("open", 1, 1, ADDR("/")); |
| 1188 | if (root != 0) { |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 1189 | /* We need to tell the FW about the number of cores we support. |
| 1190 | * |
| 1191 | * To do that, we count the number of threads on the first core |
| 1192 | * (we assume this is the same for all cores) and use it to |
| 1193 | * divide NR_CPUS. |
| 1194 | */ |
Laurent Dufour | dbd0c5d | 2013-09-17 11:52:48 +0200 | [diff] [blame] | 1195 | |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 1196 | cores = DIV_ROUND_UP(NR_CPUS, prom_count_smt_threads()); |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1197 | prom_printf("Max number of cores passed to firmware: %u (NR_CPUS = %d)\n", |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 1198 | cores, NR_CPUS); |
| 1199 | |
| 1200 | ibm_architecture_vec.vec5.max_cpus = cpu_to_be32(cores); |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 1201 | |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 1202 | /* try calling the ibm,client-architecture-support method */ |
Anton Blanchard | 049d049 | 2009-09-21 20:47:39 +0000 | [diff] [blame] | 1203 | prom_printf("Calling ibm,client-architecture-support..."); |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 1204 | if (call_prom_ret("call-method", 3, 2, &ret, |
| 1205 | ADDR("ibm,client-architecture-support"), |
Benjamin Herrenschmidt | 33b7497 | 2006-06-07 12:01:32 +1000 | [diff] [blame] | 1206 | root, |
Michael Ellerman | 76ffb57 | 2016-11-18 23:15:42 +1100 | [diff] [blame] | 1207 | ADDR(&ibm_architecture_vec)) == 0) { |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 1208 | /* the call exists... */ |
| 1209 | if (ret) |
Anton Blanchard | 4da727a | 2009-03-31 20:06:14 +0000 | [diff] [blame] | 1210 | prom_printf("\nWARNING: ibm,client-architecture" |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 1211 | "-support call FAILED!\n"); |
| 1212 | call_prom("close", 1, 0, root); |
Anton Blanchard | 4da727a | 2009-03-31 20:06:14 +0000 | [diff] [blame] | 1213 | prom_printf(" done\n"); |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 1214 | return; |
| 1215 | } |
| 1216 | call_prom("close", 1, 0, root); |
Anton Blanchard | 049d049 | 2009-09-21 20:47:39 +0000 | [diff] [blame] | 1217 | prom_printf(" not implemented\n"); |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 1218 | } |
| 1219 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1220 | #ifdef __BIG_ENDIAN__ |
| 1221 | { |
| 1222 | ihandle elfloader; |
| 1223 | |
| 1224 | /* no ibm,client-architecture-support call, try the old way */ |
| 1225 | elfloader = call_prom("open", 1, 1, |
| 1226 | ADDR("/packages/elf-loader")); |
| 1227 | if (elfloader == 0) { |
| 1228 | prom_printf("couldn't open /packages/elf-loader\n"); |
| 1229 | return; |
| 1230 | } |
| 1231 | call_prom("call-method", 3, 1, ADDR("process-elf-header"), |
| 1232 | elfloader, ADDR(&fake_elf)); |
| 1233 | call_prom("close", 1, 0, elfloader); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1234 | } |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1235 | #endif /* __BIG_ENDIAN__ */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1236 | } |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 1237 | #endif /* CONFIG_PPC_PSERIES */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1238 | |
| 1239 | /* |
| 1240 | * Memory allocation strategy... our layout is normally: |
| 1241 | * |
| 1242 | * at 14Mb or more we have vmlinux, then a gap and initrd. In some |
| 1243 | * rare cases, initrd might end up being before the kernel though. |
| 1244 | * We assume this won't override the final kernel at 0, we have no |
| 1245 | * provision to handle that in this version, but it should hopefully |
| 1246 | * never happen. |
| 1247 | * |
| 1248 | * alloc_top is set to the top of RMO, eventually shrink down if the |
| 1249 | * TCEs overlap |
| 1250 | * |
| 1251 | * alloc_bottom is set to the top of kernel/initrd |
| 1252 | * |
| 1253 | * from there, allocations are done this way : rtas is allocated |
| 1254 | * topmost, and the device-tree is allocated from the bottom. We try |
| 1255 | * to grow the device-tree allocation as we progress. If we can't, |
| 1256 | * then we fail, we don't currently have a facility to restart |
| 1257 | * elsewhere, but that shouldn't be necessary. |
| 1258 | * |
| 1259 | * Note that calls to reserve_mem have to be done explicitly, memory |
| 1260 | * allocated with either alloc_up or alloc_down isn't automatically |
| 1261 | * reserved. |
| 1262 | */ |
| 1263 | |
| 1264 | |
| 1265 | /* |
| 1266 | * Allocates memory in the RMO upward from the kernel/initrd |
| 1267 | * |
| 1268 | * When align is 0, this is a special case, it means to allocate in place |
| 1269 | * at the current location of alloc_bottom or fail (that is basically |
| 1270 | * extending the previous allocation). Used for the device-tree flattening |
| 1271 | */ |
| 1272 | static unsigned long __init alloc_up(unsigned long size, unsigned long align) |
| 1273 | { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1274 | unsigned long base = alloc_bottom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1275 | unsigned long addr = 0; |
| 1276 | |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1277 | if (align) |
| 1278 | base = _ALIGN_UP(base, align); |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1279 | prom_debug("%s(%lx, %lx)\n", __func__, size, align); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1280 | if (ram_top == 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1281 | prom_panic("alloc_up() called with mem not initialized\n"); |
| 1282 | |
| 1283 | if (align) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1284 | base = _ALIGN_UP(alloc_bottom, align); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1285 | else |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1286 | base = alloc_bottom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1287 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1288 | for(; (base + size) <= alloc_top; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1289 | base = _ALIGN_UP(base + 0x100000, align)) { |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1290 | prom_debug(" trying: 0x%lx\n\r", base); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1291 | addr = (unsigned long)prom_claim(base, size, 0); |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1292 | if (addr != PROM_ERROR && addr != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1293 | break; |
| 1294 | addr = 0; |
| 1295 | if (align == 0) |
| 1296 | break; |
| 1297 | } |
| 1298 | if (addr == 0) |
| 1299 | return 0; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1300 | alloc_bottom = addr + size; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1301 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1302 | prom_debug(" -> %lx\n", addr); |
| 1303 | prom_debug(" alloc_bottom : %lx\n", alloc_bottom); |
| 1304 | prom_debug(" alloc_top : %lx\n", alloc_top); |
| 1305 | prom_debug(" alloc_top_hi : %lx\n", alloc_top_high); |
| 1306 | prom_debug(" rmo_top : %lx\n", rmo_top); |
| 1307 | prom_debug(" ram_top : %lx\n", ram_top); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1308 | |
| 1309 | return addr; |
| 1310 | } |
| 1311 | |
| 1312 | /* |
| 1313 | * Allocates memory downward, either from top of RMO, or if highmem |
| 1314 | * is set, from the top of RAM. Note that this one doesn't handle |
| 1315 | * failures. It does claim memory if highmem is not set. |
| 1316 | */ |
| 1317 | static unsigned long __init alloc_down(unsigned long size, unsigned long align, |
| 1318 | int highmem) |
| 1319 | { |
| 1320 | unsigned long base, addr = 0; |
| 1321 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1322 | prom_debug("%s(%lx, %lx, %s)\n", __func__, size, align, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1323 | highmem ? "(high)" : "(low)"); |
| 1324 | if (ram_top == 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1325 | prom_panic("alloc_down() called with mem not initialized\n"); |
| 1326 | |
| 1327 | if (highmem) { |
| 1328 | /* Carve out storage for the TCE table. */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1329 | addr = _ALIGN_DOWN(alloc_top_high - size, align); |
| 1330 | if (addr <= alloc_bottom) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1331 | return 0; |
| 1332 | /* Will we bump into the RMO ? If yes, check out that we |
| 1333 | * didn't overlap existing allocations there, if we did, |
| 1334 | * we are dead, we must be the first in town ! |
| 1335 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1336 | if (addr < rmo_top) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1337 | /* Good, we are first */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1338 | if (alloc_top == rmo_top) |
| 1339 | alloc_top = rmo_top = addr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1340 | else |
| 1341 | return 0; |
| 1342 | } |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1343 | alloc_top_high = addr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1344 | goto bail; |
| 1345 | } |
| 1346 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1347 | base = _ALIGN_DOWN(alloc_top - size, align); |
| 1348 | for (; base > alloc_bottom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1349 | base = _ALIGN_DOWN(base - 0x100000, align)) { |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1350 | prom_debug(" trying: 0x%lx\n\r", base); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1351 | addr = (unsigned long)prom_claim(base, size, 0); |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1352 | if (addr != PROM_ERROR && addr != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1353 | break; |
| 1354 | addr = 0; |
| 1355 | } |
| 1356 | if (addr == 0) |
| 1357 | return 0; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1358 | alloc_top = addr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1359 | |
| 1360 | bail: |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1361 | prom_debug(" -> %lx\n", addr); |
| 1362 | prom_debug(" alloc_bottom : %lx\n", alloc_bottom); |
| 1363 | prom_debug(" alloc_top : %lx\n", alloc_top); |
| 1364 | prom_debug(" alloc_top_hi : %lx\n", alloc_top_high); |
| 1365 | prom_debug(" rmo_top : %lx\n", rmo_top); |
| 1366 | prom_debug(" ram_top : %lx\n", ram_top); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1367 | |
| 1368 | return addr; |
| 1369 | } |
| 1370 | |
| 1371 | /* |
| 1372 | * Parse a "reg" cell |
| 1373 | */ |
| 1374 | static unsigned long __init prom_next_cell(int s, cell_t **cellp) |
| 1375 | { |
| 1376 | cell_t *p = *cellp; |
| 1377 | unsigned long r = 0; |
| 1378 | |
| 1379 | /* Ignore more than 2 cells */ |
| 1380 | while (s > sizeof(unsigned long) / 4) { |
| 1381 | p++; |
| 1382 | s--; |
| 1383 | } |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1384 | r = be32_to_cpu(*p++); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1385 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1386 | if (s > 1) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1387 | r <<= 32; |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1388 | r |= be32_to_cpu(*(p++)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1389 | } |
| 1390 | #endif |
| 1391 | *cellp = p; |
| 1392 | return r; |
| 1393 | } |
| 1394 | |
| 1395 | /* |
| 1396 | * Very dumb function for adding to the memory reserve list, but |
| 1397 | * we don't need anything smarter at this point |
| 1398 | * |
| 1399 | * XXX Eventually check for collisions. They should NEVER happen. |
| 1400 | * If problems seem to show up, it would be a good start to track |
| 1401 | * them down. |
| 1402 | */ |
Michael Ellerman | 0108d3f | 2007-05-07 15:58:28 +1000 | [diff] [blame] | 1403 | static void __init reserve_mem(u64 base, u64 size) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1404 | { |
Kumar Gala | cbbcf34 | 2006-01-11 17:57:13 -0600 | [diff] [blame] | 1405 | u64 top = base + size; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1406 | unsigned long cnt = mem_reserve_cnt; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1407 | |
| 1408 | if (size == 0) |
| 1409 | return; |
| 1410 | |
| 1411 | /* We need to always keep one empty entry so that we |
| 1412 | * have our terminator with "size" set to 0 since we are |
| 1413 | * dumb and just copy this entire array to the boot params |
| 1414 | */ |
| 1415 | base = _ALIGN_DOWN(base, PAGE_SIZE); |
| 1416 | top = _ALIGN_UP(top, PAGE_SIZE); |
| 1417 | size = top - base; |
| 1418 | |
| 1419 | if (cnt >= (MEM_RESERVE_MAP_SIZE - 1)) |
| 1420 | prom_panic("Memory reserve map exhausted !\n"); |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1421 | mem_reserve_map[cnt].base = cpu_to_be64(base); |
| 1422 | mem_reserve_map[cnt].size = cpu_to_be64(size); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1423 | mem_reserve_cnt = cnt + 1; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | /* |
Adrian Bunk | b3c2ffd | 2006-06-30 18:20:44 +0200 | [diff] [blame] | 1427 | * Initialize memory allocation mechanism, parse "memory" nodes and |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1428 | * obtain that way the top of memory and RMO to setup out local allocator |
| 1429 | */ |
| 1430 | static void __init prom_init_mem(void) |
| 1431 | { |
| 1432 | phandle node; |
Mathieu Malaterre | eab00a2 | 2018-04-04 22:08:35 +0200 | [diff] [blame] | 1433 | #ifdef DEBUG_PROM |
| 1434 | char *path; |
| 1435 | #endif |
| 1436 | char type[64]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1437 | unsigned int plen; |
| 1438 | cell_t *p, *endp; |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1439 | __be32 val; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1440 | u32 rac, rsc; |
| 1441 | |
| 1442 | /* |
| 1443 | * We iterate the memory nodes to find |
| 1444 | * 1) top of RMO (first node) |
| 1445 | * 2) top of memory |
| 1446 | */ |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1447 | val = cpu_to_be32(2); |
| 1448 | prom_getprop(prom.root, "#address-cells", &val, sizeof(val)); |
| 1449 | rac = be32_to_cpu(val); |
| 1450 | val = cpu_to_be32(1); |
| 1451 | prom_getprop(prom.root, "#size-cells", &val, sizeof(rsc)); |
| 1452 | rsc = be32_to_cpu(val); |
| 1453 | prom_debug("root_addr_cells: %x\n", rac); |
| 1454 | prom_debug("root_size_cells: %x\n", rsc); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1455 | |
| 1456 | prom_debug("scanning memory:\n"); |
Mathieu Malaterre | eab00a2 | 2018-04-04 22:08:35 +0200 | [diff] [blame] | 1457 | #ifdef DEBUG_PROM |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1458 | path = prom_scratch; |
Mathieu Malaterre | eab00a2 | 2018-04-04 22:08:35 +0200 | [diff] [blame] | 1459 | #endif |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1460 | |
| 1461 | for (node = 0; prom_next_node(&node); ) { |
| 1462 | type[0] = 0; |
| 1463 | prom_getprop(node, "device_type", type, sizeof(type)); |
| 1464 | |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1465 | if (type[0] == 0) { |
| 1466 | /* |
| 1467 | * CHRP Longtrail machines have no device_type |
| 1468 | * on the memory node, so check the name instead... |
| 1469 | */ |
| 1470 | prom_getprop(node, "name", type, sizeof(type)); |
| 1471 | } |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1472 | if (strcmp(type, "memory")) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1473 | continue; |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1474 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1475 | plen = prom_getprop(node, "reg", regbuf, sizeof(regbuf)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1476 | if (plen > sizeof(regbuf)) { |
| 1477 | prom_printf("memory node too large for buffer !\n"); |
| 1478 | plen = sizeof(regbuf); |
| 1479 | } |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1480 | p = regbuf; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1481 | endp = p + (plen / sizeof(cell_t)); |
| 1482 | |
| 1483 | #ifdef DEBUG_PROM |
| 1484 | memset(path, 0, PROM_SCRATCH_SIZE); |
| 1485 | call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1); |
| 1486 | prom_debug(" node %s :\n", path); |
| 1487 | #endif /* DEBUG_PROM */ |
| 1488 | |
| 1489 | while ((endp - p) >= (rac + rsc)) { |
| 1490 | unsigned long base, size; |
| 1491 | |
| 1492 | base = prom_next_cell(rac, &p); |
| 1493 | size = prom_next_cell(rsc, &p); |
| 1494 | |
| 1495 | if (size == 0) |
| 1496 | continue; |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1497 | prom_debug(" %lx %lx\n", base, size); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1498 | if (base == 0 && (of_platform & PLATFORM_LPAR)) |
| 1499 | rmo_top = size; |
| 1500 | if ((base + size) > ram_top) |
| 1501 | ram_top = base + size; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1505 | alloc_bottom = PAGE_ALIGN((unsigned long)&_end + 0x4000); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1506 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1507 | /* |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1508 | * If prom_memory_limit is set we reduce the upper limits *except* for |
| 1509 | * alloc_top_high. This must be the real top of RAM so we can put |
| 1510 | * TCE's up there. |
| 1511 | */ |
| 1512 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1513 | alloc_top_high = ram_top; |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1514 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1515 | if (prom_memory_limit) { |
| 1516 | if (prom_memory_limit <= alloc_bottom) { |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1517 | prom_printf("Ignoring mem=%lx <= alloc_bottom.\n", |
| 1518 | prom_memory_limit); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1519 | prom_memory_limit = 0; |
| 1520 | } else if (prom_memory_limit >= ram_top) { |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1521 | prom_printf("Ignoring mem=%lx >= ram_top.\n", |
| 1522 | prom_memory_limit); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1523 | prom_memory_limit = 0; |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1524 | } else { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1525 | ram_top = prom_memory_limit; |
| 1526 | rmo_top = min(rmo_top, prom_memory_limit); |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1531 | * Setup our top alloc point, that is top of RMO or top of |
| 1532 | * segment 0 when running non-LPAR. |
| 1533 | * Some RS64 machines have buggy firmware where claims up at |
| 1534 | * 1GB fail. Cap at 768MB as a workaround. |
| 1535 | * Since 768MB is plenty of room, and we need to cap to something |
| 1536 | * reasonable on 32-bit, cap at 768MB on all machines. |
| 1537 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1538 | if (!rmo_top) |
| 1539 | rmo_top = ram_top; |
| 1540 | rmo_top = min(0x30000000ul, rmo_top); |
| 1541 | alloc_top = rmo_top; |
| 1542 | alloc_top_high = ram_top; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1543 | |
Paul Mackerras | 64968f6 | 2011-12-13 17:54:13 +0000 | [diff] [blame] | 1544 | /* |
| 1545 | * Check if we have an initrd after the kernel but still inside |
| 1546 | * the RMO. If we do move our bottom point to after it. |
| 1547 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1548 | if (prom_initrd_start && |
| 1549 | prom_initrd_start < rmo_top && |
| 1550 | prom_initrd_end > alloc_bottom) |
| 1551 | alloc_bottom = PAGE_ALIGN(prom_initrd_end); |
Paul Mackerras | 64968f6 | 2011-12-13 17:54:13 +0000 | [diff] [blame] | 1552 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1553 | prom_printf("memory layout at init:\n"); |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1554 | prom_printf(" memory_limit : %lx (16 MB aligned)\n", |
| 1555 | prom_memory_limit); |
| 1556 | prom_printf(" alloc_bottom : %lx\n", alloc_bottom); |
| 1557 | prom_printf(" alloc_top : %lx\n", alloc_top); |
| 1558 | prom_printf(" alloc_top_hi : %lx\n", alloc_top_high); |
| 1559 | prom_printf(" rmo_top : %lx\n", rmo_top); |
| 1560 | prom_printf(" ram_top : %lx\n", ram_top); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1561 | } |
| 1562 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1563 | static void __init prom_close_stdin(void) |
| 1564 | { |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1565 | __be32 val; |
| 1566 | ihandle stdin; |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1567 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1568 | if (prom_getprop(prom.chosen, "stdin", &val, sizeof(val)) > 0) { |
| 1569 | stdin = be32_to_cpu(val); |
| 1570 | call_prom("close", 1, 0, stdin); |
| 1571 | } |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1574 | /* |
| 1575 | * Allocate room for and instantiate RTAS |
| 1576 | */ |
| 1577 | static void __init prom_instantiate_rtas(void) |
| 1578 | { |
| 1579 | phandle rtas_node; |
| 1580 | ihandle rtas_inst; |
| 1581 | u32 base, entry = 0; |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1582 | __be32 val; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1583 | u32 size = 0; |
| 1584 | |
| 1585 | prom_debug("prom_instantiate_rtas: start...\n"); |
| 1586 | |
| 1587 | rtas_node = call_prom("finddevice", 1, 1, ADDR("/rtas")); |
| 1588 | prom_debug("rtas_node: %x\n", rtas_node); |
| 1589 | if (!PHANDLE_VALID(rtas_node)) |
| 1590 | return; |
| 1591 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1592 | val = 0; |
| 1593 | prom_getprop(rtas_node, "rtas-size", &val, sizeof(size)); |
| 1594 | size = be32_to_cpu(val); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1595 | if (size == 0) |
| 1596 | return; |
| 1597 | |
| 1598 | base = alloc_down(size, PAGE_SIZE, 0); |
Anton Blanchard | 6d1e2c6 | 2011-11-14 12:55:47 +0000 | [diff] [blame] | 1599 | if (base == 0) |
| 1600 | prom_panic("Could not allocate memory for RTAS\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1601 | |
| 1602 | rtas_inst = call_prom("open", 1, 1, ADDR("/rtas")); |
| 1603 | if (!IHANDLE_VALID(rtas_inst)) { |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1604 | prom_printf("opening rtas package failed (%x)\n", rtas_inst); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1605 | return; |
| 1606 | } |
| 1607 | |
Anton Blanchard | 1f8737a | 2009-03-31 20:06:15 +0000 | [diff] [blame] | 1608 | prom_printf("instantiating rtas at 0x%x...", base); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1609 | |
| 1610 | if (call_prom_ret("call-method", 3, 2, &entry, |
| 1611 | ADDR("instantiate-rtas"), |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1612 | rtas_inst, base) != 0 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1613 | || entry == 0) { |
| 1614 | prom_printf(" failed\n"); |
| 1615 | return; |
| 1616 | } |
| 1617 | prom_printf(" done\n"); |
| 1618 | |
| 1619 | reserve_mem(base, size); |
| 1620 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1621 | val = cpu_to_be32(base); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1622 | prom_setprop(rtas_node, "/rtas", "linux,rtas-base", |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1623 | &val, sizeof(val)); |
| 1624 | val = cpu_to_be32(entry); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1625 | prom_setprop(rtas_node, "/rtas", "linux,rtas-entry", |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1626 | &val, sizeof(val)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1627 | |
Benjamin Herrenschmidt | dbe78b4 | 2013-09-25 14:02:50 +1000 | [diff] [blame] | 1628 | /* Check if it supports "query-cpu-stopped-state" */ |
| 1629 | if (prom_getprop(rtas_node, "query-cpu-stopped-state", |
| 1630 | &val, sizeof(val)) != PROM_ERROR) |
| 1631 | rtas_has_query_cpu_stopped = true; |
| 1632 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1633 | prom_debug("rtas base = 0x%x\n", base); |
| 1634 | prom_debug("rtas entry = 0x%x\n", entry); |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1635 | prom_debug("rtas size = 0x%x\n", size); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1636 | |
| 1637 | prom_debug("prom_instantiate_rtas: end...\n"); |
| 1638 | } |
| 1639 | |
| 1640 | #ifdef CONFIG_PPC64 |
| 1641 | /* |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1642 | * Allocate room for and instantiate Stored Measurement Log (SML) |
| 1643 | */ |
| 1644 | static void __init prom_instantiate_sml(void) |
| 1645 | { |
| 1646 | phandle ibmvtpm_node; |
| 1647 | ihandle ibmvtpm_inst; |
Hon Ching \(Vicky\) Lo | b4ed046 | 2015-10-07 20:11:53 -0400 | [diff] [blame] | 1648 | u32 entry = 0, size = 0, succ = 0; |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1649 | u64 base; |
Hon Ching \(Vicky\) Lo | b4ed046 | 2015-10-07 20:11:53 -0400 | [diff] [blame] | 1650 | __be32 val; |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1651 | |
| 1652 | prom_debug("prom_instantiate_sml: start...\n"); |
| 1653 | |
Hon Ching \(Vicky\) Lo | 2f82e98 | 2015-10-07 20:11:52 -0400 | [diff] [blame] | 1654 | ibmvtpm_node = call_prom("finddevice", 1, 1, ADDR("/vdevice/vtpm")); |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1655 | prom_debug("ibmvtpm_node: %x\n", ibmvtpm_node); |
| 1656 | if (!PHANDLE_VALID(ibmvtpm_node)) |
| 1657 | return; |
| 1658 | |
Hon Ching \(Vicky\) Lo | 2f82e98 | 2015-10-07 20:11:52 -0400 | [diff] [blame] | 1659 | ibmvtpm_inst = call_prom("open", 1, 1, ADDR("/vdevice/vtpm")); |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1660 | if (!IHANDLE_VALID(ibmvtpm_inst)) { |
| 1661 | prom_printf("opening vtpm package failed (%x)\n", ibmvtpm_inst); |
| 1662 | return; |
| 1663 | } |
| 1664 | |
Hon Ching \(Vicky\) Lo | b4ed046 | 2015-10-07 20:11:53 -0400 | [diff] [blame] | 1665 | if (prom_getprop(ibmvtpm_node, "ibm,sml-efi-reformat-supported", |
| 1666 | &val, sizeof(val)) != PROM_ERROR) { |
| 1667 | if (call_prom_ret("call-method", 2, 2, &succ, |
| 1668 | ADDR("reformat-sml-to-efi-alignment"), |
| 1669 | ibmvtpm_inst) != 0 || succ == 0) { |
| 1670 | prom_printf("Reformat SML to EFI alignment failed\n"); |
| 1671 | return; |
| 1672 | } |
Hon Ching \(Vicky\) Lo | b4ed046 | 2015-10-07 20:11:53 -0400 | [diff] [blame] | 1673 | |
Hon Ching \(Vicky\) Lo | 9e5d4af | 2015-10-07 20:11:54 -0400 | [diff] [blame] | 1674 | if (call_prom_ret("call-method", 2, 2, &size, |
| 1675 | ADDR("sml-get-allocated-size"), |
| 1676 | ibmvtpm_inst) != 0 || size == 0) { |
| 1677 | prom_printf("SML get allocated size failed\n"); |
| 1678 | return; |
| 1679 | } |
| 1680 | } else { |
| 1681 | if (call_prom_ret("call-method", 2, 2, &size, |
| 1682 | ADDR("sml-get-handover-size"), |
| 1683 | ibmvtpm_inst) != 0 || size == 0) { |
| 1684 | prom_printf("SML get handover size failed\n"); |
| 1685 | return; |
| 1686 | } |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | base = alloc_down(size, PAGE_SIZE, 0); |
| 1690 | if (base == 0) |
| 1691 | prom_panic("Could not allocate memory for sml\n"); |
| 1692 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1693 | prom_printf("instantiating sml at 0x%llx...", base); |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1694 | |
Hon Ching \(Vicky\) Lo | 9e5d4af | 2015-10-07 20:11:54 -0400 | [diff] [blame] | 1695 | memset((void *)base, 0, size); |
| 1696 | |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1697 | if (call_prom_ret("call-method", 4, 2, &entry, |
| 1698 | ADDR("sml-handover"), |
| 1699 | ibmvtpm_inst, size, base) != 0 || entry == 0) { |
| 1700 | prom_printf("SML handover failed\n"); |
| 1701 | return; |
| 1702 | } |
| 1703 | prom_printf(" done\n"); |
| 1704 | |
| 1705 | reserve_mem(base, size); |
| 1706 | |
Hon Ching \(Vicky\) Lo | 2f82e98 | 2015-10-07 20:11:52 -0400 | [diff] [blame] | 1707 | prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-base", |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1708 | &base, sizeof(base)); |
Hon Ching \(Vicky\) Lo | 2f82e98 | 2015-10-07 20:11:52 -0400 | [diff] [blame] | 1709 | prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-size", |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1710 | &size, sizeof(size)); |
| 1711 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1712 | prom_debug("sml base = 0x%llx\n", base); |
| 1713 | prom_debug("sml size = 0x%x\n", size); |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1714 | |
| 1715 | prom_debug("prom_instantiate_sml: end...\n"); |
| 1716 | } |
| 1717 | |
| 1718 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1719 | * Allocate room for and initialize TCE tables |
| 1720 | */ |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1721 | #ifdef __BIG_ENDIAN__ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1722 | static void __init prom_initialize_tce_table(void) |
| 1723 | { |
| 1724 | phandle node; |
| 1725 | ihandle phb_node; |
| 1726 | char compatible[64], type[64], model[64]; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1727 | char *path = prom_scratch; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1728 | u64 base, align; |
| 1729 | u32 minalign, minsize; |
| 1730 | u64 tce_entry, *tce_entryp; |
| 1731 | u64 local_alloc_top, local_alloc_bottom; |
| 1732 | u64 i; |
| 1733 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1734 | if (prom_iommu_off) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1735 | return; |
| 1736 | |
| 1737 | prom_debug("starting prom_initialize_tce_table\n"); |
| 1738 | |
| 1739 | /* Cache current top of allocs so we reserve a single block */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1740 | local_alloc_top = alloc_top_high; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1741 | local_alloc_bottom = local_alloc_top; |
| 1742 | |
| 1743 | /* Search all nodes looking for PHBs. */ |
| 1744 | for (node = 0; prom_next_node(&node); ) { |
| 1745 | compatible[0] = 0; |
| 1746 | type[0] = 0; |
| 1747 | model[0] = 0; |
| 1748 | prom_getprop(node, "compatible", |
| 1749 | compatible, sizeof(compatible)); |
| 1750 | prom_getprop(node, "device_type", type, sizeof(type)); |
| 1751 | prom_getprop(node, "model", model, sizeof(model)); |
| 1752 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1753 | if ((type[0] == 0) || (strstr(type, "pci") == NULL)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1754 | continue; |
| 1755 | |
Linas Vepstas | e788ff1 | 2007-09-07 03:45:21 +1000 | [diff] [blame] | 1756 | /* Keep the old logic intact to avoid regression. */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1757 | if (compatible[0] != 0) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1758 | if ((strstr(compatible, "python") == NULL) && |
| 1759 | (strstr(compatible, "Speedwagon") == NULL) && |
| 1760 | (strstr(compatible, "Winnipeg") == NULL)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1761 | continue; |
| 1762 | } else if (model[0] != 0) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1763 | if ((strstr(model, "ython") == NULL) && |
| 1764 | (strstr(model, "peedwagon") == NULL) && |
| 1765 | (strstr(model, "innipeg") == NULL)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1766 | continue; |
| 1767 | } |
| 1768 | |
| 1769 | if (prom_getprop(node, "tce-table-minalign", &minalign, |
| 1770 | sizeof(minalign)) == PROM_ERROR) |
| 1771 | minalign = 0; |
| 1772 | if (prom_getprop(node, "tce-table-minsize", &minsize, |
| 1773 | sizeof(minsize)) == PROM_ERROR) |
| 1774 | minsize = 4UL << 20; |
| 1775 | |
| 1776 | /* |
| 1777 | * Even though we read what OF wants, we just set the table |
| 1778 | * size to 4 MB. This is enough to map 2GB of PCI DMA space. |
| 1779 | * By doing this, we avoid the pitfalls of trying to DMA to |
| 1780 | * MMIO space and the DMA alias hole. |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1781 | */ |
Nicholas Piggin | 471d7ff | 2018-02-21 05:08:29 +1000 | [diff] [blame] | 1782 | minsize = 4UL << 20; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1783 | |
| 1784 | /* Align to the greater of the align or size */ |
| 1785 | align = max(minalign, minsize); |
| 1786 | base = alloc_down(minsize, align, 1); |
| 1787 | if (base == 0) |
| 1788 | prom_panic("ERROR, cannot find space for TCE table.\n"); |
| 1789 | if (base < local_alloc_bottom) |
| 1790 | local_alloc_bottom = base; |
| 1791 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1792 | /* It seems OF doesn't null-terminate the path :-( */ |
Li Zefan | aca71ef | 2007-11-05 13:21:56 +1100 | [diff] [blame] | 1793 | memset(path, 0, PROM_SCRATCH_SIZE); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1794 | /* Call OF to setup the TCE hardware */ |
| 1795 | if (call_prom("package-to-path", 3, 1, node, |
| 1796 | path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) { |
| 1797 | prom_printf("package-to-path failed\n"); |
| 1798 | } |
| 1799 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1800 | /* Save away the TCE table attributes for later use. */ |
| 1801 | prom_setprop(node, path, "linux,tce-base", &base, sizeof(base)); |
| 1802 | prom_setprop(node, path, "linux,tce-size", &minsize, sizeof(minsize)); |
| 1803 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1804 | prom_debug("TCE table: %s\n", path); |
| 1805 | prom_debug("\tnode = 0x%x\n", node); |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1806 | prom_debug("\tbase = 0x%llx\n", base); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1807 | prom_debug("\tsize = 0x%x\n", minsize); |
| 1808 | |
| 1809 | /* Initialize the table to have a one-to-one mapping |
| 1810 | * over the allocated size. |
| 1811 | */ |
Ingo Molnar | 2b931fb | 2009-01-06 13:56:52 +0000 | [diff] [blame] | 1812 | tce_entryp = (u64 *)base; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1813 | for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) { |
| 1814 | tce_entry = (i << PAGE_SHIFT); |
| 1815 | tce_entry |= 0x3; |
| 1816 | *tce_entryp = tce_entry; |
| 1817 | } |
| 1818 | |
| 1819 | prom_printf("opening PHB %s", path); |
| 1820 | phb_node = call_prom("open", 1, 1, path); |
| 1821 | if (phb_node == 0) |
| 1822 | prom_printf("... failed\n"); |
| 1823 | else |
| 1824 | prom_printf("... done\n"); |
| 1825 | |
| 1826 | call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"), |
| 1827 | phb_node, -1, minsize, |
| 1828 | (u32) base, (u32) (base >> 32)); |
| 1829 | call_prom("close", 1, 0, phb_node); |
| 1830 | } |
| 1831 | |
| 1832 | reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom); |
| 1833 | |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 1834 | /* These are only really needed if there is a memory limit in |
| 1835 | * effect, but we don't know so export them always. */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1836 | prom_tce_alloc_start = local_alloc_bottom; |
| 1837 | prom_tce_alloc_end = local_alloc_top; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1838 | |
| 1839 | /* Flag the first invalid entry */ |
| 1840 | prom_debug("ending prom_initialize_tce_table\n"); |
| 1841 | } |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1842 | #endif /* __BIG_ENDIAN__ */ |
| 1843 | #endif /* CONFIG_PPC64 */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1844 | |
| 1845 | /* |
| 1846 | * With CHRP SMP we need to use the OF to start the other processors. |
| 1847 | * We can't wait until smp_boot_cpus (the OF is trashed by then) |
| 1848 | * so we have to put the processors into a holding pattern controlled |
| 1849 | * by the kernel (not OF) before we destroy the OF. |
| 1850 | * |
| 1851 | * This uses a chunk of low memory, puts some holding pattern |
| 1852 | * code there and sends the other processors off to there until |
| 1853 | * smp_boot_cpus tells them to do something. The holding pattern |
| 1854 | * checks that address until its cpu # is there, when it is that |
| 1855 | * cpu jumps to __secondary_start(). smp_boot_cpus() takes care |
| 1856 | * of setting those values. |
| 1857 | * |
| 1858 | * We also use physical address 0x4 here to tell when a cpu |
| 1859 | * is in its holding pattern code. |
| 1860 | * |
| 1861 | * -- Cort |
| 1862 | */ |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1863 | /* |
| 1864 | * We want to reference the copy of __secondary_hold_* in the |
| 1865 | * 0 - 0x100 address range |
| 1866 | */ |
| 1867 | #define LOW_ADDR(x) (((unsigned long) &(x)) & 0xff) |
| 1868 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1869 | static void __init prom_hold_cpus(void) |
| 1870 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1871 | unsigned long i; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1872 | phandle node; |
| 1873 | char type[64]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1874 | unsigned long *spinloop |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1875 | = (void *) LOW_ADDR(__secondary_hold_spinloop); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1876 | unsigned long *acknowledge |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1877 | = (void *) LOW_ADDR(__secondary_hold_acknowledge); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1878 | unsigned long secondary_hold = LOW_ADDR(__secondary_hold); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1879 | |
Benjamin Herrenschmidt | dbe78b4 | 2013-09-25 14:02:50 +1000 | [diff] [blame] | 1880 | /* |
| 1881 | * On pseries, if RTAS supports "query-cpu-stopped-state", |
| 1882 | * we skip this stage, the CPUs will be started by the |
| 1883 | * kernel using RTAS. |
| 1884 | */ |
| 1885 | if ((of_platform == PLATFORM_PSERIES || |
| 1886 | of_platform == PLATFORM_PSERIES_LPAR) && |
| 1887 | rtas_has_query_cpu_stopped) { |
| 1888 | prom_printf("prom_hold_cpus: skipped\n"); |
| 1889 | return; |
| 1890 | } |
| 1891 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1892 | prom_debug("prom_hold_cpus: start...\n"); |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1893 | prom_debug(" 1) spinloop = 0x%lx\n", (unsigned long)spinloop); |
| 1894 | prom_debug(" 1) *spinloop = 0x%lx\n", *spinloop); |
| 1895 | prom_debug(" 1) acknowledge = 0x%lx\n", |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1896 | (unsigned long)acknowledge); |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1897 | prom_debug(" 1) *acknowledge = 0x%lx\n", *acknowledge); |
| 1898 | prom_debug(" 1) secondary_hold = 0x%lx\n", secondary_hold); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1899 | |
| 1900 | /* Set the common spinloop variable, so all of the secondary cpus |
| 1901 | * will block when they are awakened from their OF spinloop. |
| 1902 | * This must occur for both SMP and non SMP kernels, since OF will |
| 1903 | * be trashed when we move the kernel. |
| 1904 | */ |
| 1905 | *spinloop = 0; |
| 1906 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1907 | /* look for cpus */ |
| 1908 | for (node = 0; prom_next_node(&node); ) { |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1909 | unsigned int cpu_no; |
| 1910 | __be32 reg; |
| 1911 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1912 | type[0] = 0; |
| 1913 | prom_getprop(node, "device_type", type, sizeof(type)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1914 | if (strcmp(type, "cpu") != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1915 | continue; |
| 1916 | |
| 1917 | /* Skip non-configured cpus. */ |
| 1918 | if (prom_getprop(node, "status", type, sizeof(type)) > 0) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1919 | if (strcmp(type, "okay") != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1920 | continue; |
| 1921 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1922 | reg = cpu_to_be32(-1); /* make sparse happy */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1923 | prom_getprop(node, "reg", ®, sizeof(reg)); |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1924 | cpu_no = be32_to_cpu(reg); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1925 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1926 | prom_debug("cpu hw idx = %u\n", cpu_no); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1927 | |
| 1928 | /* Init the acknowledge var which will be reset by |
| 1929 | * the secondary cpu when it awakens from its OF |
| 1930 | * spinloop. |
| 1931 | */ |
| 1932 | *acknowledge = (unsigned long)-1; |
| 1933 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1934 | if (cpu_no != prom.cpu) { |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1935 | /* Primary Thread of non-boot cpu or any thread */ |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1936 | prom_printf("starting cpu hw idx %u... ", cpu_no); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1937 | call_prom("start-cpu", 3, 0, node, |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1938 | secondary_hold, cpu_no); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1939 | |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1940 | for (i = 0; (i < 100000000) && |
| 1941 | (*acknowledge == ((unsigned long)-1)); i++ ) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1942 | mb(); |
| 1943 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 1944 | if (*acknowledge == cpu_no) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1945 | prom_printf("done\n"); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1946 | else |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1947 | prom_printf("failed: %lx\n", *acknowledge); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1948 | } |
| 1949 | #ifdef CONFIG_SMP |
| 1950 | else |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 1951 | prom_printf("boot cpu hw idx %u\n", cpu_no); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1952 | #endif /* CONFIG_SMP */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1953 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1954 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1955 | prom_debug("prom_hold_cpus: end...\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | |
| 1959 | static void __init prom_init_client_services(unsigned long pp) |
| 1960 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1961 | /* Get a handle to the prom entry point before anything else */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1962 | prom_entry = pp; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1963 | |
| 1964 | /* get a handle for the stdout device */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1965 | prom.chosen = call_prom("finddevice", 1, 1, ADDR("/chosen")); |
| 1966 | if (!PHANDLE_VALID(prom.chosen)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1967 | prom_panic("cannot find chosen"); /* msg won't be printed :( */ |
| 1968 | |
| 1969 | /* get device tree root */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1970 | prom.root = call_prom("finddevice", 1, 1, ADDR("/")); |
| 1971 | if (!PHANDLE_VALID(prom.root)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1972 | prom_panic("cannot find device tree root"); /* msg won't be printed :( */ |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1973 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1974 | prom.mmumap = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1975 | } |
| 1976 | |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1977 | #ifdef CONFIG_PPC32 |
| 1978 | /* |
| 1979 | * For really old powermacs, we need to map things we claim. |
| 1980 | * For that, we need the ihandle of the mmu. |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1981 | * Also, on the longtrail, we need to work around other bugs. |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1982 | */ |
| 1983 | static void __init prom_find_mmu(void) |
| 1984 | { |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1985 | phandle oprom; |
| 1986 | char version[64]; |
| 1987 | |
| 1988 | oprom = call_prom("finddevice", 1, 1, ADDR("/openprom")); |
| 1989 | if (!PHANDLE_VALID(oprom)) |
| 1990 | return; |
| 1991 | if (prom_getprop(oprom, "model", version, sizeof(version)) <= 0) |
| 1992 | return; |
| 1993 | version[sizeof(version) - 1] = 0; |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1994 | /* XXX might need to add other versions here */ |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1995 | if (strcmp(version, "Open Firmware, 1.0.5") == 0) |
| 1996 | of_workarounds = OF_WA_CLAIM; |
| 1997 | else if (strncmp(version, "FirmWorks,3.", 12) == 0) { |
| 1998 | of_workarounds = OF_WA_CLAIM | OF_WA_LONGTRAIL; |
| 1999 | call_prom("interpret", 1, 1, "dev /memory 0 to allow-reclaim"); |
| 2000 | } else |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2001 | return; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2002 | prom.memory = call_prom("open", 1, 1, ADDR("/memory")); |
| 2003 | prom_getprop(prom.chosen, "mmu", &prom.mmumap, |
| 2004 | sizeof(prom.mmumap)); |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2005 | prom.mmumap = be32_to_cpu(prom.mmumap); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2006 | if (!IHANDLE_VALID(prom.memory) || !IHANDLE_VALID(prom.mmumap)) |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2007 | of_workarounds &= ~OF_WA_CLAIM; /* hmmm */ |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2008 | } |
| 2009 | #else |
| 2010 | #define prom_find_mmu() |
| 2011 | #endif |
| 2012 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2013 | static void __init prom_init_stdout(void) |
| 2014 | { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2015 | char *path = of_stdout_device; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2016 | char type[16]; |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2017 | phandle stdout_node; |
| 2018 | __be32 val; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2019 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2020 | if (prom_getprop(prom.chosen, "stdout", &val, sizeof(val)) <= 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2021 | prom_panic("cannot find stdout"); |
| 2022 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2023 | prom.stdout = be32_to_cpu(val); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2024 | |
| 2025 | /* Get the full OF pathname of the stdout device */ |
| 2026 | memset(path, 0, 256); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2027 | call_prom("instance-to-path", 3, 1, prom.stdout, path, 255); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2028 | prom_printf("OF stdout device is: %s\n", of_stdout_device); |
| 2029 | prom_setprop(prom.chosen, "/chosen", "linux,stdout-path", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2030 | path, strlen(path) + 1); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2031 | |
Benjamin Herrenschmidt | 10348f5 | 2014-01-13 09:49:17 +1100 | [diff] [blame] | 2032 | /* instance-to-package fails on PA-Semi */ |
| 2033 | stdout_node = call_prom("instance-to-package", 1, 1, prom.stdout); |
| 2034 | if (stdout_node != PROM_ERROR) { |
| 2035 | val = cpu_to_be32(stdout_node); |
Benjamin Herrenschmidt | 10348f5 | 2014-01-13 09:49:17 +1100 | [diff] [blame] | 2036 | |
| 2037 | /* If it's a display, note it */ |
| 2038 | memset(type, 0, sizeof(type)); |
| 2039 | prom_getprop(stdout_node, "device_type", type, sizeof(type)); |
| 2040 | if (strcmp(type, "display") == 0) |
| 2041 | prom_setprop(stdout_node, path, "linux,boot-display", NULL, 0); |
| 2042 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2043 | } |
| 2044 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2045 | static int __init prom_find_machine_type(void) |
| 2046 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2047 | char compat[256]; |
| 2048 | int len, i = 0; |
Benjamin Herrenschmidt | 21fe330 | 2005-11-07 16:41:59 +1100 | [diff] [blame] | 2049 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2050 | phandle rtas; |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2051 | int x; |
Benjamin Herrenschmidt | 21fe330 | 2005-11-07 16:41:59 +1100 | [diff] [blame] | 2052 | #endif |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2053 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2054 | /* Look for a PowerMac or a Cell */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2055 | len = prom_getprop(prom.root, "compatible", |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2056 | compat, sizeof(compat)-1); |
| 2057 | if (len > 0) { |
| 2058 | compat[len] = 0; |
| 2059 | while (i < len) { |
| 2060 | char *p = &compat[i]; |
| 2061 | int sl = strlen(p); |
| 2062 | if (sl == 0) |
| 2063 | break; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2064 | if (strstr(p, "Power Macintosh") || |
| 2065 | strstr(p, "MacRISC")) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2066 | return PLATFORM_POWERMAC; |
Arnd Bergmann | 133dda1 | 2006-06-07 12:04:18 +1000 | [diff] [blame] | 2067 | #ifdef CONFIG_PPC64 |
| 2068 | /* We must make sure we don't detect the IBM Cell |
| 2069 | * blades as pSeries due to some firmware issues, |
| 2070 | * so we do it here. |
| 2071 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2072 | if (strstr(p, "IBM,CBEA") || |
| 2073 | strstr(p, "IBM,CPBW-1.0")) |
Arnd Bergmann | 133dda1 | 2006-06-07 12:04:18 +1000 | [diff] [blame] | 2074 | return PLATFORM_GENERIC; |
| 2075 | #endif /* CONFIG_PPC64 */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2076 | i += sl + 1; |
| 2077 | } |
| 2078 | } |
| 2079 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2080 | /* Try to figure out if it's an IBM pSeries or any other |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2081 | * PAPR compliant platform. We assume it is if : |
| 2082 | * - /device_type is "chrp" (please, do NOT use that for future |
| 2083 | * non-IBM designs ! |
| 2084 | * - it has /rtas |
| 2085 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2086 | len = prom_getprop(prom.root, "device_type", |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2087 | compat, sizeof(compat)-1); |
| 2088 | if (len <= 0) |
| 2089 | return PLATFORM_GENERIC; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2090 | if (strcmp(compat, "chrp")) |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2091 | return PLATFORM_GENERIC; |
| 2092 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2093 | /* Default to pSeries. We need to know if we are running LPAR */ |
| 2094 | rtas = call_prom("finddevice", 1, 1, ADDR("/rtas")); |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2095 | if (!PHANDLE_VALID(rtas)) |
| 2096 | return PLATFORM_GENERIC; |
| 2097 | x = prom_getproplen(rtas, "ibm,hypertas-functions"); |
| 2098 | if (x != PROM_ERROR) { |
Anton Blanchard | 4da727a | 2009-03-31 20:06:14 +0000 | [diff] [blame] | 2099 | prom_debug("Hypertas detected, assuming LPAR !\n"); |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2100 | return PLATFORM_PSERIES_LPAR; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2101 | } |
| 2102 | return PLATFORM_PSERIES; |
| 2103 | #else |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2104 | return PLATFORM_GENERIC; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2105 | #endif |
| 2106 | } |
| 2107 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2108 | static int __init prom_set_color(ihandle ih, int i, int r, int g, int b) |
| 2109 | { |
| 2110 | return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r); |
| 2111 | } |
| 2112 | |
| 2113 | /* |
| 2114 | * If we have a display that we don't know how to drive, |
| 2115 | * we will want to try to execute OF's open method for it |
| 2116 | * later. However, OF will probably fall over if we do that |
| 2117 | * we've taken over the MMU. |
| 2118 | * So we check whether we will need to open the display, |
| 2119 | * and if so, open it now. |
| 2120 | */ |
| 2121 | static void __init prom_check_displays(void) |
| 2122 | { |
| 2123 | char type[16], *path; |
| 2124 | phandle node; |
| 2125 | ihandle ih; |
| 2126 | int i; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2127 | |
Benjamin Herrenschmidt | 7f995d3 | 2018-05-31 14:33:41 +1000 | [diff] [blame] | 2128 | static const unsigned char default_colors[] = { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2129 | 0x00, 0x00, 0x00, |
| 2130 | 0x00, 0x00, 0xaa, |
| 2131 | 0x00, 0xaa, 0x00, |
| 2132 | 0x00, 0xaa, 0xaa, |
| 2133 | 0xaa, 0x00, 0x00, |
| 2134 | 0xaa, 0x00, 0xaa, |
| 2135 | 0xaa, 0xaa, 0x00, |
| 2136 | 0xaa, 0xaa, 0xaa, |
| 2137 | 0x55, 0x55, 0x55, |
| 2138 | 0x55, 0x55, 0xff, |
| 2139 | 0x55, 0xff, 0x55, |
| 2140 | 0x55, 0xff, 0xff, |
| 2141 | 0xff, 0x55, 0x55, |
| 2142 | 0xff, 0x55, 0xff, |
| 2143 | 0xff, 0xff, 0x55, |
| 2144 | 0xff, 0xff, 0xff |
| 2145 | }; |
| 2146 | const unsigned char *clut; |
| 2147 | |
Anton Blanchard | 4da727a | 2009-03-31 20:06:14 +0000 | [diff] [blame] | 2148 | prom_debug("Looking for displays\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2149 | for (node = 0; prom_next_node(&node); ) { |
| 2150 | memset(type, 0, sizeof(type)); |
| 2151 | prom_getprop(node, "device_type", type, sizeof(type)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2152 | if (strcmp(type, "display") != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2153 | continue; |
| 2154 | |
| 2155 | /* It seems OF doesn't null-terminate the path :-( */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2156 | path = prom_scratch; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2157 | memset(path, 0, PROM_SCRATCH_SIZE); |
| 2158 | |
| 2159 | /* |
| 2160 | * leave some room at the end of the path for appending extra |
| 2161 | * arguments |
| 2162 | */ |
| 2163 | if (call_prom("package-to-path", 3, 1, node, path, |
| 2164 | PROM_SCRATCH_SIZE-10) == PROM_ERROR) |
| 2165 | continue; |
Anton Blanchard | 1f8737a | 2009-03-31 20:06:15 +0000 | [diff] [blame] | 2166 | prom_printf("found display : %s, opening... ", path); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2167 | |
| 2168 | ih = call_prom("open", 1, 1, path); |
| 2169 | if (ih == 0) { |
| 2170 | prom_printf("failed\n"); |
| 2171 | continue; |
| 2172 | } |
| 2173 | |
| 2174 | /* Success */ |
| 2175 | prom_printf("done\n"); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2176 | prom_setprop(node, path, "linux,opened", NULL, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2177 | |
| 2178 | /* Setup a usable color table when the appropriate |
| 2179 | * method is available. Should update this to set-colors */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2180 | clut = default_colors; |
Benjamin Herrenschmidt | 3f53638 | 2011-12-14 13:55:11 +0000 | [diff] [blame] | 2181 | for (i = 0; i < 16; i++, clut += 3) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2182 | if (prom_set_color(ih, i, clut[0], clut[1], |
| 2183 | clut[2]) != 0) |
| 2184 | break; |
| 2185 | |
| 2186 | #ifdef CONFIG_LOGO_LINUX_CLUT224 |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2187 | clut = PTRRELOC(logo_linux_clut224.clut); |
| 2188 | for (i = 0; i < logo_linux_clut224.clutsize; i++, clut += 3) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2189 | if (prom_set_color(ih, i + 32, clut[0], clut[1], |
| 2190 | clut[2]) != 0) |
| 2191 | break; |
| 2192 | #endif /* CONFIG_LOGO_LINUX_CLUT224 */ |
Benjamin Herrenschmidt | 7191b61 | 2013-07-25 12:12:32 +1000 | [diff] [blame] | 2193 | |
| 2194 | #ifdef CONFIG_PPC_EARLY_DEBUG_BOOTX |
| 2195 | if (prom_getprop(node, "linux,boot-display", NULL, 0) != |
| 2196 | PROM_ERROR) { |
| 2197 | u32 width, height, pitch, addr; |
| 2198 | |
| 2199 | prom_printf("Setting btext !\n"); |
| 2200 | prom_getprop(node, "width", &width, 4); |
| 2201 | prom_getprop(node, "height", &height, 4); |
| 2202 | prom_getprop(node, "linebytes", &pitch, 4); |
| 2203 | prom_getprop(node, "address", &addr, 4); |
| 2204 | prom_printf("W=%d H=%d LB=%d addr=0x%x\n", |
| 2205 | width, height, pitch, addr); |
| 2206 | btext_setup_display(width, height, 8, pitch, addr); |
| 2207 | } |
| 2208 | #endif /* CONFIG_PPC_EARLY_DEBUG_BOOTX */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2209 | } |
| 2210 | } |
| 2211 | |
| 2212 | |
| 2213 | /* Return (relocated) pointer to this much memory: moves initrd if reqd. */ |
| 2214 | static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end, |
| 2215 | unsigned long needed, unsigned long align) |
| 2216 | { |
| 2217 | void *ret; |
| 2218 | |
| 2219 | *mem_start = _ALIGN(*mem_start, align); |
| 2220 | while ((*mem_start + needed) > *mem_end) { |
| 2221 | unsigned long room, chunk; |
| 2222 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 2223 | prom_debug("Chunk exhausted, claiming more at %lx...\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2224 | alloc_bottom); |
| 2225 | room = alloc_top - alloc_bottom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2226 | if (room > DEVTREE_CHUNK_SIZE) |
| 2227 | room = DEVTREE_CHUNK_SIZE; |
| 2228 | if (room < PAGE_SIZE) |
Anton Blanchard | fbafd72 | 2011-07-25 20:47:51 +0000 | [diff] [blame] | 2229 | prom_panic("No memory for flatten_device_tree " |
| 2230 | "(no room)\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2231 | chunk = alloc_up(room, 0); |
| 2232 | if (chunk == 0) |
Anton Blanchard | fbafd72 | 2011-07-25 20:47:51 +0000 | [diff] [blame] | 2233 | prom_panic("No memory for flatten_device_tree " |
| 2234 | "(claim failed)\n"); |
Anton Blanchard | 966728d | 2011-07-25 20:47:07 +0000 | [diff] [blame] | 2235 | *mem_end = chunk + room; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | ret = (void *)*mem_start; |
| 2239 | *mem_start += needed; |
| 2240 | |
| 2241 | return ret; |
| 2242 | } |
| 2243 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2244 | #define dt_push_token(token, mem_start, mem_end) do { \ |
| 2245 | void *room = make_room(mem_start, mem_end, 4, 4); \ |
| 2246 | *(__be32 *)room = cpu_to_be32(token); \ |
| 2247 | } while(0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2248 | |
| 2249 | static unsigned long __init dt_find_string(char *str) |
| 2250 | { |
| 2251 | char *s, *os; |
| 2252 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2253 | s = os = (char *)dt_string_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2254 | s += 4; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2255 | while (s < (char *)dt_string_end) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2256 | if (strcmp(s, str) == 0) |
| 2257 | return s - os; |
| 2258 | s += strlen(s) + 1; |
| 2259 | } |
| 2260 | return 0; |
| 2261 | } |
| 2262 | |
| 2263 | /* |
| 2264 | * The Open Firmware 1275 specification states properties must be 31 bytes or |
| 2265 | * less, however not all firmwares obey this. Make it 64 bytes to be safe. |
| 2266 | */ |
| 2267 | #define MAX_PROPERTY_NAME 64 |
| 2268 | |
| 2269 | static void __init scan_dt_build_strings(phandle node, |
| 2270 | unsigned long *mem_start, |
| 2271 | unsigned long *mem_end) |
| 2272 | { |
| 2273 | char *prev_name, *namep, *sstart; |
| 2274 | unsigned long soff; |
| 2275 | phandle child; |
| 2276 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2277 | sstart = (char *)dt_string_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2278 | |
| 2279 | /* get and store all property names */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2280 | prev_name = ""; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2281 | for (;;) { |
| 2282 | /* 64 is max len of name including nul. */ |
| 2283 | namep = make_room(mem_start, mem_end, MAX_PROPERTY_NAME, 1); |
| 2284 | if (call_prom("nextprop", 3, 1, node, prev_name, namep) != 1) { |
| 2285 | /* No more nodes: unwind alloc */ |
| 2286 | *mem_start = (unsigned long)namep; |
| 2287 | break; |
| 2288 | } |
| 2289 | |
| 2290 | /* skip "name" */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2291 | if (strcmp(namep, "name") == 0) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2292 | *mem_start = (unsigned long)namep; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2293 | prev_name = "name"; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2294 | continue; |
| 2295 | } |
| 2296 | /* get/create string entry */ |
| 2297 | soff = dt_find_string(namep); |
| 2298 | if (soff != 0) { |
| 2299 | *mem_start = (unsigned long)namep; |
| 2300 | namep = sstart + soff; |
| 2301 | } else { |
| 2302 | /* Trim off some if we can */ |
| 2303 | *mem_start = (unsigned long)namep + strlen(namep) + 1; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2304 | dt_string_end = *mem_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2305 | } |
| 2306 | prev_name = namep; |
| 2307 | } |
| 2308 | |
| 2309 | /* do all our children */ |
| 2310 | child = call_prom("child", 1, 1, node); |
| 2311 | while (child != 0) { |
| 2312 | scan_dt_build_strings(child, mem_start, mem_end); |
| 2313 | child = call_prom("peer", 1, 1, child); |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, |
| 2318 | unsigned long *mem_end) |
| 2319 | { |
| 2320 | phandle child; |
| 2321 | char *namep, *prev_name, *sstart, *p, *ep, *lp, *path; |
| 2322 | unsigned long soff; |
| 2323 | unsigned char *valp; |
| 2324 | static char pname[MAX_PROPERTY_NAME]; |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2325 | int l, room, has_phandle = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2326 | |
| 2327 | dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end); |
| 2328 | |
| 2329 | /* get the node's full name */ |
| 2330 | namep = (char *)*mem_start; |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 2331 | room = *mem_end - *mem_start; |
| 2332 | if (room > 255) |
| 2333 | room = 255; |
| 2334 | l = call_prom("package-to-path", 3, 1, node, namep, room); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2335 | if (l >= 0) { |
| 2336 | /* Didn't fit? Get more room. */ |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 2337 | if (l >= room) { |
| 2338 | if (l >= *mem_end - *mem_start) |
| 2339 | namep = make_room(mem_start, mem_end, l+1, 1); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2340 | call_prom("package-to-path", 3, 1, node, namep, l); |
| 2341 | } |
| 2342 | namep[l] = '\0'; |
| 2343 | |
| 2344 | /* Fixup an Apple bug where they have bogus \0 chars in the |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2345 | * middle of the path in some properties, and extract |
| 2346 | * the unit name (everything after the last '/'). |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2347 | */ |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2348 | for (lp = p = namep, ep = namep + l; p < ep; p++) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2349 | if (*p == '/') |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2350 | lp = namep; |
| 2351 | else if (*p != 0) |
| 2352 | *lp++ = *p; |
| 2353 | } |
| 2354 | *lp = 0; |
| 2355 | *mem_start = _ALIGN((unsigned long)lp + 1, 4); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | /* get it again for debugging */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2359 | path = prom_scratch; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2360 | memset(path, 0, PROM_SCRATCH_SIZE); |
| 2361 | call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1); |
| 2362 | |
| 2363 | /* get and store all properties */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2364 | prev_name = ""; |
| 2365 | sstart = (char *)dt_string_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2366 | for (;;) { |
| 2367 | if (call_prom("nextprop", 3, 1, node, prev_name, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2368 | pname) != 1) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2369 | break; |
| 2370 | |
| 2371 | /* skip "name" */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2372 | if (strcmp(pname, "name") == 0) { |
| 2373 | prev_name = "name"; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2374 | continue; |
| 2375 | } |
| 2376 | |
| 2377 | /* find string offset */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2378 | soff = dt_find_string(pname); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2379 | if (soff == 0) { |
| 2380 | prom_printf("WARNING: Can't find string index for" |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2381 | " <%s>, node %s\n", pname, path); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2382 | break; |
| 2383 | } |
| 2384 | prev_name = sstart + soff; |
| 2385 | |
| 2386 | /* get length */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2387 | l = call_prom("getproplen", 2, 1, node, pname); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2388 | |
| 2389 | /* sanity checks */ |
| 2390 | if (l == PROM_ERROR) |
| 2391 | continue; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2392 | |
| 2393 | /* push property head */ |
| 2394 | dt_push_token(OF_DT_PROP, mem_start, mem_end); |
| 2395 | dt_push_token(l, mem_start, mem_end); |
| 2396 | dt_push_token(soff, mem_start, mem_end); |
| 2397 | |
| 2398 | /* push property content */ |
| 2399 | valp = make_room(mem_start, mem_end, l, 4); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2400 | call_prom("getprop", 4, 1, node, pname, valp, l); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2401 | *mem_start = _ALIGN(*mem_start, 4); |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2402 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2403 | if (!strcmp(pname, "phandle")) |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2404 | has_phandle = 1; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2405 | } |
| 2406 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2407 | /* Add a "linux,phandle" property if no "phandle" property already |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 2408 | * existed. |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2409 | */ |
| 2410 | if (!has_phandle) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2411 | soff = dt_find_string("linux,phandle"); |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2412 | if (soff == 0) |
| 2413 | prom_printf("WARNING: Can't find string index for" |
| 2414 | " <linux-phandle> node %s\n", path); |
| 2415 | else { |
| 2416 | dt_push_token(OF_DT_PROP, mem_start, mem_end); |
| 2417 | dt_push_token(4, mem_start, mem_end); |
| 2418 | dt_push_token(soff, mem_start, mem_end); |
| 2419 | valp = make_room(mem_start, mem_end, 4, 4); |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2420 | *(__be32 *)valp = cpu_to_be32(node); |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2421 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | /* do all our children */ |
| 2425 | child = call_prom("child", 1, 1, node); |
| 2426 | while (child != 0) { |
| 2427 | scan_dt_build_struct(child, mem_start, mem_end); |
| 2428 | child = call_prom("peer", 1, 1, child); |
| 2429 | } |
| 2430 | |
| 2431 | dt_push_token(OF_DT_END_NODE, mem_start, mem_end); |
| 2432 | } |
| 2433 | |
| 2434 | static void __init flatten_device_tree(void) |
| 2435 | { |
| 2436 | phandle root; |
| 2437 | unsigned long mem_start, mem_end, room; |
| 2438 | struct boot_param_header *hdr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2439 | char *namep; |
| 2440 | u64 *rsvmap; |
| 2441 | |
| 2442 | /* |
| 2443 | * Check how much room we have between alloc top & bottom (+/- a |
Anton Blanchard | fbafd72 | 2011-07-25 20:47:51 +0000 | [diff] [blame] | 2444 | * few pages), crop to 1MB, as this is our "chunk" size |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2445 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2446 | room = alloc_top - alloc_bottom - 0x4000; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2447 | if (room > DEVTREE_CHUNK_SIZE) |
| 2448 | room = DEVTREE_CHUNK_SIZE; |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 2449 | prom_debug("starting device tree allocs at %lx\n", alloc_bottom); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2450 | |
| 2451 | /* Now try to claim that */ |
| 2452 | mem_start = (unsigned long)alloc_up(room, PAGE_SIZE); |
| 2453 | if (mem_start == 0) |
| 2454 | prom_panic("Can't allocate initial device-tree chunk\n"); |
Anton Blanchard | 966728d | 2011-07-25 20:47:07 +0000 | [diff] [blame] | 2455 | mem_end = mem_start + room; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2456 | |
| 2457 | /* Get root of tree */ |
| 2458 | root = call_prom("peer", 1, 1, (phandle)0); |
| 2459 | if (root == (phandle)0) |
| 2460 | prom_panic ("couldn't get device tree root\n"); |
| 2461 | |
| 2462 | /* Build header and make room for mem rsv map */ |
| 2463 | mem_start = _ALIGN(mem_start, 4); |
| 2464 | hdr = make_room(&mem_start, &mem_end, |
| 2465 | sizeof(struct boot_param_header), 4); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2466 | dt_header_start = (unsigned long)hdr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2467 | rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8); |
| 2468 | |
| 2469 | /* Start of strings */ |
| 2470 | mem_start = PAGE_ALIGN(mem_start); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2471 | dt_string_start = mem_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2472 | mem_start += 4; /* hole */ |
| 2473 | |
| 2474 | /* Add "linux,phandle" in there, we'll need it */ |
| 2475 | namep = make_room(&mem_start, &mem_end, 16, 1); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2476 | strcpy(namep, "linux,phandle"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2477 | mem_start = (unsigned long)namep + strlen(namep) + 1; |
| 2478 | |
| 2479 | /* Build string array */ |
| 2480 | prom_printf("Building dt strings...\n"); |
| 2481 | scan_dt_build_strings(root, &mem_start, &mem_end); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2482 | dt_string_end = mem_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2483 | |
| 2484 | /* Build structure */ |
| 2485 | mem_start = PAGE_ALIGN(mem_start); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2486 | dt_struct_start = mem_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2487 | prom_printf("Building dt structure...\n"); |
| 2488 | scan_dt_build_struct(root, &mem_start, &mem_end); |
| 2489 | dt_push_token(OF_DT_END, &mem_start, &mem_end); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2490 | dt_struct_end = PAGE_ALIGN(mem_start); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2491 | |
| 2492 | /* Finish header */ |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2493 | hdr->boot_cpuid_phys = cpu_to_be32(prom.cpu); |
| 2494 | hdr->magic = cpu_to_be32(OF_DT_HEADER); |
| 2495 | hdr->totalsize = cpu_to_be32(dt_struct_end - dt_header_start); |
| 2496 | hdr->off_dt_struct = cpu_to_be32(dt_struct_start - dt_header_start); |
| 2497 | hdr->off_dt_strings = cpu_to_be32(dt_string_start - dt_header_start); |
| 2498 | hdr->dt_strings_size = cpu_to_be32(dt_string_end - dt_string_start); |
| 2499 | hdr->off_mem_rsvmap = cpu_to_be32(((unsigned long)rsvmap) - dt_header_start); |
| 2500 | hdr->version = cpu_to_be32(OF_DT_VERSION); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2501 | /* Version 16 is not backward compatible */ |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2502 | hdr->last_comp_version = cpu_to_be32(0x10); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2503 | |
Jimi Xenidis | 4d1f3f2 | 2006-05-18 17:03:05 -0500 | [diff] [blame] | 2504 | /* Copy the reserve map in */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2505 | memcpy(rsvmap, mem_reserve_map, sizeof(mem_reserve_map)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2506 | |
| 2507 | #ifdef DEBUG_PROM |
| 2508 | { |
| 2509 | int i; |
| 2510 | prom_printf("reserved memory map:\n"); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2511 | for (i = 0; i < mem_reserve_cnt; i++) |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 2512 | prom_printf(" %llx - %llx\n", |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2513 | be64_to_cpu(mem_reserve_map[i].base), |
| 2514 | be64_to_cpu(mem_reserve_map[i].size)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2515 | } |
| 2516 | #endif |
Jimi Xenidis | 4d1f3f2 | 2006-05-18 17:03:05 -0500 | [diff] [blame] | 2517 | /* Bump mem_reserve_cnt to cause further reservations to fail |
| 2518 | * since it's too late. |
| 2519 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2520 | mem_reserve_cnt = MEM_RESERVE_MAP_SIZE; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2521 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 2522 | prom_printf("Device tree strings 0x%lx -> 0x%lx\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2523 | dt_string_start, dt_string_end); |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 2524 | prom_printf("Device tree struct 0x%lx -> 0x%lx\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2525 | dt_struct_start, dt_struct_end); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2526 | } |
| 2527 | |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2528 | #ifdef CONFIG_PPC_MAPLE |
| 2529 | /* PIBS Version 1.05.0000 04/26/2005 has an incorrect /ht/isa/ranges property. |
| 2530 | * The values are bad, and it doesn't even have the right number of cells. */ |
| 2531 | static void __init fixup_device_tree_maple(void) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2532 | { |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2533 | phandle isa; |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2534 | u32 rloc = 0x01002000; /* IO space; PCI device = 4 */ |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2535 | u32 isa_ranges[6]; |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2536 | char *name; |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2537 | |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2538 | name = "/ht@0/isa@4"; |
| 2539 | isa = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2540 | if (!PHANDLE_VALID(isa)) { |
| 2541 | name = "/ht@0/isa@6"; |
| 2542 | isa = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2543 | rloc = 0x01003000; /* IO space; PCI device = 6 */ |
| 2544 | } |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2545 | if (!PHANDLE_VALID(isa)) |
| 2546 | return; |
| 2547 | |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2548 | if (prom_getproplen(isa, "ranges") != 12) |
| 2549 | return; |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2550 | if (prom_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges)) |
| 2551 | == PROM_ERROR) |
| 2552 | return; |
| 2553 | |
| 2554 | if (isa_ranges[0] != 0x1 || |
| 2555 | isa_ranges[1] != 0xf4000000 || |
| 2556 | isa_ranges[2] != 0x00010000) |
| 2557 | return; |
| 2558 | |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2559 | prom_printf("Fixing up bogus ISA range on Maple/Apache...\n"); |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2560 | |
| 2561 | isa_ranges[0] = 0x1; |
| 2562 | isa_ranges[1] = 0x0; |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2563 | isa_ranges[2] = rloc; |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2564 | isa_ranges[3] = 0x0; |
| 2565 | isa_ranges[4] = 0x0; |
| 2566 | isa_ranges[5] = 0x00010000; |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2567 | prom_setprop(isa, name, "ranges", |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2568 | isa_ranges, sizeof(isa_ranges)); |
| 2569 | } |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2570 | |
| 2571 | #define CPC925_MC_START 0xf8000000 |
| 2572 | #define CPC925_MC_LENGTH 0x1000000 |
| 2573 | /* The values for memory-controller don't have right number of cells */ |
| 2574 | static void __init fixup_device_tree_maple_memory_controller(void) |
| 2575 | { |
| 2576 | phandle mc; |
| 2577 | u32 mc_reg[4]; |
| 2578 | char *name = "/hostbridge@f8000000"; |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2579 | u32 ac, sc; |
| 2580 | |
| 2581 | mc = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2582 | if (!PHANDLE_VALID(mc)) |
| 2583 | return; |
| 2584 | |
| 2585 | if (prom_getproplen(mc, "reg") != 8) |
| 2586 | return; |
| 2587 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2588 | prom_getprop(prom.root, "#address-cells", &ac, sizeof(ac)); |
| 2589 | prom_getprop(prom.root, "#size-cells", &sc, sizeof(sc)); |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2590 | if ((ac != 2) || (sc != 2)) |
| 2591 | return; |
| 2592 | |
| 2593 | if (prom_getprop(mc, "reg", mc_reg, sizeof(mc_reg)) == PROM_ERROR) |
| 2594 | return; |
| 2595 | |
| 2596 | if (mc_reg[0] != CPC925_MC_START || mc_reg[1] != CPC925_MC_LENGTH) |
| 2597 | return; |
| 2598 | |
| 2599 | prom_printf("Fixing up bogus hostbridge on Maple...\n"); |
| 2600 | |
| 2601 | mc_reg[0] = 0x0; |
| 2602 | mc_reg[1] = CPC925_MC_START; |
| 2603 | mc_reg[2] = 0x0; |
| 2604 | mc_reg[3] = CPC925_MC_LENGTH; |
| 2605 | prom_setprop(mc, name, "reg", mc_reg, sizeof(mc_reg)); |
| 2606 | } |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2607 | #else |
| 2608 | #define fixup_device_tree_maple() |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2609 | #define fixup_device_tree_maple_memory_controller() |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2610 | #endif |
| 2611 | |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2612 | #ifdef CONFIG_PPC_CHRP |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2613 | /* |
| 2614 | * Pegasos and BriQ lacks the "ranges" property in the isa node |
| 2615 | * Pegasos needs decimal IRQ 14/15, not hexadecimal |
Olaf Hering | 556ecf9 | 2007-08-18 04:27:17 +1000 | [diff] [blame] | 2616 | * Pegasos has the IDE configured in legacy mode, but advertised as native |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2617 | */ |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2618 | static void __init fixup_device_tree_chrp(void) |
| 2619 | { |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2620 | phandle ph; |
| 2621 | u32 prop[6]; |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 2622 | u32 rloc = 0x01006000; /* IO space; PCI device = 12 */ |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2623 | char *name; |
| 2624 | int rc; |
| 2625 | |
| 2626 | name = "/pci@80000000/isa@c"; |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2627 | ph = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2628 | if (!PHANDLE_VALID(ph)) { |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 2629 | name = "/pci@ff500000/isa@6"; |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2630 | ph = call_prom("finddevice", 1, 1, ADDR(name)); |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 2631 | rloc = 0x01003000; /* IO space; PCI device = 6 */ |
| 2632 | } |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2633 | if (PHANDLE_VALID(ph)) { |
| 2634 | rc = prom_getproplen(ph, "ranges"); |
| 2635 | if (rc == 0 || rc == PROM_ERROR) { |
| 2636 | prom_printf("Fixing up missing ISA range on Pegasos...\n"); |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2637 | |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2638 | prop[0] = 0x1; |
| 2639 | prop[1] = 0x0; |
| 2640 | prop[2] = rloc; |
| 2641 | prop[3] = 0x0; |
| 2642 | prop[4] = 0x0; |
| 2643 | prop[5] = 0x00010000; |
| 2644 | prom_setprop(ph, name, "ranges", prop, sizeof(prop)); |
| 2645 | } |
| 2646 | } |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2647 | |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2648 | name = "/pci@80000000/ide@C,1"; |
| 2649 | ph = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2650 | if (PHANDLE_VALID(ph)) { |
| 2651 | prom_printf("Fixing up IDE interrupt on Pegasos...\n"); |
| 2652 | prop[0] = 14; |
| 2653 | prop[1] = 0x0; |
Olaf Hering | 556ecf9 | 2007-08-18 04:27:17 +1000 | [diff] [blame] | 2654 | prom_setprop(ph, name, "interrupts", prop, 2*sizeof(u32)); |
| 2655 | prom_printf("Fixing up IDE class-code on Pegasos...\n"); |
| 2656 | rc = prom_getprop(ph, "class-code", prop, sizeof(u32)); |
| 2657 | if (rc == sizeof(u32)) { |
| 2658 | prop[0] &= ~0x5; |
| 2659 | prom_setprop(ph, name, "class-code", prop, sizeof(u32)); |
| 2660 | } |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2661 | } |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2662 | } |
| 2663 | #else |
| 2664 | #define fixup_device_tree_chrp() |
| 2665 | #endif |
| 2666 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2667 | #if defined(CONFIG_PPC64) && defined(CONFIG_PPC_PMAC) |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2668 | static void __init fixup_device_tree_pmac(void) |
| 2669 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2670 | phandle u3, i2c, mpic; |
| 2671 | u32 u3_rev; |
| 2672 | u32 interrupts[2]; |
| 2673 | u32 parent; |
| 2674 | |
| 2675 | /* Some G5s have a missing interrupt definition, fix it up here */ |
| 2676 | u3 = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000")); |
| 2677 | if (!PHANDLE_VALID(u3)) |
| 2678 | return; |
| 2679 | i2c = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/i2c@f8001000")); |
| 2680 | if (!PHANDLE_VALID(i2c)) |
| 2681 | return; |
| 2682 | mpic = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/mpic@f8040000")); |
| 2683 | if (!PHANDLE_VALID(mpic)) |
| 2684 | return; |
| 2685 | |
| 2686 | /* check if proper rev of u3 */ |
| 2687 | if (prom_getprop(u3, "device-rev", &u3_rev, sizeof(u3_rev)) |
| 2688 | == PROM_ERROR) |
| 2689 | return; |
Benjamin Herrenschmidt | 7d49697 | 2005-11-07 14:36:21 +1100 | [diff] [blame] | 2690 | if (u3_rev < 0x35 || u3_rev > 0x39) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2691 | return; |
| 2692 | /* does it need fixup ? */ |
| 2693 | if (prom_getproplen(i2c, "interrupts") > 0) |
| 2694 | return; |
| 2695 | |
| 2696 | prom_printf("fixing up bogus interrupts for u3 i2c...\n"); |
| 2697 | |
| 2698 | /* interrupt on this revision of u3 is number 0 and level */ |
| 2699 | interrupts[0] = 0; |
| 2700 | interrupts[1] = 1; |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2701 | prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupts", |
| 2702 | &interrupts, sizeof(interrupts)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2703 | parent = (u32)mpic; |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2704 | prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupt-parent", |
| 2705 | &parent, sizeof(parent)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2706 | } |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2707 | #else |
| 2708 | #define fixup_device_tree_pmac() |
| 2709 | #endif |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2710 | |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2711 | #ifdef CONFIG_PPC_EFIKA |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2712 | /* |
| 2713 | * The MPC5200 FEC driver requires an phy-handle property to tell it how |
| 2714 | * to talk to the phy. If the phy-handle property is missing, then this |
| 2715 | * function is called to add the appropriate nodes and link it to the |
| 2716 | * ethernet node. |
| 2717 | */ |
| 2718 | static void __init fixup_device_tree_efika_add_phy(void) |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2719 | { |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2720 | u32 node; |
| 2721 | char prop[64]; |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2722 | int rv; |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2723 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2724 | /* Check if /builtin/ethernet exists - bail if it doesn't */ |
| 2725 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/ethernet")); |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2726 | if (!PHANDLE_VALID(node)) |
| 2727 | return; |
| 2728 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2729 | /* Check if the phy-handle property exists - bail if it does */ |
| 2730 | rv = prom_getprop(node, "phy-handle", prop, sizeof(prop)); |
| 2731 | if (!rv) |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2732 | return; |
| 2733 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2734 | /* |
| 2735 | * At this point the ethernet device doesn't have a phy described. |
| 2736 | * Now we need to add the missing phy node and linkage |
| 2737 | */ |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2738 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2739 | /* Check for an MDIO bus node - if missing then create one */ |
Olaf Hering | 6f4347c | 2008-01-10 01:06:08 +1100 | [diff] [blame] | 2740 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/mdio")); |
| 2741 | if (!PHANDLE_VALID(node)) { |
| 2742 | prom_printf("Adding Ethernet MDIO node\n"); |
| 2743 | call_prom("interpret", 1, 1, |
| 2744 | " s\" /builtin\" find-device" |
| 2745 | " new-device" |
| 2746 | " 1 encode-int s\" #address-cells\" property" |
| 2747 | " 0 encode-int s\" #size-cells\" property" |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2748 | " s\" mdio\" device-name" |
| 2749 | " s\" fsl,mpc5200b-mdio\" encode-string" |
Olaf Hering | 6f4347c | 2008-01-10 01:06:08 +1100 | [diff] [blame] | 2750 | " s\" compatible\" property" |
| 2751 | " 0xf0003000 0x400 reg" |
| 2752 | " 0x2 encode-int" |
| 2753 | " 0x5 encode-int encode+" |
| 2754 | " 0x3 encode-int encode+" |
| 2755 | " s\" interrupts\" property" |
| 2756 | " finish-device"); |
| 2757 | }; |
| 2758 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2759 | /* Check for a PHY device node - if missing then create one and |
| 2760 | * give it's phandle to the ethernet node */ |
| 2761 | node = call_prom("finddevice", 1, 1, |
| 2762 | ADDR("/builtin/mdio/ethernet-phy")); |
Olaf Hering | 6f4347c | 2008-01-10 01:06:08 +1100 | [diff] [blame] | 2763 | if (!PHANDLE_VALID(node)) { |
| 2764 | prom_printf("Adding Ethernet PHY node\n"); |
| 2765 | call_prom("interpret", 1, 1, |
| 2766 | " s\" /builtin/mdio\" find-device" |
| 2767 | " new-device" |
| 2768 | " s\" ethernet-phy\" device-name" |
| 2769 | " 0x10 encode-int s\" reg\" property" |
| 2770 | " my-self" |
| 2771 | " ihandle>phandle" |
| 2772 | " finish-device" |
| 2773 | " s\" /builtin/ethernet\" find-device" |
| 2774 | " encode-int" |
| 2775 | " s\" phy-handle\" property" |
| 2776 | " device-end"); |
| 2777 | } |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2778 | } |
Olaf Hering | 6f4347c | 2008-01-10 01:06:08 +1100 | [diff] [blame] | 2779 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2780 | static void __init fixup_device_tree_efika(void) |
| 2781 | { |
| 2782 | int sound_irq[3] = { 2, 2, 0 }; |
| 2783 | int bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0, |
| 2784 | 3,4,0, 3,5,0, 3,6,0, 3,7,0, |
| 2785 | 3,8,0, 3,9,0, 3,10,0, 3,11,0, |
| 2786 | 3,12,0, 3,13,0, 3,14,0, 3,15,0 }; |
| 2787 | u32 node; |
| 2788 | char prop[64]; |
| 2789 | int rv, len; |
| 2790 | |
| 2791 | /* Check if we're really running on a EFIKA */ |
| 2792 | node = call_prom("finddevice", 1, 1, ADDR("/")); |
| 2793 | if (!PHANDLE_VALID(node)) |
| 2794 | return; |
| 2795 | |
| 2796 | rv = prom_getprop(node, "model", prop, sizeof(prop)); |
| 2797 | if (rv == PROM_ERROR) |
| 2798 | return; |
| 2799 | if (strcmp(prop, "EFIKA5K2")) |
| 2800 | return; |
| 2801 | |
| 2802 | prom_printf("Applying EFIKA device tree fixups\n"); |
| 2803 | |
| 2804 | /* Claiming to be 'chrp' is death */ |
| 2805 | node = call_prom("finddevice", 1, 1, ADDR("/")); |
| 2806 | rv = prom_getprop(node, "device_type", prop, sizeof(prop)); |
| 2807 | if (rv != PROM_ERROR && (strcmp(prop, "chrp") == 0)) |
| 2808 | prom_setprop(node, "/", "device_type", "efika", sizeof("efika")); |
| 2809 | |
David Woodhouse | 7f4392c | 2008-04-14 02:52:38 +1000 | [diff] [blame] | 2810 | /* CODEGEN,description is exposed in /proc/cpuinfo so |
| 2811 | fix that too */ |
| 2812 | rv = prom_getprop(node, "CODEGEN,description", prop, sizeof(prop)); |
| 2813 | if (rv != PROM_ERROR && (strstr(prop, "CHRP"))) |
| 2814 | prom_setprop(node, "/", "CODEGEN,description", |
| 2815 | "Efika 5200B PowerPC System", |
| 2816 | sizeof("Efika 5200B PowerPC System")); |
| 2817 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2818 | /* Fixup bestcomm interrupts property */ |
| 2819 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/bestcomm")); |
| 2820 | if (PHANDLE_VALID(node)) { |
| 2821 | len = prom_getproplen(node, "interrupts"); |
| 2822 | if (len == 12) { |
| 2823 | prom_printf("Fixing bestcomm interrupts property\n"); |
| 2824 | prom_setprop(node, "/builtin/bestcom", "interrupts", |
| 2825 | bcomm_irq, sizeof(bcomm_irq)); |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | /* Fixup sound interrupts property */ |
| 2830 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/sound")); |
| 2831 | if (PHANDLE_VALID(node)) { |
| 2832 | rv = prom_getprop(node, "interrupts", prop, sizeof(prop)); |
| 2833 | if (rv == PROM_ERROR) { |
| 2834 | prom_printf("Adding sound interrupts property\n"); |
| 2835 | prom_setprop(node, "/builtin/sound", "interrupts", |
| 2836 | sound_irq, sizeof(sound_irq)); |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | /* Make sure ethernet phy-handle property exists */ |
| 2841 | fixup_device_tree_efika_add_phy(); |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2842 | } |
| 2843 | #else |
| 2844 | #define fixup_device_tree_efika() |
| 2845 | #endif |
| 2846 | |
Darren Stevens | 5024678 | 2016-08-31 13:24:40 +0100 | [diff] [blame] | 2847 | #ifdef CONFIG_PPC_PASEMI_NEMO |
| 2848 | /* |
| 2849 | * CFE supplied on Nemo is broken in several ways, biggest |
| 2850 | * problem is that it reassigns ISA interrupts to unused mpic ints. |
| 2851 | * Add an interrupt-controller property for the io-bridge to use |
| 2852 | * and correct the ints so we can attach them to an irq_domain |
| 2853 | */ |
| 2854 | static void __init fixup_device_tree_pasemi(void) |
| 2855 | { |
| 2856 | u32 interrupts[2], parent, rval, val = 0; |
| 2857 | char *name, *pci_name; |
| 2858 | phandle iob, node; |
| 2859 | |
| 2860 | /* Find the root pci node */ |
| 2861 | name = "/pxp@0,e0000000"; |
| 2862 | iob = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2863 | if (!PHANDLE_VALID(iob)) |
| 2864 | return; |
| 2865 | |
| 2866 | /* check if interrupt-controller node set yet */ |
| 2867 | if (prom_getproplen(iob, "interrupt-controller") !=PROM_ERROR) |
| 2868 | return; |
| 2869 | |
| 2870 | prom_printf("adding interrupt-controller property for SB600...\n"); |
| 2871 | |
| 2872 | prom_setprop(iob, name, "interrupt-controller", &val, 0); |
| 2873 | |
| 2874 | pci_name = "/pxp@0,e0000000/pci@11"; |
| 2875 | node = call_prom("finddevice", 1, 1, ADDR(pci_name)); |
| 2876 | parent = ADDR(iob); |
| 2877 | |
| 2878 | for( ; prom_next_node(&node); ) { |
| 2879 | /* scan each node for one with an interrupt */ |
| 2880 | if (!PHANDLE_VALID(node)) |
| 2881 | continue; |
| 2882 | |
| 2883 | rval = prom_getproplen(node, "interrupts"); |
| 2884 | if (rval == 0 || rval == PROM_ERROR) |
| 2885 | continue; |
| 2886 | |
| 2887 | prom_getprop(node, "interrupts", &interrupts, sizeof(interrupts)); |
| 2888 | if ((interrupts[0] < 212) || (interrupts[0] > 222)) |
| 2889 | continue; |
| 2890 | |
| 2891 | /* found a node, update both interrupts and interrupt-parent */ |
| 2892 | if ((interrupts[0] >= 212) && (interrupts[0] <= 215)) |
| 2893 | interrupts[0] -= 203; |
| 2894 | if ((interrupts[0] >= 216) && (interrupts[0] <= 220)) |
| 2895 | interrupts[0] -= 213; |
| 2896 | if (interrupts[0] == 221) |
| 2897 | interrupts[0] = 14; |
| 2898 | if (interrupts[0] == 222) |
| 2899 | interrupts[0] = 8; |
| 2900 | |
| 2901 | prom_setprop(node, pci_name, "interrupts", interrupts, |
| 2902 | sizeof(interrupts)); |
| 2903 | prom_setprop(node, pci_name, "interrupt-parent", &parent, |
| 2904 | sizeof(parent)); |
| 2905 | } |
Darren Stevens | 687e16b | 2016-08-31 13:24:45 +0100 | [diff] [blame] | 2906 | |
| 2907 | /* |
| 2908 | * The io-bridge has device_type set to 'io-bridge' change it to 'isa' |
| 2909 | * so that generic isa-bridge code can add the SB600 and its on-board |
| 2910 | * peripherals. |
| 2911 | */ |
| 2912 | name = "/pxp@0,e0000000/io-bridge@0"; |
| 2913 | iob = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2914 | if (!PHANDLE_VALID(iob)) |
| 2915 | return; |
| 2916 | |
| 2917 | /* device_type is already set, just change it. */ |
| 2918 | |
| 2919 | prom_printf("Changing device_type of SB600 node...\n"); |
| 2920 | |
| 2921 | prom_setprop(iob, name, "device_type", "isa", sizeof("isa")); |
Darren Stevens | 5024678 | 2016-08-31 13:24:40 +0100 | [diff] [blame] | 2922 | } |
| 2923 | #else /* !CONFIG_PPC_PASEMI_NEMO */ |
| 2924 | static inline void fixup_device_tree_pasemi(void) { } |
| 2925 | #endif |
| 2926 | |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2927 | static void __init fixup_device_tree(void) |
| 2928 | { |
| 2929 | fixup_device_tree_maple(); |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2930 | fixup_device_tree_maple_memory_controller(); |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2931 | fixup_device_tree_chrp(); |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2932 | fixup_device_tree_pmac(); |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2933 | fixup_device_tree_efika(); |
Darren Stevens | 5024678 | 2016-08-31 13:24:40 +0100 | [diff] [blame] | 2934 | fixup_device_tree_pasemi(); |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2935 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2936 | |
| 2937 | static void __init prom_find_boot_cpu(void) |
| 2938 | { |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2939 | __be32 rval; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2940 | ihandle prom_cpu; |
| 2941 | phandle cpu_pkg; |
| 2942 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2943 | rval = 0; |
| 2944 | if (prom_getprop(prom.chosen, "cpu", &rval, sizeof(rval)) <= 0) |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2945 | return; |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2946 | prom_cpu = be32_to_cpu(rval); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2947 | |
| 2948 | cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu); |
| 2949 | |
Darren Stevens | af2b7fa | 2017-01-23 19:42:54 +0000 | [diff] [blame] | 2950 | if (!PHANDLE_VALID(cpu_pkg)) |
| 2951 | return; |
| 2952 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2953 | prom_getprop(cpu_pkg, "reg", &rval, sizeof(rval)); |
| 2954 | prom.cpu = be32_to_cpu(rval); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2955 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 2956 | prom_debug("Booting CPU hw index = %d\n", prom.cpu); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | static void __init prom_check_initrd(unsigned long r3, unsigned long r4) |
| 2960 | { |
| 2961 | #ifdef CONFIG_BLK_DEV_INITRD |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2962 | if (r3 && r4 && r4 != 0xdeadbeef) { |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2963 | __be64 val; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2964 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2965 | prom_initrd_start = is_kernel_addr(r3) ? __pa(r3) : r3; |
| 2966 | prom_initrd_end = prom_initrd_start + r4; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2967 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2968 | val = cpu_to_be64(prom_initrd_start); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2969 | prom_setprop(prom.chosen, "/chosen", "linux,initrd-start", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2970 | &val, sizeof(val)); |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 2971 | val = cpu_to_be64(prom_initrd_end); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2972 | prom_setprop(prom.chosen, "/chosen", "linux,initrd-end", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2973 | &val, sizeof(val)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2974 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2975 | reserve_mem(prom_initrd_start, |
| 2976 | prom_initrd_end - prom_initrd_start); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2977 | |
Mathieu Malaterre | eae5f70 | 2018-04-06 22:12:19 +0200 | [diff] [blame] | 2978 | prom_debug("initrd_start=0x%lx\n", prom_initrd_start); |
| 2979 | prom_debug("initrd_end=0x%lx\n", prom_initrd_end); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2980 | } |
| 2981 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 2982 | } |
| 2983 | |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 2984 | #ifdef CONFIG_PPC64 |
| 2985 | #ifdef CONFIG_RELOCATABLE |
| 2986 | static void reloc_toc(void) |
| 2987 | { |
| 2988 | } |
| 2989 | |
| 2990 | static void unreloc_toc(void) |
| 2991 | { |
| 2992 | } |
| 2993 | #else |
Anton Blanchard | 1674400 | 2013-03-12 01:51:51 +0000 | [diff] [blame] | 2994 | static void __reloc_toc(unsigned long offset, unsigned long nr_entries) |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 2995 | { |
| 2996 | unsigned long i; |
Anton Blanchard | 1674400 | 2013-03-12 01:51:51 +0000 | [diff] [blame] | 2997 | unsigned long *toc_entry; |
| 2998 | |
| 2999 | /* Get the start of the TOC by using r2 directly. */ |
| 3000 | asm volatile("addi %0,2,-0x8000" : "=b" (toc_entry)); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 3001 | |
| 3002 | for (i = 0; i < nr_entries; i++) { |
| 3003 | *toc_entry = *toc_entry + offset; |
| 3004 | toc_entry++; |
| 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | static void reloc_toc(void) |
| 3009 | { |
| 3010 | unsigned long offset = reloc_offset(); |
| 3011 | unsigned long nr_entries = |
| 3012 | (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long); |
| 3013 | |
Anton Blanchard | 1674400 | 2013-03-12 01:51:51 +0000 | [diff] [blame] | 3014 | __reloc_toc(offset, nr_entries); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 3015 | |
| 3016 | mb(); |
| 3017 | } |
| 3018 | |
| 3019 | static void unreloc_toc(void) |
| 3020 | { |
| 3021 | unsigned long offset = reloc_offset(); |
| 3022 | unsigned long nr_entries = |
| 3023 | (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long); |
| 3024 | |
| 3025 | mb(); |
| 3026 | |
Anton Blanchard | 1674400 | 2013-03-12 01:51:51 +0000 | [diff] [blame] | 3027 | __reloc_toc(-offset, nr_entries); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 3028 | } |
| 3029 | #endif |
| 3030 | #endif |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 3031 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3032 | /* |
| 3033 | * We enter here early on, when the Open Firmware prom is still |
| 3034 | * handling exceptions and the MMU hash table for us. |
| 3035 | */ |
| 3036 | |
| 3037 | unsigned long __init prom_init(unsigned long r3, unsigned long r4, |
| 3038 | unsigned long pp, |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 3039 | unsigned long r6, unsigned long r7, |
| 3040 | unsigned long kbase) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3041 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3042 | unsigned long hdr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3043 | |
| 3044 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 3045 | unsigned long offset = reloc_offset(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3046 | reloc_got2(offset); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 3047 | #else |
| 3048 | reloc_toc(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3049 | #endif |
| 3050 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3051 | /* |
| 3052 | * First zero the BSS |
| 3053 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3054 | memset(&__bss_start, 0, __bss_stop - __bss_start); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3055 | |
| 3056 | /* |
| 3057 | * Init interface to Open Firmware, get some node references, |
| 3058 | * like /chosen |
| 3059 | */ |
| 3060 | prom_init_client_services(pp); |
| 3061 | |
| 3062 | /* |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 3063 | * See if this OF is old enough that we need to do explicit maps |
| 3064 | * and other workarounds |
| 3065 | */ |
| 3066 | prom_find_mmu(); |
| 3067 | |
| 3068 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3069 | * Init prom stdout device |
| 3070 | */ |
| 3071 | prom_init_stdout(); |
| 3072 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3073 | prom_printf("Preparing to boot %s", linux_banner); |
Michael Ellerman | e7943fb | 2009-03-04 19:02:01 +0000 | [diff] [blame] | 3074 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3075 | /* |
| 3076 | * Get default machine type. At this point, we do not differentiate |
| 3077 | * between pSeries SMP and pSeries LPAR |
| 3078 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3079 | of_platform = prom_find_machine_type(); |
| 3080 | prom_printf("Detected machine type: %x\n", of_platform); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3081 | |
Suzuki Poulose | 0f890c8 | 2011-12-14 22:57:15 +0000 | [diff] [blame] | 3082 | #ifndef CONFIG_NONSTATIC_KERNEL |
Olaf Hering | add60ef | 2006-03-23 22:03:57 +0100 | [diff] [blame] | 3083 | /* Bail if this is a kdump kernel. */ |
| 3084 | if (PHYSICAL_START > 0) |
| 3085 | prom_panic("Error: You can't boot a kdump kernel from OF!\n"); |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 3086 | #endif |
Olaf Hering | add60ef | 2006-03-23 22:03:57 +0100 | [diff] [blame] | 3087 | |
| 3088 | /* |
| 3089 | * Check for an initrd |
| 3090 | */ |
| 3091 | prom_check_initrd(r3, r4); |
| 3092 | |
Suraj Jitindar Singh | 12cc9fd | 2017-02-28 17:03:47 +1100 | [diff] [blame] | 3093 | /* |
| 3094 | * Do early parsing of command line |
| 3095 | */ |
| 3096 | early_cmdline_parse(); |
| 3097 | |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 3098 | #ifdef CONFIG_PPC_PSERIES |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3099 | /* |
| 3100 | * On pSeries, inform the firmware about our capabilities |
| 3101 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3102 | if (of_platform == PLATFORM_PSERIES || |
| 3103 | of_platform == PLATFORM_PSERIES_LPAR) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3104 | prom_send_capabilities(); |
| 3105 | #endif |
| 3106 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3107 | /* |
Arnd Bergmann | f3f66f5 | 2005-10-31 20:08:37 -0500 | [diff] [blame] | 3108 | * Copy the CPU hold code |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3109 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3110 | if (of_platform != PLATFORM_POWERMAC) |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 3111 | copy_and_flush(0, kbase, 0x100, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3112 | |
| 3113 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3114 | * Initialize memory management within prom_init |
| 3115 | */ |
| 3116 | prom_init_mem(); |
| 3117 | |
| 3118 | /* |
| 3119 | * Determine which cpu is actually running right _now_ |
| 3120 | */ |
| 3121 | prom_find_boot_cpu(); |
| 3122 | |
| 3123 | /* |
| 3124 | * Initialize display devices |
| 3125 | */ |
| 3126 | prom_check_displays(); |
| 3127 | |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 3128 | #if defined(CONFIG_PPC64) && defined(__BIG_ENDIAN__) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3129 | /* |
| 3130 | * Initialize IOMMU (TCE tables) on pSeries. Do that before anything else |
| 3131 | * that uses the allocator, we need to make sure we get the top of memory |
| 3132 | * available for us here... |
| 3133 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3134 | if (of_platform == PLATFORM_PSERIES) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3135 | prom_initialize_tce_table(); |
| 3136 | #endif |
| 3137 | |
| 3138 | /* |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 3139 | * On non-powermacs, try to instantiate RTAS. PowerMacs don't |
| 3140 | * have a usable RTAS implementation. |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3141 | */ |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 3142 | if (of_platform != PLATFORM_POWERMAC) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3143 | prom_instantiate_rtas(); |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 3144 | |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 3145 | #ifdef CONFIG_PPC64 |
| 3146 | /* instantiate sml */ |
| 3147 | prom_instantiate_sml(); |
| 3148 | #endif |
| 3149 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 3150 | /* |
| 3151 | * On non-powermacs, put all CPUs in spin-loops. |
| 3152 | * |
| 3153 | * PowerMacs use a different mechanism to spin CPUs |
Benjamin Herrenschmidt | dbe78b4 | 2013-09-25 14:02:50 +1000 | [diff] [blame] | 3154 | * |
| 3155 | * (This must be done after instanciating RTAS) |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 3156 | */ |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 3157 | if (of_platform != PLATFORM_POWERMAC) |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 3158 | prom_hold_cpus(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3159 | |
| 3160 | /* |
| 3161 | * Fill in some infos for use by the kernel later on |
| 3162 | */ |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 3163 | if (prom_memory_limit) { |
| 3164 | __be64 val = cpu_to_be64(prom_memory_limit); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3165 | prom_setprop(prom.chosen, "/chosen", "linux,memory-limit", |
Benjamin Herrenschmidt | 493adff | 2013-08-07 02:01:38 +1000 | [diff] [blame] | 3166 | &val, sizeof(val)); |
| 3167 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3168 | #ifdef CONFIG_PPC64 |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3169 | if (prom_iommu_off) |
| 3170 | prom_setprop(prom.chosen, "/chosen", "linux,iommu-off", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 3171 | NULL, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3172 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3173 | if (prom_iommu_force_on) |
| 3174 | prom_setprop(prom.chosen, "/chosen", "linux,iommu-force-on", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 3175 | NULL, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3176 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3177 | if (prom_tce_alloc_start) { |
| 3178 | prom_setprop(prom.chosen, "/chosen", "linux,tce-alloc-start", |
| 3179 | &prom_tce_alloc_start, |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3180 | sizeof(prom_tce_alloc_start)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3181 | prom_setprop(prom.chosen, "/chosen", "linux,tce-alloc-end", |
| 3182 | &prom_tce_alloc_end, |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3183 | sizeof(prom_tce_alloc_end)); |
| 3184 | } |
| 3185 | #endif |
| 3186 | |
| 3187 | /* |
| 3188 | * Fixup any known bugs in the device-tree |
| 3189 | */ |
| 3190 | fixup_device_tree(); |
| 3191 | |
| 3192 | /* |
| 3193 | * Now finally create the flattened device-tree |
| 3194 | */ |
Anton Blanchard | 1f8737a | 2009-03-31 20:06:15 +0000 | [diff] [blame] | 3195 | prom_printf("copying OF device tree...\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3196 | flatten_device_tree(); |
| 3197 | |
Paul Mackerras | 3825ac0 | 2005-11-08 22:48:08 +1100 | [diff] [blame] | 3198 | /* |
| 3199 | * in case stdin is USB and still active on IBM machines... |
| 3200 | * Unfortunately quiesce crashes on some powermacs if we have |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 3201 | * closed stdin already (in particular the powerbook 101). |
Paul Mackerras | 3825ac0 | 2005-11-08 22:48:08 +1100 | [diff] [blame] | 3202 | */ |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 3203 | if (of_platform != PLATFORM_POWERMAC) |
Paul Mackerras | 3825ac0 | 2005-11-08 22:48:08 +1100 | [diff] [blame] | 3204 | prom_close_stdin(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3205 | |
| 3206 | /* |
| 3207 | * Call OF "quiesce" method to shut down pending DMA's from |
| 3208 | * devices etc... |
| 3209 | */ |
Michael Ellerman | 7e862d7 | 2015-03-30 17:38:09 +1100 | [diff] [blame] | 3210 | prom_printf("Quiescing Open Firmware ...\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3211 | call_prom("quiesce", 0, 0); |
| 3212 | |
| 3213 | /* |
| 3214 | * And finally, call the kernel passing it the flattened device |
| 3215 | * tree and NULL as r5, thus triggering the new entry point which |
| 3216 | * is common to us and kexec |
| 3217 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3218 | hdr = dt_header_start; |
Benjamin Herrenschmidt | 40dfef6 | 2011-11-29 18:22:56 +0000 | [diff] [blame] | 3219 | |
| 3220 | /* Don't print anything after quiesce under OPAL, it crashes OFW */ |
Benjamin Herrenschmidt | 11fdb30 | 2018-10-15 13:49:53 +1100 | [diff] [blame] | 3221 | prom_printf("Booting Linux via __start() @ 0x%lx ...\n", kbase); |
| 3222 | prom_debug("->dt_header_start=0x%lx\n", hdr); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3223 | |
| 3224 | #ifdef CONFIG_PPC32 |
| 3225 | reloc_got2(-offset); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 3226 | #else |
| 3227 | unreloc_toc(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3228 | #endif |
| 3229 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 3230 | __start(hdr, kbase, 0, 0, 0, 0, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3231 | |
| 3232 | return 0; |
| 3233 | } |