setup.c 25 KB

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