setup.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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/user.h>
  25. #include <linux/tty.h>
  26. #include <linux/ioport.h>
  27. #include <linux/delay.h>
  28. #include <linux/init.h>
  29. #include <linux/initrd.h>
  30. #include <linux/bootmem.h>
  31. #include <linux/root_dev.h>
  32. #include <linux/console.h>
  33. #include <linux/kernel_stat.h>
  34. #include <linux/device.h>
  35. #include <linux/notifier.h>
  36. #include <linux/pfn.h>
  37. #include <linux/ctype.h>
  38. #include <linux/reboot.h>
  39. #include <linux/topology.h>
  40. #include <linux/ftrace.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 "entry.h"
  61. /*
  62. * Machine setup..
  63. */
  64. unsigned int console_mode = 0;
  65. EXPORT_SYMBOL(console_mode);
  66. unsigned int console_devno = -1;
  67. EXPORT_SYMBOL(console_devno);
  68. unsigned int console_irq = -1;
  69. EXPORT_SYMBOL(console_irq);
  70. unsigned long elf_hwcap = 0;
  71. char elf_platform[ELF_PLATFORM_SIZE];
  72. struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
  73. int __initdata memory_end_set;
  74. unsigned long __initdata memory_end;
  75. unsigned long VMALLOC_START;
  76. EXPORT_SYMBOL(VMALLOC_START);
  77. unsigned long VMALLOC_END;
  78. EXPORT_SYMBOL(VMALLOC_END);
  79. struct page *vmemmap;
  80. EXPORT_SYMBOL(vmemmap);
  81. #ifdef CONFIG_64BIT
  82. unsigned long MODULES_VADDR;
  83. unsigned long MODULES_END;
  84. #endif
  85. /* An array with a pointer to the lowcore of every CPU. */
  86. struct _lowcore *lowcore_ptr[NR_CPUS];
  87. EXPORT_SYMBOL(lowcore_ptr);
  88. /*
  89. * This is set up by the setup-routine at boot-time
  90. * for S390 need to find out, what we have to setup
  91. * using address 0x10400 ...
  92. */
  93. #include <asm/setup.h>
  94. /*
  95. * condev= and conmode= setup parameter.
  96. */
  97. static int __init condev_setup(char *str)
  98. {
  99. int vdev;
  100. vdev = simple_strtoul(str, &str, 0);
  101. if (vdev >= 0 && vdev < 65536) {
  102. console_devno = vdev;
  103. console_irq = -1;
  104. }
  105. return 1;
  106. }
  107. __setup("condev=", condev_setup);
  108. static void __init set_preferred_console(void)
  109. {
  110. if (MACHINE_IS_KVM) {
  111. if (sclp_has_vt220())
  112. add_preferred_console("ttyS", 1, NULL);
  113. else if (sclp_has_linemode())
  114. add_preferred_console("ttyS", 0, NULL);
  115. else
  116. add_preferred_console("hvc", 0, NULL);
  117. } else if (CONSOLE_IS_3215 || CONSOLE_IS_SCLP)
  118. add_preferred_console("ttyS", 0, NULL);
  119. else if (CONSOLE_IS_3270)
  120. add_preferred_console("tty3270", 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 {
  183. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  184. SET_CONSOLE_SCLP;
  185. #endif
  186. }
  187. }
  188. #ifdef CONFIG_ZFCPDUMP
  189. static void __init setup_zfcpdump(void)
  190. {
  191. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  192. return;
  193. if (OLDMEM_BASE)
  194. return;
  195. strcat(boot_command_line, " cio_ignore=all,!ipldev,!condev");
  196. console_loglevel = 2;
  197. }
  198. #else
  199. static inline void setup_zfcpdump(void) {}
  200. #endif /* CONFIG_ZFCPDUMP */
  201. /*
  202. * Reboot, halt and power_off stubs. They just call _machine_restart,
  203. * _machine_halt or _machine_power_off.
  204. */
  205. void machine_restart(char *command)
  206. {
  207. if ((!in_interrupt() && !in_atomic()) || oops_in_progress)
  208. /*
  209. * Only unblank the console if we are called in enabled
  210. * context or a bust_spinlocks cleared the way for us.
  211. */
  212. console_unblank();
  213. _machine_restart(command);
  214. }
  215. void machine_halt(void)
  216. {
  217. if (!in_interrupt() || oops_in_progress)
  218. /*
  219. * Only unblank the console if we are called in enabled
  220. * context or a bust_spinlocks cleared the way for us.
  221. */
  222. console_unblank();
  223. _machine_halt();
  224. }
  225. void machine_power_off(void)
  226. {
  227. if (!in_interrupt() || oops_in_progress)
  228. /*
  229. * Only unblank the console if we are called in enabled
  230. * context or a bust_spinlocks cleared the way for us.
  231. */
  232. console_unblank();
  233. _machine_power_off();
  234. }
  235. /*
  236. * Dummy power off function.
  237. */
  238. void (*pm_power_off)(void) = machine_power_off;
  239. EXPORT_SYMBOL_GPL(pm_power_off);
  240. static int __init early_parse_mem(char *p)
  241. {
  242. memory_end = memparse(p, &p);
  243. memory_end_set = 1;
  244. return 0;
  245. }
  246. early_param("mem", early_parse_mem);
  247. static int __init parse_vmalloc(char *arg)
  248. {
  249. if (!arg)
  250. return -EINVAL;
  251. VMALLOC_END = (memparse(arg, &arg) + PAGE_SIZE - 1) & PAGE_MASK;
  252. return 0;
  253. }
  254. early_param("vmalloc", parse_vmalloc);
  255. void *restart_stack __attribute__((__section__(".data")));
  256. static void __init setup_lowcore(void)
  257. {
  258. struct _lowcore *lc;
  259. /*
  260. * Setup lowcore for boot cpu
  261. */
  262. BUILD_BUG_ON(sizeof(struct _lowcore) != LC_PAGES * 4096);
  263. lc = __alloc_bootmem_low(LC_PAGES * PAGE_SIZE, LC_PAGES * PAGE_SIZE, 0);
  264. lc->restart_psw.mask = PSW_KERNEL_BITS;
  265. lc->restart_psw.addr =
  266. PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
  267. lc->external_new_psw.mask = PSW_KERNEL_BITS |
  268. PSW_MASK_DAT | PSW_MASK_MCHECK;
  269. lc->external_new_psw.addr =
  270. PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
  271. lc->svc_new_psw.mask = PSW_KERNEL_BITS |
  272. PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
  273. lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
  274. lc->program_new_psw.mask = PSW_KERNEL_BITS |
  275. PSW_MASK_DAT | PSW_MASK_MCHECK;
  276. lc->program_new_psw.addr =
  277. PSW_ADDR_AMODE | (unsigned long) pgm_check_handler;
  278. lc->mcck_new_psw.mask = PSW_KERNEL_BITS;
  279. lc->mcck_new_psw.addr =
  280. PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
  281. lc->io_new_psw.mask = PSW_KERNEL_BITS |
  282. PSW_MASK_DAT | PSW_MASK_MCHECK;
  283. lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
  284. lc->clock_comparator = -1ULL;
  285. lc->kernel_stack = ((unsigned long) &init_thread_union)
  286. + THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  287. lc->async_stack = (unsigned long)
  288. __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0)
  289. + ASYNC_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  290. lc->panic_stack = (unsigned long)
  291. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0)
  292. + PAGE_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  293. lc->current_task = (unsigned long) init_thread_union.thread_info.task;
  294. lc->thread_info = (unsigned long) &init_thread_union;
  295. lc->machine_flags = S390_lowcore.machine_flags;
  296. lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
  297. memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
  298. MAX_FACILITY_BIT/8);
  299. #ifndef CONFIG_64BIT
  300. if (MACHINE_HAS_IEEE) {
  301. lc->extended_save_area_addr = (__u32)
  302. __alloc_bootmem_low(PAGE_SIZE, PAGE_SIZE, 0);
  303. /* enable extended save area */
  304. __ctl_set_bit(14, 29);
  305. }
  306. #else
  307. lc->vdso_per_cpu_data = (unsigned long) &lc->paste[0];
  308. #endif
  309. lc->sync_enter_timer = S390_lowcore.sync_enter_timer;
  310. lc->async_enter_timer = S390_lowcore.async_enter_timer;
  311. lc->exit_timer = S390_lowcore.exit_timer;
  312. lc->user_timer = S390_lowcore.user_timer;
  313. lc->system_timer = S390_lowcore.system_timer;
  314. lc->steal_timer = S390_lowcore.steal_timer;
  315. lc->last_update_timer = S390_lowcore.last_update_timer;
  316. lc->last_update_clock = S390_lowcore.last_update_clock;
  317. lc->ftrace_func = S390_lowcore.ftrace_func;
  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. set_prefix((u32)(unsigned long) lc);
  336. lowcore_ptr[0] = lc;
  337. }
  338. static struct resource code_resource = {
  339. .name = "Kernel code",
  340. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  341. };
  342. static struct resource data_resource = {
  343. .name = "Kernel data",
  344. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  345. };
  346. static struct resource bss_resource = {
  347. .name = "Kernel bss",
  348. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  349. };
  350. static struct resource __initdata *standard_resources[] = {
  351. &code_resource,
  352. &data_resource,
  353. &bss_resource,
  354. };
  355. static void __init setup_resources(void)
  356. {
  357. struct resource *res, *std_res, *sub_res;
  358. int i, 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 (i = 0; i < MEMORY_CHUNKS; i++) {
  366. if (!memory_chunk[i].size)
  367. continue;
  368. res = alloc_bootmem_low(sizeof(*res));
  369. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  370. switch (memory_chunk[i].type) {
  371. case CHUNK_READ_WRITE:
  372. res->name = "System RAM";
  373. break;
  374. case CHUNK_READ_ONLY:
  375. res->name = "System ROM";
  376. res->flags |= IORESOURCE_READONLY;
  377. break;
  378. default:
  379. res->name = "reserved";
  380. }
  381. res->start = memory_chunk[i].addr;
  382. res->end = res->start + memory_chunk[i].size - 1;
  383. request_resource(&iomem_resource, res);
  384. for (j = 0; j < ARRAY_SIZE(standard_resources); j++) {
  385. std_res = standard_resources[j];
  386. if (std_res->start < res->start ||
  387. std_res->start > res->end)
  388. continue;
  389. if (std_res->end > res->end) {
  390. sub_res = alloc_bootmem_low(sizeof(*sub_res));
  391. *sub_res = *std_res;
  392. sub_res->end = res->end;
  393. std_res->start = res->end + 1;
  394. request_resource(res, sub_res);
  395. } else {
  396. request_resource(res, std_res);
  397. }
  398. }
  399. }
  400. }
  401. static void __init setup_memory_end(void)
  402. {
  403. unsigned long vmax, vmalloc_size, tmp;
  404. unsigned long real_memory_size = 0;
  405. int i;
  406. #ifdef CONFIG_ZFCPDUMP
  407. if (ipl_info.type == IPL_TYPE_FCP_DUMP &&
  408. !OLDMEM_BASE && sclp_get_hsa_size()) {
  409. memory_end = sclp_get_hsa_size();
  410. memory_end_set = 1;
  411. }
  412. #endif
  413. memory_end &= PAGE_MASK;
  414. /*
  415. * Make sure all chunks are MAX_ORDER aligned so we don't need the
  416. * extra checks that HOLES_IN_ZONE would require.
  417. */
  418. for (i = 0; i < MEMORY_CHUNKS; i++) {
  419. unsigned long start, end;
  420. struct mem_chunk *chunk;
  421. unsigned long align;
  422. chunk = &memory_chunk[i];
  423. if (!chunk->size)
  424. continue;
  425. align = 1UL << (MAX_ORDER + PAGE_SHIFT - 1);
  426. start = (chunk->addr + align - 1) & ~(align - 1);
  427. end = (chunk->addr + chunk->size) & ~(align - 1);
  428. if (start >= end)
  429. memset(chunk, 0, sizeof(*chunk));
  430. else {
  431. chunk->addr = start;
  432. chunk->size = end - start;
  433. }
  434. real_memory_size = max(real_memory_size,
  435. chunk->addr + chunk->size);
  436. }
  437. /* Choose kernel address space layout: 2, 3, or 4 levels. */
  438. #ifdef CONFIG_64BIT
  439. vmalloc_size = VMALLOC_END ?: (128UL << 30) - MODULES_LEN;
  440. tmp = (memory_end ?: real_memory_size) / PAGE_SIZE;
  441. tmp = tmp * (sizeof(struct page) + PAGE_SIZE) + vmalloc_size;
  442. if (tmp <= (1UL << 42))
  443. vmax = 1UL << 42; /* 3-level kernel page table */
  444. else
  445. vmax = 1UL << 53; /* 4-level kernel page table */
  446. /* module area is at the end of the kernel address space. */
  447. MODULES_END = vmax;
  448. MODULES_VADDR = MODULES_END - MODULES_LEN;
  449. VMALLOC_END = MODULES_VADDR;
  450. #else
  451. vmalloc_size = VMALLOC_END ?: 96UL << 20;
  452. vmax = 1UL << 31; /* 2-level kernel page table */
  453. /* vmalloc area is at the end of the kernel address space. */
  454. VMALLOC_END = vmax;
  455. #endif
  456. VMALLOC_START = vmax - vmalloc_size;
  457. /* Split remaining virtual space between 1:1 mapping & vmemmap array */
  458. tmp = VMALLOC_START / (PAGE_SIZE + sizeof(struct page));
  459. /* vmemmap contains a multiple of PAGES_PER_SECTION struct pages */
  460. tmp = SECTION_ALIGN_UP(tmp);
  461. tmp = VMALLOC_START - tmp * sizeof(struct page);
  462. tmp &= ~((vmax >> 11) - 1); /* align to page table level */
  463. tmp = min(tmp, 1UL << MAX_PHYSMEM_BITS);
  464. vmemmap = (struct page *) tmp;
  465. /* Take care that memory_end is set and <= vmemmap */
  466. memory_end = min(memory_end ?: real_memory_size, tmp);
  467. /* Fixup memory chunk array to fit into 0..memory_end */
  468. for (i = 0; i < MEMORY_CHUNKS; i++) {
  469. struct mem_chunk *chunk = &memory_chunk[i];
  470. if (!chunk->size)
  471. continue;
  472. if (chunk->addr >= memory_end) {
  473. memset(chunk, 0, sizeof(*chunk));
  474. continue;
  475. }
  476. if (chunk->addr + chunk->size > memory_end)
  477. chunk->size = memory_end - chunk->addr;
  478. }
  479. }
  480. static void __init setup_vmcoreinfo(void)
  481. {
  482. mem_assign_absolute(S390_lowcore.vmcore_info, paddr_vmcoreinfo_note());
  483. }
  484. #ifdef CONFIG_CRASH_DUMP
  485. /*
  486. * Find suitable location for crashkernel memory
  487. */
  488. static unsigned long __init find_crash_base(unsigned long crash_size,
  489. char **msg)
  490. {
  491. unsigned long crash_base;
  492. struct mem_chunk *chunk;
  493. int i;
  494. if (memory_chunk[0].size < crash_size) {
  495. *msg = "first memory chunk must be at least crashkernel size";
  496. return 0;
  497. }
  498. if (OLDMEM_BASE && crash_size == OLDMEM_SIZE)
  499. return OLDMEM_BASE;
  500. for (i = MEMORY_CHUNKS - 1; i >= 0; i--) {
  501. chunk = &memory_chunk[i];
  502. if (chunk->size == 0)
  503. continue;
  504. if (chunk->type != CHUNK_READ_WRITE)
  505. continue;
  506. if (chunk->size < crash_size)
  507. continue;
  508. crash_base = (chunk->addr + chunk->size) - crash_size;
  509. if (crash_base < crash_size)
  510. continue;
  511. if (crash_base < sclp_get_hsa_size())
  512. continue;
  513. if (crash_base < (unsigned long) INITRD_START + INITRD_SIZE)
  514. continue;
  515. return crash_base;
  516. }
  517. *msg = "no suitable area found";
  518. return 0;
  519. }
  520. /*
  521. * Check if crash_base and crash_size is valid
  522. */
  523. static int __init verify_crash_base(unsigned long crash_base,
  524. unsigned long crash_size,
  525. char **msg)
  526. {
  527. struct mem_chunk *chunk;
  528. int i;
  529. /*
  530. * Because we do the swap to zero, we must have at least 'crash_size'
  531. * bytes free space before crash_base
  532. */
  533. if (crash_size > crash_base) {
  534. *msg = "crashkernel offset must be greater than size";
  535. return -EINVAL;
  536. }
  537. /* First memory chunk must be at least crash_size */
  538. if (memory_chunk[0].size < crash_size) {
  539. *msg = "first memory chunk must be at least crashkernel size";
  540. return -EINVAL;
  541. }
  542. /* Check if we fit into the respective memory chunk */
  543. for (i = 0; i < MEMORY_CHUNKS; i++) {
  544. chunk = &memory_chunk[i];
  545. if (chunk->size == 0)
  546. continue;
  547. if (crash_base < chunk->addr)
  548. continue;
  549. if (crash_base >= chunk->addr + chunk->size)
  550. continue;
  551. /* we have found the memory chunk */
  552. if (crash_base + crash_size > chunk->addr + chunk->size) {
  553. *msg = "selected memory chunk is too small for "
  554. "crashkernel memory";
  555. return -EINVAL;
  556. }
  557. return 0;
  558. }
  559. *msg = "invalid memory range specified";
  560. return -EINVAL;
  561. }
  562. /*
  563. * When kdump is enabled, we have to ensure that no memory from
  564. * the area [0 - crashkernel memory size] and
  565. * [crashk_res.start - crashk_res.end] is set offline.
  566. */
  567. static int kdump_mem_notifier(struct notifier_block *nb,
  568. unsigned long action, void *data)
  569. {
  570. struct memory_notify *arg = data;
  571. if (arg->start_pfn < PFN_DOWN(resource_size(&crashk_res)))
  572. return NOTIFY_BAD;
  573. if (arg->start_pfn > PFN_DOWN(crashk_res.end))
  574. return NOTIFY_OK;
  575. if (arg->start_pfn + arg->nr_pages - 1 < PFN_DOWN(crashk_res.start))
  576. return NOTIFY_OK;
  577. return NOTIFY_BAD;
  578. }
  579. static struct notifier_block kdump_mem_nb = {
  580. .notifier_call = kdump_mem_notifier,
  581. };
  582. #endif
  583. /*
  584. * Make sure that oldmem, where the dump is stored, is protected
  585. */
  586. static void reserve_oldmem(void)
  587. {
  588. #ifdef CONFIG_CRASH_DUMP
  589. unsigned long real_size = 0;
  590. int i;
  591. if (!OLDMEM_BASE)
  592. return;
  593. for (i = 0; i < MEMORY_CHUNKS; i++) {
  594. struct mem_chunk *chunk = &memory_chunk[i];
  595. real_size = max(real_size, chunk->addr + chunk->size);
  596. }
  597. create_mem_hole(memory_chunk, OLDMEM_BASE, OLDMEM_SIZE);
  598. create_mem_hole(memory_chunk, OLDMEM_SIZE, real_size - OLDMEM_SIZE);
  599. #endif
  600. }
  601. /*
  602. * Reserve memory for kdump kernel to be loaded with kexec
  603. */
  604. static void __init reserve_crashkernel(void)
  605. {
  606. #ifdef CONFIG_CRASH_DUMP
  607. unsigned long long crash_base, crash_size;
  608. char *msg = NULL;
  609. int rc;
  610. rc = parse_crashkernel(boot_command_line, memory_end, &crash_size,
  611. &crash_base);
  612. if (rc || crash_size == 0)
  613. return;
  614. crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
  615. crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);
  616. if (register_memory_notifier(&kdump_mem_nb))
  617. return;
  618. if (!crash_base)
  619. crash_base = find_crash_base(crash_size, &msg);
  620. if (!crash_base) {
  621. pr_info("crashkernel reservation failed: %s\n", msg);
  622. unregister_memory_notifier(&kdump_mem_nb);
  623. return;
  624. }
  625. if (verify_crash_base(crash_base, crash_size, &msg)) {
  626. pr_info("crashkernel reservation failed: %s\n", msg);
  627. unregister_memory_notifier(&kdump_mem_nb);
  628. return;
  629. }
  630. if (!OLDMEM_BASE && MACHINE_IS_VM)
  631. diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size));
  632. crashk_res.start = crash_base;
  633. crashk_res.end = crash_base + crash_size - 1;
  634. insert_resource(&iomem_resource, &crashk_res);
  635. create_mem_hole(memory_chunk, crash_base, crash_size);
  636. pr_info("Reserving %lluMB of memory at %lluMB "
  637. "for crashkernel (System RAM: %luMB)\n",
  638. crash_size >> 20, crash_base >> 20, memory_end >> 20);
  639. os_info_crashkernel_add(crash_base, crash_size);
  640. #endif
  641. }
  642. static void __init setup_memory(void)
  643. {
  644. unsigned long bootmap_size;
  645. unsigned long start_pfn, end_pfn;
  646. int i;
  647. /*
  648. * partially used pages are not usable - thus
  649. * we are rounding upwards:
  650. */
  651. start_pfn = PFN_UP(__pa(&_end));
  652. end_pfn = max_pfn = PFN_DOWN(memory_end);
  653. #ifdef CONFIG_BLK_DEV_INITRD
  654. /*
  655. * Move the initrd in case the bitmap of the bootmem allocater
  656. * would overwrite it.
  657. */
  658. if (INITRD_START && INITRD_SIZE) {
  659. unsigned long bmap_size;
  660. unsigned long start;
  661. bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
  662. bmap_size = PFN_PHYS(bmap_size);
  663. if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
  664. start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
  665. #ifdef CONFIG_CRASH_DUMP
  666. if (OLDMEM_BASE) {
  667. /* Move initrd behind kdump oldmem */
  668. if (start + INITRD_SIZE > OLDMEM_BASE &&
  669. start < OLDMEM_BASE + OLDMEM_SIZE)
  670. start = OLDMEM_BASE + OLDMEM_SIZE;
  671. }
  672. #endif
  673. if (start + INITRD_SIZE > memory_end) {
  674. pr_err("initrd extends beyond end of "
  675. "memory (0x%08lx > 0x%08lx) "
  676. "disabling initrd\n",
  677. start + INITRD_SIZE, memory_end);
  678. INITRD_START = INITRD_SIZE = 0;
  679. } else {
  680. pr_info("Moving initrd (0x%08lx -> "
  681. "0x%08lx, size: %ld)\n",
  682. INITRD_START, start, INITRD_SIZE);
  683. memmove((void *) start, (void *) INITRD_START,
  684. INITRD_SIZE);
  685. INITRD_START = start;
  686. }
  687. }
  688. }
  689. #endif
  690. /*
  691. * Initialize the boot-time allocator
  692. */
  693. bootmap_size = init_bootmem(start_pfn, end_pfn);
  694. /*
  695. * Register RAM areas with the bootmem allocator.
  696. */
  697. for (i = 0; i < MEMORY_CHUNKS; i++) {
  698. unsigned long start_chunk, end_chunk, pfn;
  699. if (!memory_chunk[i].size)
  700. continue;
  701. start_chunk = PFN_DOWN(memory_chunk[i].addr);
  702. end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size);
  703. end_chunk = min(end_chunk, end_pfn);
  704. if (start_chunk >= end_chunk)
  705. continue;
  706. memblock_add_node(PFN_PHYS(start_chunk),
  707. PFN_PHYS(end_chunk - start_chunk), 0);
  708. pfn = max(start_chunk, start_pfn);
  709. storage_key_init_range(PFN_PHYS(pfn), PFN_PHYS(end_chunk));
  710. }
  711. psw_set_key(PAGE_DEFAULT_KEY);
  712. free_bootmem_with_active_regions(0, max_pfn);
  713. /*
  714. * Reserve memory used for lowcore/command line/kernel image.
  715. */
  716. reserve_bootmem(0, (unsigned long)_ehead, BOOTMEM_DEFAULT);
  717. reserve_bootmem((unsigned long)_stext,
  718. PFN_PHYS(start_pfn) - (unsigned long)_stext,
  719. BOOTMEM_DEFAULT);
  720. /*
  721. * Reserve the bootmem bitmap itself as well. We do this in two
  722. * steps (first step was init_bootmem()) because this catches
  723. * the (very unlikely) case of us accidentally initializing the
  724. * bootmem allocator with an invalid RAM area.
  725. */
  726. reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size,
  727. BOOTMEM_DEFAULT);
  728. #ifdef CONFIG_CRASH_DUMP
  729. if (crashk_res.start)
  730. reserve_bootmem(crashk_res.start,
  731. crashk_res.end - crashk_res.start + 1,
  732. BOOTMEM_DEFAULT);
  733. if (is_kdump_kernel())
  734. reserve_bootmem(elfcorehdr_addr - OLDMEM_BASE,
  735. PAGE_ALIGN(elfcorehdr_size), BOOTMEM_DEFAULT);
  736. #endif
  737. #ifdef CONFIG_BLK_DEV_INITRD
  738. if (INITRD_START && INITRD_SIZE) {
  739. if (INITRD_START + INITRD_SIZE <= memory_end) {
  740. reserve_bootmem(INITRD_START, INITRD_SIZE,
  741. BOOTMEM_DEFAULT);
  742. initrd_start = INITRD_START;
  743. initrd_end = initrd_start + INITRD_SIZE;
  744. } else {
  745. pr_err("initrd extends beyond end of "
  746. "memory (0x%08lx > 0x%08lx) "
  747. "disabling initrd\n",
  748. initrd_start + INITRD_SIZE, memory_end);
  749. initrd_start = initrd_end = 0;
  750. }
  751. }
  752. #endif
  753. }
  754. /*
  755. * Setup hardware capabilities.
  756. */
  757. static void __init setup_hwcaps(void)
  758. {
  759. static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
  760. struct cpuid cpu_id;
  761. int i;
  762. /*
  763. * The store facility list bits numbers as found in the principles
  764. * of operation are numbered with bit 1UL<<31 as number 0 to
  765. * bit 1UL<<0 as number 31.
  766. * Bit 0: instructions named N3, "backported" to esa-mode
  767. * Bit 2: z/Architecture mode is active
  768. * Bit 7: the store-facility-list-extended facility is installed
  769. * Bit 17: the message-security assist is installed
  770. * Bit 19: the long-displacement facility is installed
  771. * Bit 21: the extended-immediate facility is installed
  772. * Bit 22: extended-translation facility 3 is installed
  773. * Bit 30: extended-translation facility 3 enhancement facility
  774. * These get translated to:
  775. * HWCAP_S390_ESAN3 bit 0, HWCAP_S390_ZARCH bit 1,
  776. * HWCAP_S390_STFLE bit 2, HWCAP_S390_MSA bit 3,
  777. * HWCAP_S390_LDISP bit 4, HWCAP_S390_EIMM bit 5 and
  778. * HWCAP_S390_ETF3EH bit 8 (22 && 30).
  779. */
  780. for (i = 0; i < 6; i++)
  781. if (test_facility(stfl_bits[i]))
  782. elf_hwcap |= 1UL << i;
  783. if (test_facility(22) && test_facility(30))
  784. elf_hwcap |= HWCAP_S390_ETF3EH;
  785. /*
  786. * Check for additional facilities with store-facility-list-extended.
  787. * stfle stores doublewords (8 byte) with bit 1ULL<<63 as bit 0
  788. * and 1ULL<<0 as bit 63. Bits 0-31 contain the same information
  789. * as stored by stfl, bits 32-xxx contain additional facilities.
  790. * How many facility words are stored depends on the number of
  791. * doublewords passed to the instruction. The additional facilities
  792. * are:
  793. * Bit 42: decimal floating point facility is installed
  794. * Bit 44: perform floating point operation facility is installed
  795. * translated to:
  796. * HWCAP_S390_DFP bit 6 (42 && 44).
  797. */
  798. if ((elf_hwcap & (1UL << 2)) && test_facility(42) && test_facility(44))
  799. elf_hwcap |= HWCAP_S390_DFP;
  800. /*
  801. * Huge page support HWCAP_S390_HPAGE is bit 7.
  802. */
  803. if (MACHINE_HAS_HPAGE)
  804. elf_hwcap |= HWCAP_S390_HPAGE;
  805. #if defined(CONFIG_64BIT)
  806. /*
  807. * 64-bit register support for 31-bit processes
  808. * HWCAP_S390_HIGH_GPRS is bit 9.
  809. */
  810. elf_hwcap |= HWCAP_S390_HIGH_GPRS;
  811. /*
  812. * Transactional execution support HWCAP_S390_TE is bit 10.
  813. */
  814. if (test_facility(50) && test_facility(73))
  815. elf_hwcap |= HWCAP_S390_TE;
  816. #endif
  817. get_cpu_id(&cpu_id);
  818. switch (cpu_id.machine) {
  819. case 0x9672:
  820. #if !defined(CONFIG_64BIT)
  821. default: /* Use "g5" as default for 31 bit kernels. */
  822. #endif
  823. strcpy(elf_platform, "g5");
  824. break;
  825. case 0x2064:
  826. case 0x2066:
  827. #if defined(CONFIG_64BIT)
  828. default: /* Use "z900" as default for 64 bit kernels. */
  829. #endif
  830. strcpy(elf_platform, "z900");
  831. break;
  832. case 0x2084:
  833. case 0x2086:
  834. strcpy(elf_platform, "z990");
  835. break;
  836. case 0x2094:
  837. case 0x2096:
  838. strcpy(elf_platform, "z9-109");
  839. break;
  840. case 0x2097:
  841. case 0x2098:
  842. strcpy(elf_platform, "z10");
  843. break;
  844. case 0x2817:
  845. case 0x2818:
  846. strcpy(elf_platform, "z196");
  847. break;
  848. case 0x2827:
  849. case 0x2828:
  850. strcpy(elf_platform, "zEC12");
  851. break;
  852. }
  853. }
  854. /*
  855. * Setup function called from init/main.c just after the banner
  856. * was printed.
  857. */
  858. void __init setup_arch(char **cmdline_p)
  859. {
  860. /*
  861. * print what head.S has found out about the machine
  862. */
  863. #ifndef CONFIG_64BIT
  864. if (MACHINE_IS_VM)
  865. pr_info("Linux is running as a z/VM "
  866. "guest operating system in 31-bit mode\n");
  867. else if (MACHINE_IS_LPAR)
  868. pr_info("Linux is running natively in 31-bit mode\n");
  869. if (MACHINE_HAS_IEEE)
  870. pr_info("The hardware system has IEEE compatible "
  871. "floating point units\n");
  872. else
  873. pr_info("The hardware system has no IEEE compatible "
  874. "floating point units\n");
  875. #else /* CONFIG_64BIT */
  876. if (MACHINE_IS_VM)
  877. pr_info("Linux is running as a z/VM "
  878. "guest operating system in 64-bit mode\n");
  879. else if (MACHINE_IS_KVM)
  880. pr_info("Linux is running under KVM in 64-bit mode\n");
  881. else if (MACHINE_IS_LPAR)
  882. pr_info("Linux is running natively in 64-bit mode\n");
  883. #endif /* CONFIG_64BIT */
  884. /* Have one command line that is parsed and saved in /proc/cmdline */
  885. /* boot_command_line has been already set up in early.c */
  886. *cmdline_p = boot_command_line;
  887. ROOT_DEV = Root_RAM0;
  888. init_mm.start_code = PAGE_OFFSET;
  889. init_mm.end_code = (unsigned long) &_etext;
  890. init_mm.end_data = (unsigned long) &_edata;
  891. init_mm.brk = (unsigned long) &_end;
  892. parse_early_param();
  893. detect_memory_layout(memory_chunk, memory_end);
  894. os_info_init();
  895. setup_ipl();
  896. reserve_oldmem();
  897. setup_memory_end();
  898. reserve_crashkernel();
  899. setup_memory();
  900. setup_resources();
  901. setup_vmcoreinfo();
  902. setup_lowcore();
  903. smp_fill_possible_mask();
  904. cpu_init();
  905. s390_init_cpu_topology();
  906. /*
  907. * Setup capabilities (ELF_HWCAP & ELF_PLATFORM).
  908. */
  909. setup_hwcaps();
  910. /*
  911. * Create kernel page tables and switch to virtual addressing.
  912. */
  913. paging_init();
  914. /* Setup default console */
  915. conmode_default();
  916. set_preferred_console();
  917. /* Setup zfcpdump support */
  918. setup_zfcpdump();
  919. }
  920. #ifdef CONFIG_32BIT
  921. static int no_removal_warning __initdata;
  922. static int __init parse_no_removal_warning(char *str)
  923. {
  924. no_removal_warning = 1;
  925. return 0;
  926. }
  927. __setup("no_removal_warning", parse_no_removal_warning);
  928. static int __init removal_warning(void)
  929. {
  930. if (no_removal_warning)
  931. return 0;
  932. printk(KERN_ALERT "\n\n");
  933. printk(KERN_CONT "Warning - you are using a 31 bit kernel!\n\n");
  934. printk(KERN_CONT "We plan to remove 31 bit kernel support from the kernel sources in March 2015.\n");
  935. printk(KERN_CONT "Currently we assume that nobody is using the 31 bit kernel on old 31 bit\n");
  936. printk(KERN_CONT "hardware anymore. If you think that the code should not be removed and also\n");
  937. printk(KERN_CONT "future versions of the Linux kernel should be able to run in 31 bit mode\n");
  938. printk(KERN_CONT "please let us know. Please write to:\n");
  939. printk(KERN_CONT "linux390@de.ibm.com (mail address) and/or\n");
  940. printk(KERN_CONT "linux-s390@vger.kernel.org (mailing list).\n\n");
  941. printk(KERN_CONT "Thank you!\n\n");
  942. printk(KERN_CONT "If this kernel runs on a 64 bit machine you may consider using a 64 bit kernel.\n");
  943. printk(KERN_CONT "This message can be disabled with the \"no_removal_warning\" kernel parameter.\n");
  944. schedule_timeout_uninterruptible(300 * HZ);
  945. return 0;
  946. }
  947. early_initcall(removal_warning);
  948. #endif