setup.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. /*
  2. * S390 version
  3. * Copyright IBM Corp. 1999, 2012
  4. * Author(s): Hartmut Penner (hp@de.ibm.com),
  5. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  6. *
  7. * Derived from "arch/i386/kernel/setup.c"
  8. * Copyright (C) 1995, Linus Torvalds
  9. */
  10. /*
  11. * This file handles the architecture-dependent parts of initialization
  12. */
  13. #define KMSG_COMPONENT "setup"
  14. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  15. #include <linux/errno.h>
  16. #include <linux/export.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/memblock.h>
  20. #include <linux/mm.h>
  21. #include <linux/stddef.h>
  22. #include <linux/unistd.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/random.h>
  25. #include <linux/user.h>
  26. #include <linux/tty.h>
  27. #include <linux/ioport.h>
  28. #include <linux/delay.h>
  29. #include <linux/init.h>
  30. #include <linux/initrd.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/root_dev.h>
  33. #include <linux/console.h>
  34. #include <linux/kernel_stat.h>
  35. #include <linux/device.h>
  36. #include <linux/notifier.h>
  37. #include <linux/pfn.h>
  38. #include <linux/ctype.h>
  39. #include <linux/reboot.h>
  40. #include <linux/topology.h>
  41. #include <linux/kexec.h>
  42. #include <linux/crash_dump.h>
  43. #include <linux/memory.h>
  44. #include <linux/compat.h>
  45. #include <asm/ipl.h>
  46. #include <asm/facility.h>
  47. #include <asm/smp.h>
  48. #include <asm/mmu_context.h>
  49. #include <asm/cpcmd.h>
  50. #include <asm/lowcore.h>
  51. #include <asm/irq.h>
  52. #include <asm/page.h>
  53. #include <asm/ptrace.h>
  54. #include <asm/sections.h>
  55. #include <asm/ebcdic.h>
  56. #include <asm/kvm_virtio.h>
  57. #include <asm/diag.h>
  58. #include <asm/os_info.h>
  59. #include <asm/sclp.h>
  60. #include <asm/sysinfo.h>
  61. #include <asm/numa.h>
  62. #include <asm/alternative.h>
  63. #include <asm/nospec-branch.h>
  64. #include "entry.h"
  65. /*
  66. * Machine setup..
  67. */
  68. unsigned int console_mode = 0;
  69. EXPORT_SYMBOL(console_mode);
  70. unsigned int console_devno = -1;
  71. EXPORT_SYMBOL(console_devno);
  72. unsigned int console_irq = -1;
  73. EXPORT_SYMBOL(console_irq);
  74. unsigned long elf_hwcap __read_mostly = 0;
  75. char elf_platform[ELF_PLATFORM_SIZE];
  76. unsigned long int_hwcap = 0;
  77. int __initdata memory_end_set;
  78. unsigned long __initdata memory_end;
  79. unsigned long __initdata max_physmem_end;
  80. unsigned long VMALLOC_START;
  81. EXPORT_SYMBOL(VMALLOC_START);
  82. unsigned long VMALLOC_END;
  83. EXPORT_SYMBOL(VMALLOC_END);
  84. struct page *vmemmap;
  85. EXPORT_SYMBOL(vmemmap);
  86. unsigned long MODULES_VADDR;
  87. unsigned long MODULES_END;
  88. /* An array with a pointer to the lowcore of every CPU. */
  89. struct lowcore *lowcore_ptr[NR_CPUS];
  90. EXPORT_SYMBOL(lowcore_ptr);
  91. /*
  92. * This is set up by the setup-routine at boot-time
  93. * for S390 need to find out, what we have to setup
  94. * using address 0x10400 ...
  95. */
  96. #include <asm/setup.h>
  97. /*
  98. * condev= and conmode= setup parameter.
  99. */
  100. static int __init condev_setup(char *str)
  101. {
  102. int vdev;
  103. vdev = simple_strtoul(str, &str, 0);
  104. if (vdev >= 0 && vdev < 65536) {
  105. console_devno = vdev;
  106. console_irq = -1;
  107. }
  108. return 1;
  109. }
  110. __setup("condev=", condev_setup);
  111. static void __init set_preferred_console(void)
  112. {
  113. if (CONSOLE_IS_3215 || CONSOLE_IS_SCLP)
  114. add_preferred_console("ttyS", 0, NULL);
  115. else if (CONSOLE_IS_3270)
  116. add_preferred_console("tty3270", 0, NULL);
  117. else if (CONSOLE_IS_VT220)
  118. add_preferred_console("ttyS", 1, NULL);
  119. else if (CONSOLE_IS_HVC)
  120. add_preferred_console("hvc", 0, NULL);
  121. }
  122. static int __init conmode_setup(char *str)
  123. {
  124. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  125. if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
  126. SET_CONSOLE_SCLP;
  127. #endif
  128. #if defined(CONFIG_TN3215_CONSOLE)
  129. if (strncmp(str, "3215", 5) == 0)
  130. SET_CONSOLE_3215;
  131. #endif
  132. #if defined(CONFIG_TN3270_CONSOLE)
  133. if (strncmp(str, "3270", 5) == 0)
  134. SET_CONSOLE_3270;
  135. #endif
  136. set_preferred_console();
  137. return 1;
  138. }
  139. __setup("conmode=", conmode_setup);
  140. static void __init conmode_default(void)
  141. {
  142. char query_buffer[1024];
  143. char *ptr;
  144. if (MACHINE_IS_VM) {
  145. cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
  146. console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
  147. ptr = strstr(query_buffer, "SUBCHANNEL =");
  148. console_irq = simple_strtoul(ptr + 13, NULL, 16);
  149. cpcmd("QUERY TERM", query_buffer, 1024, NULL);
  150. ptr = strstr(query_buffer, "CONMODE");
  151. /*
  152. * Set the conmode to 3215 so that the device recognition
  153. * will set the cu_type of the console to 3215. If the
  154. * conmode is 3270 and we don't set it back then both
  155. * 3215 and the 3270 driver will try to access the console
  156. * device (3215 as console and 3270 as normal tty).
  157. */
  158. cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
  159. if (ptr == NULL) {
  160. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  161. SET_CONSOLE_SCLP;
  162. #endif
  163. return;
  164. }
  165. if (strncmp(ptr + 8, "3270", 4) == 0) {
  166. #if defined(CONFIG_TN3270_CONSOLE)
  167. SET_CONSOLE_3270;
  168. #elif defined(CONFIG_TN3215_CONSOLE)
  169. SET_CONSOLE_3215;
  170. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  171. SET_CONSOLE_SCLP;
  172. #endif
  173. } else if (strncmp(ptr + 8, "3215", 4) == 0) {
  174. #if defined(CONFIG_TN3215_CONSOLE)
  175. SET_CONSOLE_3215;
  176. #elif defined(CONFIG_TN3270_CONSOLE)
  177. SET_CONSOLE_3270;
  178. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  179. SET_CONSOLE_SCLP;
  180. #endif
  181. }
  182. } else if (MACHINE_IS_KVM) {
  183. if (sclp.has_vt220 && IS_ENABLED(CONFIG_SCLP_VT220_CONSOLE))
  184. SET_CONSOLE_VT220;
  185. else if (sclp.has_linemode && IS_ENABLED(CONFIG_SCLP_CONSOLE))
  186. SET_CONSOLE_SCLP;
  187. else
  188. SET_CONSOLE_HVC;
  189. } else {
  190. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  191. SET_CONSOLE_SCLP;
  192. #endif
  193. }
  194. }
  195. #ifdef CONFIG_CRASH_DUMP
  196. static void __init setup_zfcpdump(void)
  197. {
  198. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  199. return;
  200. if (OLDMEM_BASE)
  201. return;
  202. strcat(boot_command_line, " cio_ignore=all,!ipldev,!condev");
  203. console_loglevel = 2;
  204. }
  205. #else
  206. static inline void setup_zfcpdump(void) {}
  207. #endif /* CONFIG_CRASH_DUMP */
  208. /*
  209. * Reboot, halt and power_off stubs. They just call _machine_restart,
  210. * _machine_halt or _machine_power_off.
  211. */
  212. void machine_restart(char *command)
  213. {
  214. if ((!in_interrupt() && !in_atomic()) || oops_in_progress)
  215. /*
  216. * Only unblank the console if we are called in enabled
  217. * context or a bust_spinlocks cleared the way for us.
  218. */
  219. console_unblank();
  220. _machine_restart(command);
  221. }
  222. void machine_halt(void)
  223. {
  224. if (!in_interrupt() || oops_in_progress)
  225. /*
  226. * Only unblank the console if we are called in enabled
  227. * context or a bust_spinlocks cleared the way for us.
  228. */
  229. console_unblank();
  230. _machine_halt();
  231. }
  232. void machine_power_off(void)
  233. {
  234. if (!in_interrupt() || oops_in_progress)
  235. /*
  236. * Only unblank the console if we are called in enabled
  237. * context or a bust_spinlocks cleared the way for us.
  238. */
  239. console_unblank();
  240. _machine_power_off();
  241. }
  242. /*
  243. * Dummy power off function.
  244. */
  245. void (*pm_power_off)(void) = machine_power_off;
  246. EXPORT_SYMBOL_GPL(pm_power_off);
  247. static int __init early_parse_mem(char *p)
  248. {
  249. memory_end = memparse(p, &p);
  250. memory_end &= PAGE_MASK;
  251. memory_end_set = 1;
  252. return 0;
  253. }
  254. early_param("mem", early_parse_mem);
  255. static int __init parse_vmalloc(char *arg)
  256. {
  257. if (!arg)
  258. return -EINVAL;
  259. VMALLOC_END = (memparse(arg, &arg) + PAGE_SIZE - 1) & PAGE_MASK;
  260. return 0;
  261. }
  262. early_param("vmalloc", parse_vmalloc);
  263. void *restart_stack __section(.data);
  264. static void __init setup_lowcore(void)
  265. {
  266. struct lowcore *lc;
  267. /*
  268. * Setup lowcore for boot cpu
  269. */
  270. BUILD_BUG_ON(sizeof(struct lowcore) != LC_PAGES * 4096);
  271. lc = __alloc_bootmem_low(LC_PAGES * PAGE_SIZE, LC_PAGES * PAGE_SIZE, 0);
  272. lc->restart_psw.mask = PSW_KERNEL_BITS;
  273. lc->restart_psw.addr = (unsigned long) restart_int_handler;
  274. lc->external_new_psw.mask = PSW_KERNEL_BITS |
  275. PSW_MASK_DAT | PSW_MASK_MCHECK;
  276. lc->external_new_psw.addr = (unsigned long) ext_int_handler;
  277. lc->svc_new_psw.mask = PSW_KERNEL_BITS |
  278. PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
  279. lc->svc_new_psw.addr = (unsigned long) system_call;
  280. lc->program_new_psw.mask = PSW_KERNEL_BITS |
  281. PSW_MASK_DAT | PSW_MASK_MCHECK;
  282. lc->program_new_psw.addr = (unsigned long) pgm_check_handler;
  283. lc->mcck_new_psw.mask = PSW_KERNEL_BITS;
  284. lc->mcck_new_psw.addr = (unsigned long) mcck_int_handler;
  285. lc->io_new_psw.mask = PSW_KERNEL_BITS |
  286. PSW_MASK_DAT | PSW_MASK_MCHECK;
  287. lc->io_new_psw.addr = (unsigned long) io_int_handler;
  288. lc->clock_comparator = -1ULL;
  289. lc->kernel_stack = ((unsigned long) &init_thread_union)
  290. + THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  291. lc->async_stack = (unsigned long)
  292. __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0)
  293. + ASYNC_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  294. lc->panic_stack = (unsigned long)
  295. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0)
  296. + PAGE_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  297. lc->current_task = (unsigned long) init_thread_union.thread_info.task;
  298. lc->thread_info = (unsigned long) &init_thread_union;
  299. lc->lpp = LPP_MAGIC;
  300. lc->machine_flags = S390_lowcore.machine_flags;
  301. lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
  302. memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
  303. sizeof(lc->stfle_fac_list));
  304. memcpy(lc->alt_stfle_fac_list, S390_lowcore.alt_stfle_fac_list,
  305. sizeof(lc->alt_stfle_fac_list));
  306. if (MACHINE_HAS_VX)
  307. lc->vector_save_area_addr =
  308. (unsigned long) &lc->vector_save_area;
  309. lc->vdso_per_cpu_data = (unsigned long) &lc->paste[0];
  310. lc->sync_enter_timer = S390_lowcore.sync_enter_timer;
  311. lc->async_enter_timer = S390_lowcore.async_enter_timer;
  312. lc->exit_timer = S390_lowcore.exit_timer;
  313. lc->user_timer = S390_lowcore.user_timer;
  314. lc->system_timer = S390_lowcore.system_timer;
  315. lc->steal_timer = S390_lowcore.steal_timer;
  316. lc->last_update_timer = S390_lowcore.last_update_timer;
  317. lc->last_update_clock = S390_lowcore.last_update_clock;
  318. restart_stack = __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0);
  319. restart_stack += ASYNC_SIZE;
  320. /*
  321. * Set up PSW restart to call ipl.c:do_restart(). Copy the relevant
  322. * restart data to the absolute zero lowcore. This is necessary if
  323. * PSW restart is done on an offline CPU that has lowcore zero.
  324. */
  325. lc->restart_stack = (unsigned long) restart_stack;
  326. lc->restart_fn = (unsigned long) do_restart;
  327. lc->restart_data = 0;
  328. lc->restart_source = -1UL;
  329. /* Setup absolute zero lowcore */
  330. mem_assign_absolute(S390_lowcore.restart_stack, lc->restart_stack);
  331. mem_assign_absolute(S390_lowcore.restart_fn, lc->restart_fn);
  332. mem_assign_absolute(S390_lowcore.restart_data, lc->restart_data);
  333. mem_assign_absolute(S390_lowcore.restart_source, lc->restart_source);
  334. mem_assign_absolute(S390_lowcore.restart_psw, lc->restart_psw);
  335. #ifdef CONFIG_SMP
  336. lc->spinlock_lockval = arch_spin_lockval(0);
  337. #endif
  338. lc->br_r1_trampoline = 0x07f1; /* br %r1 */
  339. set_prefix((u32)(unsigned long) lc);
  340. lowcore_ptr[0] = lc;
  341. }
  342. static struct resource code_resource = {
  343. .name = "Kernel code",
  344. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
  345. };
  346. static struct resource data_resource = {
  347. .name = "Kernel data",
  348. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
  349. };
  350. static struct resource bss_resource = {
  351. .name = "Kernel bss",
  352. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
  353. };
  354. static struct resource __initdata *standard_resources[] = {
  355. &code_resource,
  356. &data_resource,
  357. &bss_resource,
  358. };
  359. static void __init setup_resources(void)
  360. {
  361. struct resource *res, *std_res, *sub_res;
  362. struct memblock_region *reg;
  363. int j;
  364. code_resource.start = (unsigned long) &_text;
  365. code_resource.end = (unsigned long) &_etext - 1;
  366. data_resource.start = (unsigned long) &_etext;
  367. data_resource.end = (unsigned long) &_edata - 1;
  368. bss_resource.start = (unsigned long) &__bss_start;
  369. bss_resource.end = (unsigned long) &__bss_stop - 1;
  370. for_each_memblock(memory, reg) {
  371. res = alloc_bootmem_low(sizeof(*res));
  372. res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM;
  373. res->name = "System RAM";
  374. res->start = reg->base;
  375. res->end = reg->base + reg->size - 1;
  376. request_resource(&iomem_resource, res);
  377. for (j = 0; j < ARRAY_SIZE(standard_resources); j++) {
  378. std_res = standard_resources[j];
  379. if (std_res->start < res->start ||
  380. std_res->start > res->end)
  381. continue;
  382. if (std_res->end > res->end) {
  383. sub_res = alloc_bootmem_low(sizeof(*sub_res));
  384. *sub_res = *std_res;
  385. sub_res->end = res->end;
  386. std_res->start = res->end + 1;
  387. request_resource(res, sub_res);
  388. } else {
  389. request_resource(res, std_res);
  390. }
  391. }
  392. }
  393. #ifdef CONFIG_CRASH_DUMP
  394. /*
  395. * Re-add removed crash kernel memory as reserved memory. This makes
  396. * sure it will be mapped with the identity mapping and struct pages
  397. * will be created, so it can be resized later on.
  398. * However add it later since the crash kernel resource should not be
  399. * part of the System RAM resource.
  400. */
  401. if (crashk_res.end) {
  402. memblock_add_node(crashk_res.start, resource_size(&crashk_res), 0);
  403. memblock_reserve(crashk_res.start, resource_size(&crashk_res));
  404. insert_resource(&iomem_resource, &crashk_res);
  405. }
  406. #endif
  407. }
  408. static void __init setup_memory_end(void)
  409. {
  410. unsigned long vmax, vmalloc_size, tmp;
  411. /* Choose kernel address space layout: 2, 3, or 4 levels. */
  412. vmalloc_size = VMALLOC_END ?: (128UL << 30) - MODULES_LEN;
  413. tmp = (memory_end ?: max_physmem_end) / PAGE_SIZE;
  414. tmp = tmp * (sizeof(struct page) + PAGE_SIZE);
  415. if (tmp + vmalloc_size + MODULES_LEN <= (1UL << 42))
  416. vmax = 1UL << 42; /* 3-level kernel page table */
  417. else
  418. vmax = 1UL << 53; /* 4-level kernel page table */
  419. /* module area is at the end of the kernel address space. */
  420. MODULES_END = vmax;
  421. MODULES_VADDR = MODULES_END - MODULES_LEN;
  422. VMALLOC_END = MODULES_VADDR;
  423. VMALLOC_START = vmax - vmalloc_size;
  424. /* Split remaining virtual space between 1:1 mapping & vmemmap array */
  425. tmp = VMALLOC_START / (PAGE_SIZE + sizeof(struct page));
  426. /* vmemmap contains a multiple of PAGES_PER_SECTION struct pages */
  427. tmp = SECTION_ALIGN_UP(tmp);
  428. tmp = VMALLOC_START - tmp * sizeof(struct page);
  429. tmp &= ~((vmax >> 11) - 1); /* align to page table level */
  430. tmp = min(tmp, 1UL << MAX_PHYSMEM_BITS);
  431. vmemmap = (struct page *) tmp;
  432. /* Take care that memory_end is set and <= vmemmap */
  433. memory_end = min(memory_end ?: max_physmem_end, tmp);
  434. max_pfn = max_low_pfn = PFN_DOWN(memory_end);
  435. memblock_remove(memory_end, ULONG_MAX);
  436. pr_notice("Max memory size: %luMB\n", memory_end >> 20);
  437. }
  438. static void __init setup_vmcoreinfo(void)
  439. {
  440. mem_assign_absolute(S390_lowcore.vmcore_info, paddr_vmcoreinfo_note());
  441. }
  442. #ifdef CONFIG_CRASH_DUMP
  443. /*
  444. * When kdump is enabled, we have to ensure that no memory from
  445. * the area [0 - crashkernel memory size] and
  446. * [crashk_res.start - crashk_res.end] is set offline.
  447. */
  448. static int kdump_mem_notifier(struct notifier_block *nb,
  449. unsigned long action, void *data)
  450. {
  451. struct memory_notify *arg = data;
  452. if (action != MEM_GOING_OFFLINE)
  453. return NOTIFY_OK;
  454. if (arg->start_pfn < PFN_DOWN(resource_size(&crashk_res)))
  455. return NOTIFY_BAD;
  456. if (arg->start_pfn > PFN_DOWN(crashk_res.end))
  457. return NOTIFY_OK;
  458. if (arg->start_pfn + arg->nr_pages - 1 < PFN_DOWN(crashk_res.start))
  459. return NOTIFY_OK;
  460. return NOTIFY_BAD;
  461. }
  462. static struct notifier_block kdump_mem_nb = {
  463. .notifier_call = kdump_mem_notifier,
  464. };
  465. #endif
  466. /*
  467. * Make sure that the area behind memory_end is protected
  468. */
  469. static void reserve_memory_end(void)
  470. {
  471. #ifdef CONFIG_CRASH_DUMP
  472. if (ipl_info.type == IPL_TYPE_FCP_DUMP &&
  473. !OLDMEM_BASE && sclp.hsa_size) {
  474. memory_end = sclp.hsa_size;
  475. memory_end &= PAGE_MASK;
  476. memory_end_set = 1;
  477. }
  478. #endif
  479. if (!memory_end_set)
  480. return;
  481. memblock_reserve(memory_end, ULONG_MAX);
  482. }
  483. /*
  484. * Make sure that oldmem, where the dump is stored, is protected
  485. */
  486. static void reserve_oldmem(void)
  487. {
  488. #ifdef CONFIG_CRASH_DUMP
  489. if (OLDMEM_BASE)
  490. /* Forget all memory above the running kdump system */
  491. memblock_reserve(OLDMEM_SIZE, (phys_addr_t)ULONG_MAX);
  492. #endif
  493. }
  494. /*
  495. * Make sure that oldmem, where the dump is stored, is protected
  496. */
  497. static void remove_oldmem(void)
  498. {
  499. #ifdef CONFIG_CRASH_DUMP
  500. if (OLDMEM_BASE)
  501. /* Forget all memory above the running kdump system */
  502. memblock_remove(OLDMEM_SIZE, (phys_addr_t)ULONG_MAX);
  503. #endif
  504. }
  505. /*
  506. * Reserve memory for kdump kernel to be loaded with kexec
  507. */
  508. static void __init reserve_crashkernel(void)
  509. {
  510. #ifdef CONFIG_CRASH_DUMP
  511. unsigned long long crash_base, crash_size;
  512. phys_addr_t low, high;
  513. int rc;
  514. rc = parse_crashkernel(boot_command_line, memory_end, &crash_size,
  515. &crash_base);
  516. crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
  517. crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);
  518. if (rc || crash_size == 0)
  519. return;
  520. if (memblock.memory.regions[0].size < crash_size) {
  521. pr_info("crashkernel reservation failed: %s\n",
  522. "first memory chunk must be at least crashkernel size");
  523. return;
  524. }
  525. low = crash_base ?: OLDMEM_BASE;
  526. high = low + crash_size;
  527. if (low >= OLDMEM_BASE && high <= OLDMEM_BASE + OLDMEM_SIZE) {
  528. /* The crashkernel fits into OLDMEM, reuse OLDMEM */
  529. crash_base = low;
  530. } else {
  531. /* Find suitable area in free memory */
  532. low = max_t(unsigned long, crash_size, sclp.hsa_size);
  533. high = crash_base ? crash_base + crash_size : ULONG_MAX;
  534. if (crash_base && crash_base < low) {
  535. pr_info("crashkernel reservation failed: %s\n",
  536. "crash_base too low");
  537. return;
  538. }
  539. low = crash_base ?: low;
  540. crash_base = memblock_find_in_range(low, high, crash_size,
  541. KEXEC_CRASH_MEM_ALIGN);
  542. }
  543. if (!crash_base) {
  544. pr_info("crashkernel reservation failed: %s\n",
  545. "no suitable area found");
  546. return;
  547. }
  548. if (register_memory_notifier(&kdump_mem_nb))
  549. return;
  550. if (!OLDMEM_BASE && MACHINE_IS_VM)
  551. diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size));
  552. crashk_res.start = crash_base;
  553. crashk_res.end = crash_base + crash_size - 1;
  554. memblock_remove(crash_base, crash_size);
  555. pr_info("Reserving %lluMB of memory at %lluMB "
  556. "for crashkernel (System RAM: %luMB)\n",
  557. crash_size >> 20, crash_base >> 20,
  558. (unsigned long)memblock.memory.total_size >> 20);
  559. os_info_crashkernel_add(crash_base, crash_size);
  560. #endif
  561. }
  562. /*
  563. * Reserve the initrd from being used by memblock
  564. */
  565. static void __init reserve_initrd(void)
  566. {
  567. #ifdef CONFIG_BLK_DEV_INITRD
  568. initrd_start = INITRD_START;
  569. initrd_end = initrd_start + INITRD_SIZE;
  570. memblock_reserve(INITRD_START, INITRD_SIZE);
  571. #endif
  572. }
  573. /*
  574. * Check for initrd being in usable memory
  575. */
  576. static void __init check_initrd(void)
  577. {
  578. #ifdef CONFIG_BLK_DEV_INITRD
  579. if (INITRD_START && INITRD_SIZE &&
  580. !memblock_is_region_memory(INITRD_START, INITRD_SIZE)) {
  581. pr_err("initrd does not fit memory.\n");
  582. memblock_free(INITRD_START, INITRD_SIZE);
  583. initrd_start = initrd_end = 0;
  584. }
  585. #endif
  586. }
  587. /*
  588. * Reserve memory used for lowcore/command line/kernel image.
  589. */
  590. static void __init reserve_kernel(void)
  591. {
  592. unsigned long start_pfn = PFN_UP(__pa(&_end));
  593. #ifdef CONFIG_DMA_API_DEBUG
  594. /*
  595. * DMA_API_DEBUG code stumbles over addresses from the
  596. * range [_ehead, _stext]. Mark the memory as reserved
  597. * so it is not used for CONFIG_DMA_API_DEBUG=y.
  598. */
  599. memblock_reserve(0, PFN_PHYS(start_pfn));
  600. #else
  601. memblock_reserve(0, (unsigned long)_ehead);
  602. memblock_reserve((unsigned long)_stext, PFN_PHYS(start_pfn)
  603. - (unsigned long)_stext);
  604. #endif
  605. }
  606. static void __init setup_memory(void)
  607. {
  608. struct memblock_region *reg;
  609. /*
  610. * Init storage key for present memory
  611. */
  612. for_each_memblock(memory, reg) {
  613. storage_key_init_range(reg->base, reg->base + reg->size);
  614. }
  615. psw_set_key(PAGE_DEFAULT_KEY);
  616. /* Only cosmetics */
  617. memblock_enforce_memory_limit(memblock_end_of_DRAM());
  618. }
  619. /*
  620. * Setup hardware capabilities.
  621. */
  622. static int __init setup_hwcaps(void)
  623. {
  624. static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
  625. struct cpuid cpu_id;
  626. int i;
  627. /*
  628. * The store facility list bits numbers as found in the principles
  629. * of operation are numbered with bit 1UL<<31 as number 0 to
  630. * bit 1UL<<0 as number 31.
  631. * Bit 0: instructions named N3, "backported" to esa-mode
  632. * Bit 2: z/Architecture mode is active
  633. * Bit 7: the store-facility-list-extended facility is installed
  634. * Bit 17: the message-security assist is installed
  635. * Bit 19: the long-displacement facility is installed
  636. * Bit 21: the extended-immediate facility is installed
  637. * Bit 22: extended-translation facility 3 is installed
  638. * Bit 30: extended-translation facility 3 enhancement facility
  639. * These get translated to:
  640. * HWCAP_S390_ESAN3 bit 0, HWCAP_S390_ZARCH bit 1,
  641. * HWCAP_S390_STFLE bit 2, HWCAP_S390_MSA bit 3,
  642. * HWCAP_S390_LDISP bit 4, HWCAP_S390_EIMM bit 5 and
  643. * HWCAP_S390_ETF3EH bit 8 (22 && 30).
  644. */
  645. for (i = 0; i < 6; i++)
  646. if (test_facility(stfl_bits[i]))
  647. elf_hwcap |= 1UL << i;
  648. if (test_facility(22) && test_facility(30))
  649. elf_hwcap |= HWCAP_S390_ETF3EH;
  650. /*
  651. * Check for additional facilities with store-facility-list-extended.
  652. * stfle stores doublewords (8 byte) with bit 1ULL<<63 as bit 0
  653. * and 1ULL<<0 as bit 63. Bits 0-31 contain the same information
  654. * as stored by stfl, bits 32-xxx contain additional facilities.
  655. * How many facility words are stored depends on the number of
  656. * doublewords passed to the instruction. The additional facilities
  657. * are:
  658. * Bit 42: decimal floating point facility is installed
  659. * Bit 44: perform floating point operation facility is installed
  660. * translated to:
  661. * HWCAP_S390_DFP bit 6 (42 && 44).
  662. */
  663. if ((elf_hwcap & (1UL << 2)) && test_facility(42) && test_facility(44))
  664. elf_hwcap |= HWCAP_S390_DFP;
  665. /*
  666. * Huge page support HWCAP_S390_HPAGE is bit 7.
  667. */
  668. if (MACHINE_HAS_HPAGE)
  669. elf_hwcap |= HWCAP_S390_HPAGE;
  670. /*
  671. * 64-bit register support for 31-bit processes
  672. * HWCAP_S390_HIGH_GPRS is bit 9.
  673. */
  674. elf_hwcap |= HWCAP_S390_HIGH_GPRS;
  675. /*
  676. * Transactional execution support HWCAP_S390_TE is bit 10.
  677. */
  678. if (test_facility(50) && test_facility(73))
  679. elf_hwcap |= HWCAP_S390_TE;
  680. /*
  681. * Vector extension HWCAP_S390_VXRS is bit 11. The Vector extension
  682. * can be disabled with the "novx" parameter. Use MACHINE_HAS_VX
  683. * instead of facility bit 129.
  684. */
  685. if (MACHINE_HAS_VX)
  686. elf_hwcap |= HWCAP_S390_VXRS;
  687. get_cpu_id(&cpu_id);
  688. add_device_randomness(&cpu_id, sizeof(cpu_id));
  689. switch (cpu_id.machine) {
  690. case 0x2064:
  691. case 0x2066:
  692. default: /* Use "z900" as default for 64 bit kernels. */
  693. strcpy(elf_platform, "z900");
  694. break;
  695. case 0x2084:
  696. case 0x2086:
  697. strcpy(elf_platform, "z990");
  698. break;
  699. case 0x2094:
  700. case 0x2096:
  701. strcpy(elf_platform, "z9-109");
  702. break;
  703. case 0x2097:
  704. case 0x2098:
  705. strcpy(elf_platform, "z10");
  706. break;
  707. case 0x2817:
  708. case 0x2818:
  709. strcpy(elf_platform, "z196");
  710. break;
  711. case 0x2827:
  712. case 0x2828:
  713. strcpy(elf_platform, "zEC12");
  714. break;
  715. case 0x2964:
  716. case 0x2965:
  717. strcpy(elf_platform, "z13");
  718. break;
  719. }
  720. /*
  721. * Virtualization support HWCAP_INT_SIE is bit 0.
  722. */
  723. if (sclp.has_sief2)
  724. int_hwcap |= HWCAP_INT_SIE;
  725. return 0;
  726. }
  727. arch_initcall(setup_hwcaps);
  728. /*
  729. * Add system information as device randomness
  730. */
  731. static void __init setup_randomness(void)
  732. {
  733. struct sysinfo_3_2_2 *vmms;
  734. vmms = (struct sysinfo_3_2_2 *) memblock_alloc(PAGE_SIZE, PAGE_SIZE);
  735. if (stsi(vmms, 3, 2, 2) == 0 && vmms->count)
  736. add_device_randomness(&vmms->vm, sizeof(vmms->vm[0]) * vmms->count);
  737. memblock_free((unsigned long) vmms, PAGE_SIZE);
  738. }
  739. /*
  740. * Find the correct size for the task_struct. This depends on
  741. * the size of the struct fpu at the end of the thread_struct
  742. * which is embedded in the task_struct.
  743. */
  744. static void __init setup_task_size(void)
  745. {
  746. int task_size = sizeof(struct task_struct);
  747. if (!MACHINE_HAS_VX) {
  748. task_size -= sizeof(__vector128) * __NUM_VXRS;
  749. task_size += sizeof(freg_t) * __NUM_FPRS;
  750. }
  751. arch_task_struct_size = task_size;
  752. }
  753. /*
  754. * Setup function called from init/main.c just after the banner
  755. * was printed.
  756. */
  757. void __init setup_arch(char **cmdline_p)
  758. {
  759. /*
  760. * print what head.S has found out about the machine
  761. */
  762. if (MACHINE_IS_VM)
  763. pr_info("Linux is running as a z/VM "
  764. "guest operating system in 64-bit mode\n");
  765. else if (MACHINE_IS_KVM)
  766. pr_info("Linux is running under KVM in 64-bit mode\n");
  767. else if (MACHINE_IS_LPAR)
  768. pr_info("Linux is running natively in 64-bit mode\n");
  769. /* Have one command line that is parsed and saved in /proc/cmdline */
  770. /* boot_command_line has been already set up in early.c */
  771. *cmdline_p = boot_command_line;
  772. ROOT_DEV = Root_RAM0;
  773. /* Is init_mm really needed? */
  774. init_mm.start_code = PAGE_OFFSET;
  775. init_mm.end_code = (unsigned long) &_etext;
  776. init_mm.end_data = (unsigned long) &_edata;
  777. init_mm.brk = (unsigned long) &_end;
  778. if (IS_ENABLED(CONFIG_EXPOLINE_AUTO))
  779. nospec_auto_detect();
  780. parse_early_param();
  781. #ifdef CONFIG_CRASH_DUMP
  782. /* Deactivate elfcorehdr= kernel parameter */
  783. elfcorehdr_addr = ELFCORE_ADDR_MAX;
  784. #endif
  785. os_info_init();
  786. setup_ipl();
  787. setup_task_size();
  788. /* Do some memory reservations *before* memory is added to memblock */
  789. reserve_memory_end();
  790. reserve_oldmem();
  791. reserve_kernel();
  792. reserve_initrd();
  793. memblock_allow_resize();
  794. /* Get information about *all* installed memory */
  795. detect_memory_memblock();
  796. remove_oldmem();
  797. /*
  798. * Make sure all chunks are MAX_ORDER aligned so we don't need the
  799. * extra checks that HOLES_IN_ZONE would require.
  800. *
  801. * Is this still required?
  802. */
  803. memblock_trim_memory(1UL << (MAX_ORDER - 1 + PAGE_SHIFT));
  804. setup_memory_end();
  805. setup_memory();
  806. check_initrd();
  807. reserve_crashkernel();
  808. #ifdef CONFIG_CRASH_DUMP
  809. /*
  810. * Be aware that smp_save_dump_cpus() triggers a system reset.
  811. * Therefore CPU and device initialization should be done afterwards.
  812. */
  813. smp_save_dump_cpus();
  814. #endif
  815. setup_resources();
  816. setup_vmcoreinfo();
  817. setup_lowcore();
  818. smp_fill_possible_mask();
  819. cpu_detect_mhz_feature();
  820. cpu_init();
  821. numa_setup();
  822. /*
  823. * Create kernel page tables and switch to virtual addressing.
  824. */
  825. paging_init();
  826. /* Setup default console */
  827. conmode_default();
  828. set_preferred_console();
  829. apply_alternative_instructions();
  830. if (IS_ENABLED(CONFIG_EXPOLINE))
  831. nospec_init_branches();
  832. /* Setup zfcpdump support */
  833. setup_zfcpdump();
  834. /* Add system specific data to the random pool */
  835. setup_randomness();
  836. }