setup.c 28 KB

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