setup.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  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 "entry.h"
  62. /*
  63. * Machine setup..
  64. */
  65. unsigned int console_mode = 0;
  66. EXPORT_SYMBOL(console_mode);
  67. unsigned int console_devno = -1;
  68. EXPORT_SYMBOL(console_devno);
  69. unsigned int console_irq = -1;
  70. EXPORT_SYMBOL(console_irq);
  71. unsigned long elf_hwcap = 0;
  72. char elf_platform[ELF_PLATFORM_SIZE];
  73. int __initdata memory_end_set;
  74. unsigned long __initdata memory_end;
  75. unsigned long __initdata max_physmem_end;
  76. unsigned long VMALLOC_START;
  77. EXPORT_SYMBOL(VMALLOC_START);
  78. unsigned long VMALLOC_END;
  79. EXPORT_SYMBOL(VMALLOC_END);
  80. struct page *vmemmap;
  81. EXPORT_SYMBOL(vmemmap);
  82. #ifdef CONFIG_64BIT
  83. unsigned long MODULES_VADDR;
  84. unsigned long MODULES_END;
  85. #endif
  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 (MACHINE_IS_KVM) {
  112. if (sclp_has_vt220())
  113. add_preferred_console("ttyS", 1, NULL);
  114. else if (sclp_has_linemode())
  115. add_preferred_console("ttyS", 0, NULL);
  116. else
  117. add_preferred_console("hvc", 0, NULL);
  118. } else if (CONSOLE_IS_3215 || CONSOLE_IS_SCLP)
  119. add_preferred_console("ttyS", 0, NULL);
  120. else if (CONSOLE_IS_3270)
  121. add_preferred_console("tty3270", 0, NULL);
  122. }
  123. static int __init conmode_setup(char *str)
  124. {
  125. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  126. if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
  127. SET_CONSOLE_SCLP;
  128. #endif
  129. #if defined(CONFIG_TN3215_CONSOLE)
  130. if (strncmp(str, "3215", 5) == 0)
  131. SET_CONSOLE_3215;
  132. #endif
  133. #if defined(CONFIG_TN3270_CONSOLE)
  134. if (strncmp(str, "3270", 5) == 0)
  135. SET_CONSOLE_3270;
  136. #endif
  137. set_preferred_console();
  138. return 1;
  139. }
  140. __setup("conmode=", conmode_setup);
  141. static void __init conmode_default(void)
  142. {
  143. char query_buffer[1024];
  144. char *ptr;
  145. if (MACHINE_IS_VM) {
  146. cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
  147. console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
  148. ptr = strstr(query_buffer, "SUBCHANNEL =");
  149. console_irq = simple_strtoul(ptr + 13, NULL, 16);
  150. cpcmd("QUERY TERM", query_buffer, 1024, NULL);
  151. ptr = strstr(query_buffer, "CONMODE");
  152. /*
  153. * Set the conmode to 3215 so that the device recognition
  154. * will set the cu_type of the console to 3215. If the
  155. * conmode is 3270 and we don't set it back then both
  156. * 3215 and the 3270 driver will try to access the console
  157. * device (3215 as console and 3270 as normal tty).
  158. */
  159. cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
  160. if (ptr == NULL) {
  161. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  162. SET_CONSOLE_SCLP;
  163. #endif
  164. return;
  165. }
  166. if (strncmp(ptr + 8, "3270", 4) == 0) {
  167. #if defined(CONFIG_TN3270_CONSOLE)
  168. SET_CONSOLE_3270;
  169. #elif defined(CONFIG_TN3215_CONSOLE)
  170. SET_CONSOLE_3215;
  171. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  172. SET_CONSOLE_SCLP;
  173. #endif
  174. } else if (strncmp(ptr + 8, "3215", 4) == 0) {
  175. #if defined(CONFIG_TN3215_CONSOLE)
  176. SET_CONSOLE_3215;
  177. #elif defined(CONFIG_TN3270_CONSOLE)
  178. SET_CONSOLE_3270;
  179. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  180. SET_CONSOLE_SCLP;
  181. #endif
  182. }
  183. } else {
  184. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  185. SET_CONSOLE_SCLP;
  186. #endif
  187. }
  188. }
  189. #ifdef CONFIG_CRASH_DUMP
  190. static void __init setup_zfcpdump(void)
  191. {
  192. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  193. return;
  194. if (OLDMEM_BASE)
  195. return;
  196. strcat(boot_command_line, " cio_ignore=all,!ipldev,!condev");
  197. console_loglevel = 2;
  198. }
  199. #else
  200. static inline void setup_zfcpdump(void) {}
  201. #endif /* CONFIG_CRASH_DUMP */
  202. /*
  203. * Reboot, halt and power_off stubs. They just call _machine_restart,
  204. * _machine_halt or _machine_power_off.
  205. */
  206. void machine_restart(char *command)
  207. {
  208. if ((!in_interrupt() && !in_atomic()) || oops_in_progress)
  209. /*
  210. * Only unblank the console if we are called in enabled
  211. * context or a bust_spinlocks cleared the way for us.
  212. */
  213. console_unblank();
  214. _machine_restart(command);
  215. }
  216. void machine_halt(void)
  217. {
  218. if (!in_interrupt() || oops_in_progress)
  219. /*
  220. * Only unblank the console if we are called in enabled
  221. * context or a bust_spinlocks cleared the way for us.
  222. */
  223. console_unblank();
  224. _machine_halt();
  225. }
  226. void machine_power_off(void)
  227. {
  228. if (!in_interrupt() || oops_in_progress)
  229. /*
  230. * Only unblank the console if we are called in enabled
  231. * context or a bust_spinlocks cleared the way for us.
  232. */
  233. console_unblank();
  234. _machine_power_off();
  235. }
  236. /*
  237. * Dummy power off function.
  238. */
  239. void (*pm_power_off)(void) = machine_power_off;
  240. EXPORT_SYMBOL_GPL(pm_power_off);
  241. static int __init early_parse_mem(char *p)
  242. {
  243. memory_end = memparse(p, &p);
  244. memory_end &= PAGE_MASK;
  245. memory_end_set = 1;
  246. return 0;
  247. }
  248. early_param("mem", early_parse_mem);
  249. static int __init parse_vmalloc(char *arg)
  250. {
  251. if (!arg)
  252. return -EINVAL;
  253. VMALLOC_END = (memparse(arg, &arg) + PAGE_SIZE - 1) & PAGE_MASK;
  254. return 0;
  255. }
  256. early_param("vmalloc", parse_vmalloc);
  257. void *restart_stack __attribute__((__section__(".data")));
  258. static void __init setup_lowcore(void)
  259. {
  260. struct _lowcore *lc;
  261. /*
  262. * Setup lowcore for boot cpu
  263. */
  264. BUILD_BUG_ON(sizeof(struct _lowcore) != LC_PAGES * 4096);
  265. lc = __alloc_bootmem_low(LC_PAGES * PAGE_SIZE, LC_PAGES * PAGE_SIZE, 0);
  266. lc->restart_psw.mask = PSW_KERNEL_BITS;
  267. lc->restart_psw.addr =
  268. PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
  269. lc->external_new_psw.mask = PSW_KERNEL_BITS |
  270. PSW_MASK_DAT | PSW_MASK_MCHECK;
  271. lc->external_new_psw.addr =
  272. PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
  273. lc->svc_new_psw.mask = PSW_KERNEL_BITS |
  274. PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
  275. lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
  276. lc->program_new_psw.mask = PSW_KERNEL_BITS |
  277. PSW_MASK_DAT | PSW_MASK_MCHECK;
  278. lc->program_new_psw.addr =
  279. PSW_ADDR_AMODE | (unsigned long) pgm_check_handler;
  280. lc->mcck_new_psw.mask = PSW_KERNEL_BITS;
  281. lc->mcck_new_psw.addr =
  282. PSW_ADDR_AMODE | (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 = PSW_ADDR_AMODE | (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->machine_flags = S390_lowcore.machine_flags;
  298. lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
  299. memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
  300. MAX_FACILITY_BIT/8);
  301. #ifndef CONFIG_64BIT
  302. if (MACHINE_HAS_IEEE) {
  303. lc->extended_save_area_addr = (__u32)
  304. __alloc_bootmem_low(PAGE_SIZE, PAGE_SIZE, 0);
  305. /* enable extended save area */
  306. __ctl_set_bit(14, 29);
  307. }
  308. #else
  309. if (MACHINE_HAS_VX)
  310. lc->vector_save_area_addr =
  311. (unsigned long) &lc->vector_save_area;
  312. lc->vdso_per_cpu_data = (unsigned long) &lc->paste[0];
  313. #endif
  314. lc->sync_enter_timer = S390_lowcore.sync_enter_timer;
  315. lc->async_enter_timer = S390_lowcore.async_enter_timer;
  316. lc->exit_timer = S390_lowcore.exit_timer;
  317. lc->user_timer = S390_lowcore.user_timer;
  318. lc->system_timer = S390_lowcore.system_timer;
  319. lc->steal_timer = S390_lowcore.steal_timer;
  320. lc->last_update_timer = S390_lowcore.last_update_timer;
  321. lc->last_update_clock = S390_lowcore.last_update_clock;
  322. restart_stack = __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0);
  323. restart_stack += ASYNC_SIZE;
  324. /*
  325. * Set up PSW restart to call ipl.c:do_restart(). Copy the relevant
  326. * restart data to the absolute zero lowcore. This is necessary if
  327. * PSW restart is done on an offline CPU that has lowcore zero.
  328. */
  329. lc->restart_stack = (unsigned long) restart_stack;
  330. lc->restart_fn = (unsigned long) do_restart;
  331. lc->restart_data = 0;
  332. lc->restart_source = -1UL;
  333. /* Setup absolute zero lowcore */
  334. mem_assign_absolute(S390_lowcore.restart_stack, lc->restart_stack);
  335. mem_assign_absolute(S390_lowcore.restart_fn, lc->restart_fn);
  336. mem_assign_absolute(S390_lowcore.restart_data, lc->restart_data);
  337. mem_assign_absolute(S390_lowcore.restart_source, lc->restart_source);
  338. mem_assign_absolute(S390_lowcore.restart_psw, lc->restart_psw);
  339. #ifdef CONFIG_SMP
  340. lc->spinlock_lockval = arch_spin_lockval(0);
  341. #endif
  342. set_prefix((u32)(unsigned long) lc);
  343. lowcore_ptr[0] = lc;
  344. }
  345. static struct resource code_resource = {
  346. .name = "Kernel code",
  347. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  348. };
  349. static struct resource data_resource = {
  350. .name = "Kernel data",
  351. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  352. };
  353. static struct resource bss_resource = {
  354. .name = "Kernel bss",
  355. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  356. };
  357. static struct resource __initdata *standard_resources[] = {
  358. &code_resource,
  359. &data_resource,
  360. &bss_resource,
  361. };
  362. static void __init setup_resources(void)
  363. {
  364. struct resource *res, *std_res, *sub_res;
  365. struct memblock_region *reg;
  366. int j;
  367. code_resource.start = (unsigned long) &_text;
  368. code_resource.end = (unsigned long) &_etext - 1;
  369. data_resource.start = (unsigned long) &_etext;
  370. data_resource.end = (unsigned long) &_edata - 1;
  371. bss_resource.start = (unsigned long) &__bss_start;
  372. bss_resource.end = (unsigned long) &__bss_stop - 1;
  373. for_each_memblock(memory, reg) {
  374. res = alloc_bootmem_low(sizeof(*res));
  375. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  376. res->name = "System RAM";
  377. res->start = reg->base;
  378. res->end = reg->base + reg->size - 1;
  379. request_resource(&iomem_resource, res);
  380. for (j = 0; j < ARRAY_SIZE(standard_resources); j++) {
  381. std_res = standard_resources[j];
  382. if (std_res->start < res->start ||
  383. std_res->start > res->end)
  384. continue;
  385. if (std_res->end > res->end) {
  386. sub_res = alloc_bootmem_low(sizeof(*sub_res));
  387. *sub_res = *std_res;
  388. sub_res->end = res->end;
  389. std_res->start = res->end + 1;
  390. request_resource(res, sub_res);
  391. } else {
  392. request_resource(res, std_res);
  393. }
  394. }
  395. }
  396. }
  397. static void __init setup_memory_end(void)
  398. {
  399. unsigned long vmax, vmalloc_size, tmp;
  400. /* Choose kernel address space layout: 2, 3, or 4 levels. */
  401. #ifdef CONFIG_64BIT
  402. vmalloc_size = VMALLOC_END ?: (128UL << 30) - MODULES_LEN;
  403. tmp = (memory_end ?: max_physmem_end) / PAGE_SIZE;
  404. tmp = tmp * (sizeof(struct page) + PAGE_SIZE);
  405. if (tmp + vmalloc_size + MODULES_LEN <= (1UL << 42))
  406. vmax = 1UL << 42; /* 3-level kernel page table */
  407. else
  408. vmax = 1UL << 53; /* 4-level kernel page table */
  409. /* module area is at the end of the kernel address space. */
  410. MODULES_END = vmax;
  411. MODULES_VADDR = MODULES_END - MODULES_LEN;
  412. VMALLOC_END = MODULES_VADDR;
  413. #else
  414. vmalloc_size = VMALLOC_END ?: 96UL << 20;
  415. vmax = 1UL << 31; /* 2-level kernel page table */
  416. /* vmalloc area is at the end of the kernel address space. */
  417. VMALLOC_END = vmax;
  418. #endif
  419. VMALLOC_START = vmax - vmalloc_size;
  420. /* Split remaining virtual space between 1:1 mapping & vmemmap array */
  421. tmp = VMALLOC_START / (PAGE_SIZE + sizeof(struct page));
  422. /* vmemmap contains a multiple of PAGES_PER_SECTION struct pages */
  423. tmp = SECTION_ALIGN_UP(tmp);
  424. tmp = VMALLOC_START - tmp * sizeof(struct page);
  425. tmp &= ~((vmax >> 11) - 1); /* align to page table level */
  426. tmp = min(tmp, 1UL << MAX_PHYSMEM_BITS);
  427. vmemmap = (struct page *) tmp;
  428. /* Take care that memory_end is set and <= vmemmap */
  429. memory_end = min(memory_end ?: max_physmem_end, tmp);
  430. max_pfn = max_low_pfn = PFN_DOWN(memory_end);
  431. memblock_remove(memory_end, ULONG_MAX);
  432. pr_notice("Max memory size: %luMB\n", memory_end >> 20);
  433. }
  434. static void __init setup_vmcoreinfo(void)
  435. {
  436. mem_assign_absolute(S390_lowcore.vmcore_info, paddr_vmcoreinfo_note());
  437. }
  438. #ifdef CONFIG_CRASH_DUMP
  439. /*
  440. * When kdump is enabled, we have to ensure that no memory from
  441. * the area [0 - crashkernel memory size] and
  442. * [crashk_res.start - crashk_res.end] is set offline.
  443. */
  444. static int kdump_mem_notifier(struct notifier_block *nb,
  445. unsigned long action, void *data)
  446. {
  447. struct memory_notify *arg = data;
  448. if (action != MEM_GOING_OFFLINE)
  449. return NOTIFY_OK;
  450. if (arg->start_pfn < PFN_DOWN(resource_size(&crashk_res)))
  451. return NOTIFY_BAD;
  452. if (arg->start_pfn > PFN_DOWN(crashk_res.end))
  453. return NOTIFY_OK;
  454. if (arg->start_pfn + arg->nr_pages - 1 < PFN_DOWN(crashk_res.start))
  455. return NOTIFY_OK;
  456. return NOTIFY_BAD;
  457. }
  458. static struct notifier_block kdump_mem_nb = {
  459. .notifier_call = kdump_mem_notifier,
  460. };
  461. #endif
  462. /*
  463. * Make sure that the area behind memory_end is protected
  464. */
  465. static void reserve_memory_end(void)
  466. {
  467. #ifdef CONFIG_CRASH_DUMP
  468. if (ipl_info.type == IPL_TYPE_FCP_DUMP &&
  469. !OLDMEM_BASE && sclp_get_hsa_size()) {
  470. memory_end = sclp_get_hsa_size();
  471. memory_end &= PAGE_MASK;
  472. memory_end_set = 1;
  473. }
  474. #endif
  475. if (!memory_end_set)
  476. return;
  477. memblock_reserve(memory_end, ULONG_MAX);
  478. }
  479. /*
  480. * Make sure that oldmem, where the dump is stored, is protected
  481. */
  482. static void reserve_oldmem(void)
  483. {
  484. #ifdef CONFIG_CRASH_DUMP
  485. if (OLDMEM_BASE)
  486. /* Forget all memory above the running kdump system */
  487. memblock_reserve(OLDMEM_SIZE, (phys_addr_t)ULONG_MAX);
  488. #endif
  489. }
  490. /*
  491. * Make sure that oldmem, where the dump is stored, is protected
  492. */
  493. static void remove_oldmem(void)
  494. {
  495. #ifdef CONFIG_CRASH_DUMP
  496. if (OLDMEM_BASE)
  497. /* Forget all memory above the running kdump system */
  498. memblock_remove(OLDMEM_SIZE, (phys_addr_t)ULONG_MAX);
  499. #endif
  500. }
  501. /*
  502. * Reserve memory for kdump kernel to be loaded with kexec
  503. */
  504. static void __init reserve_crashkernel(void)
  505. {
  506. #ifdef CONFIG_CRASH_DUMP
  507. unsigned long long crash_base, crash_size;
  508. phys_addr_t low, high;
  509. int rc;
  510. rc = parse_crashkernel(boot_command_line, memory_end, &crash_size,
  511. &crash_base);
  512. crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
  513. crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);
  514. if (rc || crash_size == 0)
  515. return;
  516. if (memblock.memory.regions[0].size < crash_size) {
  517. pr_info("crashkernel reservation failed: %s\n",
  518. "first memory chunk must be at least crashkernel size");
  519. return;
  520. }
  521. low = crash_base ?: OLDMEM_BASE;
  522. high = low + crash_size;
  523. if (low >= OLDMEM_BASE && high <= OLDMEM_BASE + OLDMEM_SIZE) {
  524. /* The crashkernel fits into OLDMEM, reuse OLDMEM */
  525. crash_base = low;
  526. } else {
  527. /* Find suitable area in free memory */
  528. low = max_t(unsigned long, crash_size, sclp_get_hsa_size());
  529. high = crash_base ? crash_base + crash_size : ULONG_MAX;
  530. if (crash_base && crash_base < low) {
  531. pr_info("crashkernel reservation failed: %s\n",
  532. "crash_base too low");
  533. return;
  534. }
  535. low = crash_base ?: low;
  536. crash_base = memblock_find_in_range(low, high, crash_size,
  537. KEXEC_CRASH_MEM_ALIGN);
  538. }
  539. if (!crash_base) {
  540. pr_info("crashkernel reservation failed: %s\n",
  541. "no suitable area found");
  542. return;
  543. }
  544. if (register_memory_notifier(&kdump_mem_nb))
  545. return;
  546. if (!OLDMEM_BASE && MACHINE_IS_VM)
  547. diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size));
  548. crashk_res.start = crash_base;
  549. crashk_res.end = crash_base + crash_size - 1;
  550. insert_resource(&iomem_resource, &crashk_res);
  551. memblock_remove(crash_base, crash_size);
  552. pr_info("Reserving %lluMB of memory at %lluMB "
  553. "for crashkernel (System RAM: %luMB)\n",
  554. crash_size >> 20, crash_base >> 20,
  555. (unsigned long)memblock.memory.total_size >> 20);
  556. os_info_crashkernel_add(crash_base, crash_size);
  557. #endif
  558. }
  559. /*
  560. * Reserve the initrd from being used by memblock
  561. */
  562. static void __init reserve_initrd(void)
  563. {
  564. #ifdef CONFIG_BLK_DEV_INITRD
  565. initrd_start = INITRD_START;
  566. initrd_end = initrd_start + INITRD_SIZE;
  567. memblock_reserve(INITRD_START, INITRD_SIZE);
  568. #endif
  569. }
  570. /*
  571. * Check for initrd being in usable memory
  572. */
  573. static void __init check_initrd(void)
  574. {
  575. #ifdef CONFIG_BLK_DEV_INITRD
  576. if (INITRD_START && INITRD_SIZE &&
  577. !memblock_is_region_memory(INITRD_START, INITRD_SIZE)) {
  578. pr_err("initrd does not fit memory.\n");
  579. memblock_free(INITRD_START, INITRD_SIZE);
  580. initrd_start = initrd_end = 0;
  581. }
  582. #endif
  583. }
  584. /*
  585. * Reserve all kernel text
  586. */
  587. static void __init reserve_kernel(void)
  588. {
  589. unsigned long start_pfn;
  590. start_pfn = PFN_UP(__pa(&_end));
  591. /*
  592. * Reserve memory used for lowcore/command line/kernel image.
  593. */
  594. memblock_reserve(0, (unsigned long)_ehead);
  595. memblock_reserve((unsigned long)_stext, PFN_PHYS(start_pfn)
  596. - (unsigned long)_stext);
  597. }
  598. static void __init reserve_elfcorehdr(void)
  599. {
  600. #ifdef CONFIG_CRASH_DUMP
  601. if (is_kdump_kernel())
  602. memblock_reserve(elfcorehdr_addr - OLDMEM_BASE,
  603. PAGE_ALIGN(elfcorehdr_size));
  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 void __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. #if defined(CONFIG_64BIT)
  671. /*
  672. * 64-bit register support for 31-bit processes
  673. * HWCAP_S390_HIGH_GPRS is bit 9.
  674. */
  675. elf_hwcap |= HWCAP_S390_HIGH_GPRS;
  676. /*
  677. * Transactional execution support HWCAP_S390_TE is bit 10.
  678. */
  679. if (test_facility(50) && test_facility(73))
  680. elf_hwcap |= HWCAP_S390_TE;
  681. /*
  682. * Vector extension HWCAP_S390_VXRS is bit 11.
  683. */
  684. if (test_facility(129))
  685. elf_hwcap |= HWCAP_S390_VXRS;
  686. #endif
  687. get_cpu_id(&cpu_id);
  688. add_device_randomness(&cpu_id, sizeof(cpu_id));
  689. switch (cpu_id.machine) {
  690. case 0x9672:
  691. #if !defined(CONFIG_64BIT)
  692. default: /* Use "g5" as default for 31 bit kernels. */
  693. #endif
  694. strcpy(elf_platform, "g5");
  695. break;
  696. case 0x2064:
  697. case 0x2066:
  698. #if defined(CONFIG_64BIT)
  699. default: /* Use "z900" as default for 64 bit kernels. */
  700. #endif
  701. strcpy(elf_platform, "z900");
  702. break;
  703. case 0x2084:
  704. case 0x2086:
  705. strcpy(elf_platform, "z990");
  706. break;
  707. case 0x2094:
  708. case 0x2096:
  709. strcpy(elf_platform, "z9-109");
  710. break;
  711. case 0x2097:
  712. case 0x2098:
  713. strcpy(elf_platform, "z10");
  714. break;
  715. case 0x2817:
  716. case 0x2818:
  717. strcpy(elf_platform, "z196");
  718. break;
  719. case 0x2827:
  720. case 0x2828:
  721. strcpy(elf_platform, "zEC12");
  722. break;
  723. }
  724. }
  725. /*
  726. * Add system information as device randomness
  727. */
  728. static void __init setup_randomness(void)
  729. {
  730. struct sysinfo_3_2_2 *vmms;
  731. vmms = (struct sysinfo_3_2_2 *) alloc_page(GFP_KERNEL);
  732. if (vmms && stsi(vmms, 3, 2, 2) == 0 && vmms->count)
  733. add_device_randomness(&vmms, vmms->count);
  734. free_page((unsigned long) vmms);
  735. }
  736. /*
  737. * Setup function called from init/main.c just after the banner
  738. * was printed.
  739. */
  740. void __init setup_arch(char **cmdline_p)
  741. {
  742. /*
  743. * print what head.S has found out about the machine
  744. */
  745. #ifndef CONFIG_64BIT
  746. if (MACHINE_IS_VM)
  747. pr_info("Linux is running as a z/VM "
  748. "guest operating system in 31-bit mode\n");
  749. else if (MACHINE_IS_LPAR)
  750. pr_info("Linux is running natively in 31-bit mode\n");
  751. if (MACHINE_HAS_IEEE)
  752. pr_info("The hardware system has IEEE compatible "
  753. "floating point units\n");
  754. else
  755. pr_info("The hardware system has no IEEE compatible "
  756. "floating point units\n");
  757. #else /* CONFIG_64BIT */
  758. if (MACHINE_IS_VM)
  759. pr_info("Linux is running as a z/VM "
  760. "guest operating system in 64-bit mode\n");
  761. else if (MACHINE_IS_KVM)
  762. pr_info("Linux is running under KVM in 64-bit mode\n");
  763. else if (MACHINE_IS_LPAR)
  764. pr_info("Linux is running natively in 64-bit mode\n");
  765. #endif /* CONFIG_64BIT */
  766. /* Have one command line that is parsed and saved in /proc/cmdline */
  767. /* boot_command_line has been already set up in early.c */
  768. *cmdline_p = boot_command_line;
  769. ROOT_DEV = Root_RAM0;
  770. /* Is init_mm really needed? */
  771. init_mm.start_code = PAGE_OFFSET;
  772. init_mm.end_code = (unsigned long) &_etext;
  773. init_mm.end_data = (unsigned long) &_edata;
  774. init_mm.brk = (unsigned long) &_end;
  775. parse_early_param();
  776. os_info_init();
  777. setup_ipl();
  778. /* Do some memory reservations *before* memory is added to memblock */
  779. reserve_memory_end();
  780. reserve_oldmem();
  781. reserve_kernel();
  782. reserve_initrd();
  783. reserve_elfcorehdr();
  784. memblock_allow_resize();
  785. /* Get information about *all* installed memory */
  786. detect_memory_memblock();
  787. remove_oldmem();
  788. /*
  789. * Make sure all chunks are MAX_ORDER aligned so we don't need the
  790. * extra checks that HOLES_IN_ZONE would require.
  791. *
  792. * Is this still required?
  793. */
  794. memblock_trim_memory(1UL << (MAX_ORDER - 1 + PAGE_SHIFT));
  795. setup_memory_end();
  796. setup_memory();
  797. check_initrd();
  798. reserve_crashkernel();
  799. setup_resources();
  800. setup_vmcoreinfo();
  801. setup_lowcore();
  802. smp_fill_possible_mask();
  803. cpu_init();
  804. s390_init_cpu_topology();
  805. /*
  806. * Setup capabilities (ELF_HWCAP & ELF_PLATFORM).
  807. */
  808. setup_hwcaps();
  809. /*
  810. * Create kernel page tables and switch to virtual addressing.
  811. */
  812. paging_init();
  813. /* Setup default console */
  814. conmode_default();
  815. set_preferred_console();
  816. /* Setup zfcpdump support */
  817. setup_zfcpdump();
  818. /* Add system specific data to the random pool */
  819. setup_randomness();
  820. }
  821. #ifdef CONFIG_32BIT
  822. static int no_removal_warning __initdata;
  823. static int __init parse_no_removal_warning(char *str)
  824. {
  825. no_removal_warning = 1;
  826. return 0;
  827. }
  828. __setup("no_removal_warning", parse_no_removal_warning);
  829. static int __init removal_warning(void)
  830. {
  831. if (no_removal_warning)
  832. return 0;
  833. printk(KERN_ALERT "\n\n");
  834. printk(KERN_CONT "Warning - you are using a 31 bit kernel!\n\n");
  835. printk(KERN_CONT "We plan to remove 31 bit kernel support from the kernel sources in March 2015.\n");
  836. printk(KERN_CONT "Currently we assume that nobody is using the 31 bit kernel on old 31 bit\n");
  837. printk(KERN_CONT "hardware anymore. If you think that the code should not be removed and also\n");
  838. printk(KERN_CONT "future versions of the Linux kernel should be able to run in 31 bit mode\n");
  839. printk(KERN_CONT "please let us know. Please write to:\n");
  840. printk(KERN_CONT "linux390@de.ibm.com (mail address) and/or\n");
  841. printk(KERN_CONT "linux-s390@vger.kernel.org (mailing list).\n\n");
  842. printk(KERN_CONT "Thank you!\n\n");
  843. printk(KERN_CONT "If this kernel runs on a 64 bit machine you may consider using a 64 bit kernel.\n");
  844. printk(KERN_CONT "This message can be disabled with the \"no_removal_warning\" kernel parameter.\n");
  845. schedule_timeout_uninterruptible(300 * HZ);
  846. return 0;
  847. }
  848. early_initcall(removal_warning);
  849. #endif